import{a4 as D,k as L,n as d,d as j,w as O,D as E,a5 as U,c as u,t as I,H as q,f as A,h as H,j as V,r as _,o as $}from"./index.fdb8061e.js";import{f as F,c as G,m as w,n as S,M as J,q as x,I as K,w as Q}from"./index.555136dd.js";import{P as R}from"./index.59f99230.js";import{L as W}from"./index.d6266256.js";function X(){const e=L({show:!1}),t=s=>{e.show=s},n=s=>{d(e,s,{transitionAppear:!0}),t(!0)},c=()=>t(!1);return F({open:n,close:c,toggle:t}),{open:n,close:c,state:e,toggle:t}}function Y(e){const t=D(e),n=document.createElement("div");return document.body.appendChild(n),{instance:t.mount(n),unmount(){t.unmount(),document.body.removeChild(n)}}}let m=0;function Z(e){e?(m||document.body.classList.add("van-toast--unclickable"),m++):m&&(m--,m||document.body.classList.remove("van-toast--unclickable"))}const[ee,p]=G("toast"),te=["show","overlay","teleport","transition","overlayClass","overlayStyle","closeOnClickOverlay"],ne={icon:String,show:Boolean,type:w("text"),overlay:Boolean,message:S,iconSize:S,duration:J(2e3),position:w("middle"),teleport:[String,Object],className:x,iconPrefix:String,transition:w("van-fade"),loadingType:String,forbidClick:Boolean,overlayClass:x,overlayStyle:Object,closeOnClick:Boolean,closeOnClickOverlay:Boolean};var M=j({name:ee,props:ne,emits:["update:show"],setup(e,{emit:t}){let n,c=!1;const s=()=>{const i=e.show&&e.forbidClick;c!==i&&(c=i,Z(c))},f=i=>t("update:show",i),k=()=>{e.closeOnClick&&f(!1)},g=()=>clearTimeout(n),C=()=>{const{icon:i,type:l,iconSize:P,iconPrefix:N,loadingType:z}=e;if(i||l==="success"||l==="fail")return u(K,{name:i||l,size:P,class:p("icon"),classPrefix:N},null);if(l==="loading")return u(W,{class:p("loading"),size:P,type:z},null)},r=()=>{const{type:i,message:l}=e;if(A(l)&&l!=="")return i==="html"?u("div",{key:0,class:p("text"),innerHTML:String(l)},null):u("div",{class:p("text")},[l])};return O(()=>[e.show,e.forbidClick],s),O(()=>[e.show,e.type,e.message,e.duration],()=>{g(),e.show&&e.duration>0&&(n=setTimeout(()=>{f(!1)},e.duration))}),E(s),U(s),()=>u(R,I({class:[p([e.position,{[e.type]:!e.icon}]),e.className],lockScroll:!1,onClick:k,onClosed:g,"onUpdate:show":f},q(e,te)),{default:()=>[C(),r()]})}});const T={icon:"",type:"text",message:"",className:"",overlay:!1,onClose:void 0,onOpened:void 0,duration:2e3,teleport:"body",iconSize:void 0,iconPrefix:void 0,position:"middle",transition:"van-fade",forbidClick:!1,loadingType:void 0,overlayClass:"",overlayStyle:void 0,closeOnClick:!1,closeOnClickOverlay:!1};let o=[],h=!1,y=d({},T);const v=new Map;function B(e){return V(e)?e:{message:e}}function oe(){const{instance:e,unmount:t}=Y({setup(){const n=_(""),{open:c,state:s,close:f,toggle:k}=X(),g=()=>{h&&(o=o.filter(r=>r!==e),t())},C=()=>u(M,I(s,{onClosed:g,"onUpdate:show":k}),null);return O(n,r=>{s.message=r}),$().render=C,{open:c,clear:f,message:n}}});return e}function se(){if(!o.length||h){const e=oe();o.push(e)}return o[o.length-1]}function a(e={}){if(!H)return{};const t=se(),n=B(e);return t.open(d({},y,v.get(n.type||y.type),n)),t}const b=e=>t=>a(d({type:e},B(t)));a.loading=b("loading");a.success=b("success");a.fail=b("fail");a.clear=e=>{var t;o.length&&(e?(o.forEach(n=>{n.clear()}),o=[]):h?(t=o.shift())==null||t.clear():o[0].clear())};function ae(e,t){typeof e=="string"?v.set(e,t):d(y,e)}a.setDefaultOptions=ae;a.resetDefaultOptions=e=>{typeof e=="string"?v.delete(e):(y=d({},T),v.clear())};a.allowMultiple=(e=!0)=>{h=e};a.install=e=>{e.use(Q(M)),e.config.globalProperties.$toast=a};export{a as T};
