import{_ as D,R as m,c as n,b as h,e as p,J as K,t as u,D as d,E as y,G as f,S as _,I as v,F as g,g as O,o as l}from"./Bgmy51Qv.js";let w=0;function N(e="id"){return w+=1,`${e}-${w}`}const b={setup(){return{currentId:N("dropdown")}},name:"Dropdown",data(){return{optionsData:this.options,searched:"",dropdownOpen:!1,hasLayer:this.layer,selectedKeyData:""}},mounted(){this.selectedKeyData=this.selectedKey??Object.keys(this.options)[0],this.processSelected(this.options)},watch:{options(e){this.processSelected(e)},selectedKey(e){this.selectedKeyData=e},searched(e){this.doSearch(e)}},props:{disabled:{type:Boolean,default:!1},defaultNull:{type:Boolean,default:!1},positionFixed:{type:Boolean,default:!0},options:{type:Object,default(){return{0:{title:"--------------"}}}},selectedKey:{default(){return null}},keyName:{type:String,default:"title"},searching:{type:Boolean,default:!1},layer:{type:Boolean,default:!1}},directives:{outsideClick:m},computed:{isSmallerDevice(){return window.innerWidth<=768},opt(){return this.optionsData??null},currentKey(){return this.selectedKeyData&&this.options[this.selectedKeyData]?this.selectedKeyData:Object.keys(this.optionsData)[0]},selectedValue(){return this.opt&&this.opt[this.currentKey]&&this.opt[this.currentKey][this.keyName]?this.opt[this.currentKey][this.keyName]:"--------------"}},methods:{processSelected(e){!this.selectedKey&&!this.defaultNull?(this.selectedKeyData=Object.keys(e)[0],this.$emit("clicked",{key:this.selectedKeyData,value:e[0]})):!this.selectedKey&&this.defaultNull?(e[0]={title:"--------------"},this.selectedKeyData="0"):this.defaultNull&&(e[0]={title:"--------------"}),this.optionsData=e},doSearch(e){var a;this.optionsData={};const t=this.options;for(const r in t)(a=t[r][this.keyName])!=null&&a.toLowerCase().includes(e.toLowerCase())&&(this.opt[r]=t[r])},openDropdown(){if(this.disabled)return!1;this.isSmallerDevice&&(this.hasLayer=!0),this.hasLayer&&this.positionFixed&&document.body.classList.add("no-scroll"),this.dropdownOpen=!this.dropdownOpen,this.$emit("value",this.dropdownOpen),this.searching&&this.dropdownOpen&&this.$nextTick(()=>{this.$refs.searcBox.focus()})},closeDropdown(){this.positionFixed&&document.body.classList.remove("no-scroll"),this.dropdownOpen=!1,this.$emit("value",this.dropdownOpen)},changed(e,t){this.$emit("changed",{key:e,value:t}),this.clicked(e,t)},clicked(e,t){this.closeDropdown(),this.searched="",(e!=="0"&&this.currentKey!==e||this.defaultNull&&this.currentKey!==e)&&(this.selectedKeyData=e,this.$emit("clicked",{key:e,value:t}))}}},B=["data-ignore"],C={key:0,class:"dropdown-wrapper"},S=["data-ignore"],L=["id"],I=["onClick"];function x(e,t,a,r,s,i){const k=_("outside-click");return l(),n("div",{class:d(["custom-dropdown",{open:s.dropdownOpen}])},[h("span",{"data-ignore":r.currentId,class:d({disabled:a.disabled}),onClick:t[0]||(t[0]=y((...o)=>i.openDropdown&&i.openDropdown(...o),["prevent"]))},[K(u(i.selectedValue)+" ",1),h("i",{class:d(["icon black ignore-click",[{"arrow-up":s.dropdownOpen},{"arrow-down":!s.dropdownOpen}]])},null,2)],10,B),s.dropdownOpen?(l(),n("div",C,[s.hasLayer?(l(),n("div",{key:0,"data-ignore":r.currentId,class:"layer",onClick:t[1]||(t[1]=(...o)=>i.closeDropdown&&i.closeDropdown(...o))},null,8,S)):p("",!0),f((l(),n("div",{class:"dropdown-inner",id:r.currentId},[a.searching?f((l(),n("input",{key:0,ref:"searcBox",type:"text","onUpdate:modelValue":t[2]||(t[2]=o=>s.searched=o)},null,512)),[[v,s.searched]]):p("",!0),h("ul",null,[(l(!0),n(g,null,O(i.opt,(o,c)=>(l(),n("li",{key:c,class:d({active:`${s.selectedKeyData}`==`${c}`}),onClick:y(V=>i.changed(c,o),["prevent"])},u(o[a.keyName]),11,I))),128))])],8,L)),[[k,i.closeDropdown]])])):p("",!0)],2)}const j=D(b,[["render",x]]);export{j as _};
