import{css as c,html as y,Component as x,bind as g,styleMap as d}from"wkit";import"../form/input.js";let s=null,p=null;const a="\u63D0\u793A",u=["\u53D6\u6D88","\u786E\u5B9A"],h=["alert","confirm","prompt"],k=h.concat(["toast"]);class w extends x{static animation={};static props={type:{type:String,default:null,observer(t){this.#t=!k.includes(t)}},left:{type:String,attribute:!1},right:{type:String,attribute:!1},top:{type:String,attribute:!1},bottom:{type:String,attribute:!1},background:{type:String,attribute:!1},maskColor:{type:String,attribute:!1},mask:!1,maskClose:!1,title:{type:String,default:"",attribute:!1},content:{type:String,default:"",attribute:!1},btns:[]};static styles=[c`:host{display:none;justify-content:center;align-items:center;position:fixed;z-index:65534;left:0;top:0;width:100%;height:0}:host([type]){display:flex}:host([type=toast]) .layer,:host([type=common]) .layer{position:absolute}.noselect{-webkit-touch-callout:none;user-select:none}.noselect img,.noselect a{-webkit-user-drag:none}`,c`.layer{flex:0 auto;position:relative;z-index:65535;border-radius:3px;color:#666;font-size:14px;background:rgba(255,255,255,.8);box-shadow:0 5px 20px rgba(0,0,0,.3);transition:opacity .2s ease-in-out,left .2s ease-in-out,right .2s ease-in-out,top .2s ease-in-out,bottom .2s ease-in-out}.layer:active{z-index:65536}`,c`.layer__title{display:flex;justify-content:space-between;align-items:center;width:100%;height:60px;padding:15px;font-size:16px;color:var(--color-dark-2)}.layer__title wc-icon{--wc-icon-size: 14px}.layer__title wc-icon:hover{color:var(--color-red-1)}.layer__content{display:flex;position:relative;width:100%;height:auto;min-height:50px;word-break:break-all;word-wrap:break-word}::slotted(.layer__content__input){flex:1}::slotted(.layer__content__toast){flex-shrink:0;flex:1;display:flex;align-items:center;width:300px;min-height:40px;margin-bottom:15px !important;padding:0 10px !important;border-radius:3px;font-weight:normal;text-indent:8px;--wc-icon-size: 16px;color:var(--color-dark-1);box-shadow:0 2px 12px rgba(0,0,0,.1)}::slotted(.layer__content__toast+.layer__content__toast){margin-top:30px}::slotted(.layer__content__toast.style-info){border:1px solid #ebeef5;background:#edf2fc;color:var(--color-grey-3)}::slotted(.layer__content__toast.style-success){border:1px solid #e1f3d8;background:#f0f9eb;color:var(--color-green-3)}::slotted(.layer__content__toast.style-warning){border:1px solid #faebb4;background:#faecd8;color:var(--color-red-1)}::slotted(.layer__content__toast.style-error){border:1px solid #f5c4c4;background:#fde2e2;color:var(--color-red-1)}.layer__ctrl{display:flex;justify-content:flex-end;width:100%;height:60px;padding:15px;line-height:30px;font-size:14px;color:#454545;text-align:right}.layer__ctrl button{min-width:64px;height:30px;padding:0 10px;margin:0 5px;border:1px solid var(--color-plain-3);border-radius:3px;white-space:nowrap;background:#fff;font-size:inherit;font-family:inherit;outline:none;color:inherit}.layer__ctrl button:hover{background:var(--color-plain-1)}.layer__ctrl button:active{border-color:var(--color-grey-1)}.layer__ctrl button:focus{box-shadow:0 0 0 2px var(--color-plain-a)}.layer__ctrl button:last-child{color:#fff;background:var(--color-teal-2);border-color:rgba(0,0,0,0)}.layer__ctrl button:last-child:hover{background:var(--color-teal-1)}.layer__ctrl button:last-child:active{background:var(--color-teal-3)}.layer__ctrl button:last-child:focus{box-shadow:0 0 0 2px var(--color-teal-a)}.layer__ctrl button::-moz-focus-inner{border:none}`,c`:host([mask]){height:100%;background:rgba(0,0,0,.2)}:host([type=alert]) .layer,:host([type=confirm]) .layer,:host([type=prompt]) .layer{max-width:600px;min-width:300px;background:#fff}:host([type=alert]) .layer__content,:host([type=confirm]) .layer__content,:host([type=prompt]) .layer__content{padding:0 15px}:host([type=toast]) .layer{box-shadow:none;background:none}:host([type=toast]) .layer__content{flex-direction:column;min-height:40px}:host([blurry]) .layer{backdrop-filter:blur(5px)}`];#t=!0;#o=null;#i=null;constructor(){super(),this.promise=new Promise((t,e)=>{this.#o=t,this.#i=e}),this.promise.host=this}#e(t){this.intercept?this.intercept(t,e=>{delete this.intercept,this.#o(t),this.$animate(!0),this.$refs.box.$animate(!0).then(o=>this.close())}):(this.#o(t),this.$animate(!0),this.$refs.box.$animate(!0).then(e=>this.close()))}#r(){switch(this.type){case"toast":let t=this.lastElementChild;t._anim=t.animate([{marginTop:"-30px",opacity:0},{marginTop:"0",opacity:1}],{duration:200,fill:"forwards"}),setTimeout(()=>{t._anim.reverse(),t._anim.onfinish=e=>{t.remove(),this.children.length===0&&(this.close(),p=null)}},3e3);break;default:this.$animate(),this.$refs.box.$animate();break}}mounted(){this.type==="prompt"?(this.$refs.input=this.firstElementChild,g(this.$refs.input,"submit",t=>{this.#e(t.target.value)})):this.type==="toast"&&(this.style.display=""),this.mask&&(this.$on("click",t=>{if(t.composedPath()[0]===t.currentTarget){if(h.includes(this.type))return;this.maskClose&&(this.#t===!1&&this.#i(),this.$refs.box.$animate(!0).then(o=>this.close()))}}),this.maskColor&&(this.style.backgroundColor=this.maskColor)),this.background&&(this.$refs.box.style.backgroundColor=this.background),this.#r()}updated(t,e){e&&this.#r()}moveTo(t={}){var e="";for(var o in t)e+=`${o}:${t[o]};`;this.$refs.box.style.cssText+=e}show(){this.#t&&(this.type="common")}close(){this.#t?(this.type=null,this.$emit("close")):(h.includes(this.type)&&(s=null),this.$emit("close"),this.remove())}handleBtnClick(t){if(t.target.tagName==="BUTTON"){let e=+t.target.dataset.idx||0;switch(this.type){case"alert":this.#e(null);break;case"confirm":case"prompt":if(e===0)this.#i(),this.$animate(!0),this.$refs.box.$animate(!0).then(o=>this.close());else{let o=this.type==="prompt"?this.$refs.input.value:null;this.#e(o)}break;default:this.#e(e);break}}}render(){let{type:t,mask:e,left:o,right:n,top:r,bottom:m}=this,f="";return t==="common"&&e===!1&&(r=r||0),f=d({left:o,right:n,top:r,bottom:m}),y`
${this.title}
${this.btns.map((b,_)=>y``)}
`}}function l(i={}){let{type:t="common",content:e=""}=i,o=t==="toast"&&p||document.createElement("wc-layer"),n=t==="toast"&&!!p;if(o.type=i.type,t==="toast"?(p=o,o.top="20px"):(i.btns&&i.btns.length&&(o.btns=i.btns),i.intercept&&typeof i.intercept=="function"&&(o.intercept=i.intercept),o.mask=i.mask,o.title=i.title,h.includes(t)&&(s?s.$animate(!0).then(r=>{s.close(),s=o}):s=o)),n){let r=document.createElement("template");r.innerHTML=e,o.appendChild(r.content.cloneNode(!0)),o.updated(null,!0)}else o.innerHTML=e,document.body.appendChild(o);return o.promise}l.alert=function(i,t=a,e=u.slice(1)){return typeof t=="object"&&(e=t,t=a),this({type:"alert",title:t,content:i,mask:!0,btns:e})},l.confirm=function(i,t=a,e=u.concat()){return typeof t=="object"&&(e=t,t=a),this({type:"confirm",title:t,content:i,mask:!0,btns:e})},l.prompt=function(i=a,t="",e){return typeof t=="function"&&(e=t,t=""),e||(e=function(o,n){o&&n()}),this({type:"prompt",title:i,content:``,mask:!0,intercept:e,btns:u.concat()})},l.toast=function(i,t="info"){var e=t;switch(t){case"info":case"warning":break;case"error":e="deny";break;case"success":e="get";break;default:e="info"}return this({content:`
${i}
`,type:"toast"})},w.reg("layer"),window.layer=l;