const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CheckboxInput-q-KtlTTN.js","assets/index-m7Z9H1b_.js"])))=>i.map(i=>d[i]); import{_,d as I,a as q,r as p,s as w,o as i,l as m,i as B,w as k,f as r,v as C,h,j as c,x as f,q as b,y as x,T as V,z as P}from"./index-m7Z9H1b_.js";import E from"./ButtonElement-VEOfE7ak.js";const z={name:"KDialog",components:{ButtonElement:E,CheckboxInput:I(()=>q(()=>import("./CheckboxInput-q-KtlTTN.js"),__vite__mapDeps([0,1])))},emits:["close"],data(){return{visible:!1,icon:null,caption:null,help:null,secure:!1,secureValue:"delete",typedSecureValue:"",requiredInput:!1,requiredInputMinLength:2,typedRequiredValue:null,cancelButton:{caption:"actions.cancel",action:this.close,variant:"tertiary"},confirmButton:{caption:"actions.ok",action:this.close,variant:"primary",params:null},checkbox:null,width:null,defaultDialogWidth:"320px",blockBodyScroll:!0}},computed:{dialogWidth:({width:e,defaultDialogWidth:n})=>e??n,dialogVisibility:({visible:e})=>({display:e?"block":"none"}),dialogSize:({dialogWidth:e})=>({maxWidth:e}),secureValueString:({$t:e,secureValue:n})=>`"${e(`forms.secure-values.${n}`)}"`,isValid:({secure:e,typedSecureValue:n,$t:u,secureValue:v,requiredInput:t,typedRequiredValue:l,requiredInputMinLength:d,checkbox:s})=>{let o=!0;return e&&(o=n===u(`forms.secure-values.${v}`)),t&&(o=l!=null&&l.length>=d),s!=null&&s.required&&(o=s.value===!0),o},confirmButtonVisible:({confirmButton:e})=>e!=null&&(e.hide==null||!e.hide),cancelButtonVisible:({cancelButton:e})=>e!=null&&(e.hide==null||!e.hide)},created(){this.$.appContext.app.config.globalProperties.$dialog=this},methods:{show:function(e={icon:null,caption:null,help:null,cancelButton:{caption:null,action:null,variant:null},confirmButton:{caption:null,action:null,variant:null},width:null}){e.icon!=null&&(this.icon=e.icon),e.caption!=null&&(this.caption=e.caption),e.help!=null&&(this.help=e.help),e.secure!=null&&(this.secure=e.secure),e.secureValue!=null&&(this.secureValue=e.secureValue),e.requiredInput!=null&&(this.requiredInput=e.requiredInput),e.requiredInputMinLength!=null&&(this.requiredInputMinLength=e.requiredInputMinLength),e.cancelButton!=null?(e.cancelButton.caption!=null&&(this.cancelButton.caption=e.cancelButton.caption),e.cancelButton.action!=null&&(this.cancelButton.action=e.cancelButton.action),e.cancelButton.variant!=null&&(this.cancelButton.variant=e.cancelButton.variant),e.cancelButton.params!=null&&(this.cancelButton.params=e.cancelButton.params),e.cancelButton.hide!=null&&(this.cancelButton.hide=e.cancelButton.hide)):e.cancelButton===null&&(this.cancelButton=null),e.confirmButton!=null&&(e.confirmButton.caption!=null&&(this.confirmButton.caption=e.confirmButton.caption),e.confirmButton.action!=null&&(this.confirmButton.action=e.confirmButton.action),e.confirmButton.variant!=null&&(this.confirmButton.variant=e.confirmButton.variant),e.confirmButton.params!=null&&(this.confirmButton.params=e.confirmButton.params),e.confirmButton.hide!=null&&(this.confirmButton.hide=e.confirmButton.hide)),e.checkbox!=null&&(this.checkbox=e.checkbox),e.width!=null&&(this.width=e.width),this.visible=!0,this.blockBodyScroll&&document.body.classList.add("dialog-visible"),document.addEventListener("keydown",this.checkKeydown,!0),this.secure?this.$nextTick(()=>{this.$refs.secureInput.focus()}):this.requiredInput&&this.$nextTick(()=>{this.$refs.requiredInput.focus()})},checkKeydown:function(e){switch(e.key){case"Enter":this.isValid&&(this.confirmButton.hide==null||!this.confirmButton.hide)?this.$refs.confirmButton.click():this.confirmButton.hide!=null&&this.confirmButton.hide&&this.$refs.cancelButton.click();break;case"Escape":this.cancelButton!=null&&(this.cancelButton.hide==null||!this.cancelButton.hide)?this.$refs.cancelButton.click():this.close();break}let n=e.composedPath().map(u=>u.id);!e.metaKey&&!n.includes("secureInput")&&!n.includes("requiredInput")&&(e.stopPropagation(),e.preventDefault())},resetProps:function(){this.icon=null,this.caption=null,this.help=null,this.secure=!1,this.secureValue="delete",this.typedSecureValue="",this.requiredInput=!1,this.typedRequiredValue=null,this.cancelButton={caption:"actions.cancel",action:this.close,variant:"tertiary",params:null},this.confirmButton={caption:"actions.ok",action:this.close,variant:"primary",params:null},this.checkbox=null,this.width=null},close:function(){setTimeout(()=>{document.body.classList.remove("dialog-visible"),document.removeEventListener("keydown",this.checkKeydown,!0)},200),this.visible=!1,this.resetProps()},executeConfirmAction:function(){let e=this.checkbox!=null&&this.checkbox.sendToConfirmFn?{[this.checkbox.name]:this.checkbox.value}:{},n=this.confirmButton.params!=null?this.confirmButton.params:{};const u=Object.assign({},n,e);this.requiredInput&&(u.requiredInputValue=this.typedRequiredValue),this.confirmButton.action(u),this.close()},executeCancelAction:function(){let e=this.cancelButton.params!=null?this.cancelButton.params:{};const n=Object.assign({},e);this.cancelButton.action(n),this.close()}}},S={class:"dialog-dialog"},T={class:"dialog-content"},L={class:"dialog-body"},D={class:"text-center"},A={key:2,class:"byline--sm"},K=["placeholder"],M={key:0,class:"d-flex justify-content-center mt-3"},R={class:"dialog-footer flex-column flex-sm-row",style:{padding:"0","row-gap":"1rem"}},j={key:0,class:"modal-backdrop"};function N(e,n,u,v,t,l){const d=p("icon"),s=p("CheckboxInput"),o=p("ButtonElement"),y=w("dompurify-html");return i(),m(P,{to:"#dialogs-container"},[B(V,{name:"dialogEntry"},{default:k(()=>[t.visible?(i(),r("div",{key:0,class:"modal",role:"modal",style:C(l.dialogVisibility),"aria-labelledby":"dialogTitle","aria-describedby":"dialogDescription"},[h("div",S,[h("div",T,[h("div",L,[h("div",D,[t.icon?(i(),m(d,{key:0,icon:t.icon,size:"4x"},null,8,["icon"])):c("",!0),t.caption?f((i(),r("div",{key:1,class:b({"headline--xs":!0,"mt-4":t.icon,"mb-2":t.help})},null,2)),[[y,t.caption]]):c("",!0),t.help?f((i(),r("div",A,null,512)),[[y,t.help]]):c("",!0),t.secure?f((i(),r("input",{key:3,id:"secureInput",ref:"secureInput","onUpdate:modelValue":n[0]||(n[0]=a=>t.typedSecureValue=a),autocomplete:"off",type:"text",class:"form-control form-control-lg mt-4 text-center",placeholder:e.$t("forms.dialog-secure-placeholder",{secureValue:l.secureValueString},{$capitalize:!0})},null,8,K)),[[x,t.typedSecureValue]]):t.requiredInput?f((i(),r("input",{key:4,id:"requiredInput",ref:"requiredInput","onUpdate:modelValue":n[1]||(n[1]=a=>t.typedRequiredValue=a),autocomplete:"off",type:"text",class:"form-control form-control-lg mt-4 text-center"},null,512)),[[x,t.typedRequiredValue]]):c("",!0)]),t.checkbox!=null?(i(),r("div",M,[B(s,{modelValue:t.checkbox.value,"onUpdate:modelValue":n[2]||(n[2]=a=>t.checkbox.value=a),label:t.checkbox.caption,vertical:"","as-switch":"",margin:"mb-0"},null,8,["modelValue","label"])])):c("",!0)]),h("div",R,[l.cancelButtonVisible?(i(),m(o,{key:0,ref:"cancelButton",variant:t.cancelButton.variant,size:"lg",action:l.executeCancelAction,label:e.$t(t.cancelButton.caption,{$capitalize:!0}),class:b({"ms-auto":t.confirmButton.hide!=null&&t.confirmButton.hide})},null,8,["variant","action","label","class"])):c("",!0),l.confirmButtonVisible?(i(),m(o,{key:1,ref:"confirmButton",disabled:!l.isValid,variant:t.confirmButton.variant,class:b(["ms-sm-auto",{"mx-auto":!l.cancelButtonVisible}]),size:"lg",action:l.executeConfirmAction,label:e.$t(t.confirmButton.caption,{$capitalize:!0})},null,8,["disabled","variant","class","action","label"])):c("",!0)])])])],4)):c("",!0)]),_:1}),B(V,{name:"modalBackdropEntry"},{default:k(()=>[t.visible?(i(),r("div",j)):c("",!0)]),_:1})])}const F=_(z,[["render",N]]);export{F as default};