import{b0 as Y,J as R,aL as be,aI as ye,d as Ce,b1 as he,b2 as Ee,b3 as Be,b4 as we,aH as Me,b5 as ke,b6 as Se,aE as Te,p as w,n as M,a3 as Ie,aF as x,b7 as _,U as ee,b8 as Ae,t as Oe,ah as Re,b9 as Ve,ba as $e,r as k,o as c,i as v,j as m,w as U,e as C,g as p,V as r,x as ne,a1 as z,c as N,y as P,B as S,z as O,bb as D,ar as Le,h as K,ai as j,aj as ze,bc as Pe,aM as De,aP as le,aN as re,aQ as ie,bd as se,be as Fe,bf as He,bg as oe,aO as ae}from"./index-4789ca0a.js";const q="_trap-focus-children",h=[],te=e=>{if(h.length===0)return;const n=h[h.length-1][q];if(n.length>0&&e.code===be.tab){if(n.length===1){e.preventDefault(),document.activeElement!==n[0]&&n[0].focus();return}const t=e.shiftKey,i=e.target===n[0],l=e.target===n[n.length-1];i&&t&&(e.preventDefault(),n[n.length-1].focus()),l&&!t&&(e.preventDefault(),n[0].focus())}},Ue={beforeMount(e){e[q]=Y(e),h.push(e),h.length<=1&&document.addEventListener("keydown",te)},updated(e){R(()=>{e[q]=Y(e)})},unmounted(){h.shift(),h.length===0&&document.removeEventListener("keydown",te)}},Ne=Ce({name:"ElMessageBox",directives:{TrapFocus:Ue},components:{ElButton:he,ElFocusTrap:Ee,ElInput:Be,ElOverlay:we,ElIcon:Me,...ke},inheritAttrs:!1,props:{buttonSize:{type:String,validator:Se},modal:{type:Boolean,default:!0},lockScroll:{type:Boolean,default:!0},showClose:{type:Boolean,default:!0},closeOnClickModal:{type:Boolean,default:!0},closeOnPressEscape:{type:Boolean,default:!0},closeOnHashChange:{type:Boolean,default:!0},center:Boolean,draggable:Boolean,roundButton:{default:!1,type:Boolean},container:{type:String,default:"body"},boxType:{type:String,default:""}},emits:["vanish","action"],setup(e,{emit:n}){const{locale:t,zIndex:i,ns:l,size:o}=Te("message-box",w(()=>e.buttonSize)),{t:d}=t,{nextZIndex:f}=i,y=M(!1),s=Ie({autofocus:!0,beforeClose:null,callback:null,cancelButtonText:"",cancelButtonClass:"",confirmButtonText:"",confirmButtonClass:"",customClass:"",customStyle:{},dangerouslyUseHTMLString:!1,distinguishCancelAndClose:!1,icon:"",inputPattern:null,inputPlaceholder:"",inputType:"text",inputValue:null,inputValidator:null,inputErrorMessage:"",message:null,modalFade:!0,modalClass:"",showCancelButton:!1,showConfirmButton:!0,type:"",title:void 0,showInput:!1,action:"",confirmButtonLoading:!1,cancelButtonLoading:!1,confirmButtonDisabled:!1,editorErrorMessage:"",validateError:!1,zIndex:f()}),F=w(()=>{const a=s.type;return{[l.bm("icon",a)]:a&&x[a]}}),H=_(),u=_(),ue=w(()=>s.icon||x[s.type]||""),de=w(()=>!!s.message),E=M(),G=M(),I=M(),$=M(),X=M(),ce=w(()=>s.confirmButtonClass);ee(()=>s.inputValue,async a=>{await R(),e.boxType==="prompt"&&a!==null&&Q()},{immediate:!0}),ee(()=>y.value,a=>{var g,B;a&&(e.boxType!=="prompt"&&(s.autofocus?I.value=(B=(g=X.value)==null?void 0:g.$el)!=null?B:E.value:I.value=E.value),s.zIndex=f()),e.boxType==="prompt"&&(a?R().then(()=>{var Z;$.value&&$.value.$el&&(s.autofocus?I.value=(Z=ge())!=null?Z:E.value:I.value=E.value)}):(s.editorErrorMessage="",s.validateError=!1))});const fe=w(()=>e.draggable);Ae(E,G,fe),Oe(async()=>{await R(),e.closeOnHashChange&&window.addEventListener("hashchange",A)}),Re(()=>{e.closeOnHashChange&&window.removeEventListener("hashchange",A)});function A(){y.value&&(y.value=!1,R(()=>{s.action&&n("action",s.action)}))}const J=()=>{e.closeOnClickModal&&L(s.distinguishCancelAndClose?"close":"cancel")},me=Pe(J),pe=a=>{if(s.inputType!=="textarea")return a.preventDefault(),L("confirm")},L=a=>{var g;e.boxType==="prompt"&&a==="confirm"&&!Q()||(s.action=a,s.beforeClose?(g=s.beforeClose)==null||g.call(s,a,s,A):A())},Q=()=>{if(e.boxType==="prompt"){const a=s.inputPattern;if(a&&!a.test(s.inputValue||""))return s.editorErrorMessage=s.inputErrorMessage||d("el.messagebox.error"),s.validateError=!0,!1;const g=s.inputValidator;if(typeof g=="function"){const B=g(s.inputValue);if(B===!1)return s.editorErrorMessage=s.inputErrorMessage||d("el.messagebox.error"),s.validateError=!0,!1;if(typeof B=="string")return s.editorErrorMessage=B,s.validateError=!0,!1}}return s.editorErrorMessage="",s.validateError=!1,!0},ge=()=>{const a=$.value.$refs;return a.input||a.textarea},W=()=>{L("close")},ve=()=>{e.closeOnPressEscape&&W()};return e.lockScroll&&Ve(y),{...$e(s),ns:l,overlayEvent:me,visible:y,hasMessage:de,typeClass:F,contentId:H,inputId:u,btnSize:o,iconComponent:ue,confirmButtonClasses:ce,rootRef:E,focusStartRef:I,headerRef:G,inputRef:$,confirmRef:X,doClose:A,handleClose:W,onCloseRequested:ve,handleWrapperClick:J,handleInputEnter:pe,handleAction:L,t:d}}}),Ke=["aria-label","aria-describedby"],je=["aria-label"],qe=["id"];function Ge(e,n,t,i,l,o){const d=k("el-icon"),f=k("close"),y=k("el-input"),s=k("el-button"),F=k("el-focus-trap"),H=k("el-overlay");return c(),v(ze,{name:"fade-in-linear",onAfterLeave:n[11]||(n[11]=u=>e.$emit("vanish")),persisted:""},{default:m(()=>[U(C(H,{"z-index":e.zIndex,"overlay-class":[e.ns.is("message-box"),e.modalClass],mask:e.modal},{default:m(()=>[p("div",{role:"dialog","aria-label":e.title,"aria-modal":"true","aria-describedby":e.showInput?void 0:e.contentId,class:r(`${e.ns.namespace.value}-overlay-message-box`),onClick:n[8]||(n[8]=(...u)=>e.overlayEvent.onClick&&e.overlayEvent.onClick(...u)),onMousedown:n[9]||(n[9]=(...u)=>e.overlayEvent.onMousedown&&e.overlayEvent.onMousedown(...u)),onMouseup:n[10]||(n[10]=(...u)=>e.overlayEvent.onMouseup&&e.overlayEvent.onMouseup(...u))},[C(F,{loop:"",trapped:e.visible,"focus-trap-el":e.rootRef,"focus-start-el":e.focusStartRef,onReleaseRequested:e.onCloseRequested},{default:m(()=>[p("div",{ref:"rootRef",class:r([e.ns.b(),e.customClass,e.ns.is("draggable",e.draggable),{[e.ns.m("center")]:e.center}]),style:ne(e.customStyle),tabindex:"-1",onClick:n[7]||(n[7]=z(()=>{},["stop"]))},[e.title!==null&&e.title!==void 0?(c(),N("div",{key:0,ref:"headerRef",class:r(e.ns.e("header"))},[p("div",{class:r(e.ns.e("title"))},[e.iconComponent&&e.center?(c(),v(d,{key:0,class:r([e.ns.e("status"),e.typeClass])},{default:m(()=>[(c(),v(P(e.iconComponent)))]),_:1},8,["class"])):S("v-if",!0),p("span",null,O(e.title),1)],2),e.showClose?(c(),N("button",{key:0,type:"button",class:r(e.ns.e("headerbtn")),"aria-label":e.t("el.messagebox.close"),onClick:n[0]||(n[0]=u=>e.handleAction(e.distinguishCancelAndClose?"close":"cancel")),onKeydown:n[1]||(n[1]=D(z(u=>e.handleAction(e.distinguishCancelAndClose?"close":"cancel"),["prevent"]),["enter"]))},[C(d,{class:r(e.ns.e("close"))},{default:m(()=>[C(f)]),_:1},8,["class"])],42,je)):S("v-if",!0)],2)):S("v-if",!0),p("div",{id:e.contentId,class:r(e.ns.e("content"))},[p("div",{class:r(e.ns.e("container"))},[e.iconComponent&&!e.center&&e.hasMessage?(c(),v(d,{key:0,class:r([e.ns.e("status"),e.typeClass])},{default:m(()=>[(c(),v(P(e.iconComponent)))]),_:1},8,["class"])):S("v-if",!0),e.hasMessage?(c(),N("div",{key:1,class:r(e.ns.e("message"))},[Le(e.$slots,"default",{},()=>[e.dangerouslyUseHTMLString?(c(),v(P(e.showInput?"label":"p"),{key:1,for:e.showInput?e.inputId:void 0,innerHTML:e.message},null,8,["for","innerHTML"])):(c(),v(P(e.showInput?"label":"p"),{key:0,for:e.showInput?e.inputId:void 0},{default:m(()=>[K(O(e.dangerouslyUseHTMLString?"":e.message),1)]),_:1},8,["for"]))])],2)):S("v-if",!0)],2),U(p("div",{class:r(e.ns.e("input"))},[C(y,{id:e.inputId,ref:"inputRef",modelValue:e.inputValue,"onUpdate:modelValue":n[2]||(n[2]=u=>e.inputValue=u),type:e.inputType,placeholder:e.inputPlaceholder,"aria-invalid":e.validateError,class:r({invalid:e.validateError}),onKeydown:D(e.handleInputEnter,["enter"])},null,8,["id","modelValue","type","placeholder","aria-invalid","class","onKeydown"]),p("div",{class:r(e.ns.e("errormsg")),style:ne({visibility:e.editorErrorMessage?"visible":"hidden"})},O(e.editorErrorMessage),7)],2),[[j,e.showInput]])],10,qe),p("div",{class:r(e.ns.e("btns"))},[e.showCancelButton?(c(),v(s,{key:0,loading:e.cancelButtonLoading,class:r([e.cancelButtonClass]),round:e.roundButton,size:e.btnSize,onClick:n[3]||(n[3]=u=>e.handleAction("cancel")),onKeydown:n[4]||(n[4]=D(z(u=>e.handleAction("cancel"),["prevent"]),["enter"]))},{default:m(()=>[K(O(e.cancelButtonText||e.t("el.messagebox.cancel")),1)]),_:1},8,["loading","class","round","size"])):S("v-if",!0),U(C(s,{ref:"confirmRef",type:"primary",loading:e.confirmButtonLoading,class:r([e.confirmButtonClasses]),round:e.roundButton,disabled:e.confirmButtonDisabled,size:e.btnSize,onClick:n[5]||(n[5]=u=>e.handleAction("confirm")),onKeydown:n[6]||(n[6]=D(z(u=>e.handleAction("confirm"),["prevent"]),["enter"]))},{default:m(()=>[K(O(e.confirmButtonText||e.t("el.messagebox.confirm")),1)]),_:1},8,["loading","class","round","disabled","size"]),[[j,e.showConfirmButton]])],2)],6)]),_:3},8,["trapped","focus-trap-el","focus-start-el","onReleaseRequested"])],42,Ke)]),_:3},8,["z-index","overlay-class","mask"]),[[j,e.visible]])]),_:3})}var Xe=ye(Ne,[["render",Ge],["__file","/home/runner/work/element-plus/element-plus/packages/components/message-box/src/index.vue"]]);const V=new Map,Je=e=>{let n=document.body;return e.appendTo&&(le(e.appendTo)&&(n=document.querySelector(e.appendTo)),ae(e.appendTo)&&(n=e.appendTo),ae(n)||(n=document.body)),n},Qe=(e,n,t=null)=>{const i=C(Xe,e,oe(e.message)||re(e.message)?{default:oe(e.message)?e.message:()=>e.message}:null);return i.appContext=t,ie(i,n),Je(e).appendChild(n.firstElementChild),i.component},We=()=>document.createElement("div"),Ze=(e,n)=>{const t=We();e.onVanish=()=>{ie(null,t),V.delete(l)},e.onAction=o=>{const d=V.get(l);let f;e.showInput?f={value:l.inputValue,action:o}:f=o,e.callback?e.callback(f,i.proxy):o==="cancel"||o==="close"?e.distinguishCancelAndClose&&o!=="cancel"?d.reject("close"):d.reject("cancel"):d.resolve(f)};const i=Qe(e,t,n),l=i.proxy;for(const o in e)se(e,o)&&!se(l.$props,o)&&(l[o]=e[o]);return l.visible=!0,l};function T(e,n=null){if(!De)return Promise.reject();let t;return le(e)||re(e)?e={message:e}:t=e.callback,new Promise((i,l)=>{const o=Ze(e,n??T._context);V.set(o,{options:e,callback:t,resolve:i,reject:l})})}const Ye=["alert","confirm","prompt"],xe={alert:{closeOnPressEscape:!1,closeOnClickModal:!1},confirm:{showCancelButton:!0},prompt:{showCancelButton:!0,showInput:!0}};Ye.forEach(e=>{T[e]=_e(e)});function _e(e){return(n,t,i,l)=>{let o="";return Fe(t)?(i=t,o=""):He(t)?o="":o=t,T(Object.assign({title:o,message:n,type:"",...xe[e]},i,{boxType:e}),l)}}T.close=()=>{V.forEach((e,n)=>{n.doClose()}),V.clear()};T._context=null;const b=T;b.install=e=>{b._context=e._context,e.config.globalProperties.$msgbox=b,e.config.globalProperties.$messageBox=b,e.config.globalProperties.$alert=b.alert,e.config.globalProperties.$confirm=b.confirm,e.config.globalProperties.$prompt=b.prompt};const nn=b;export{nn as E};
