import{T as M}from"./vendor-vue-runtime-dom-B2rky8vu.js";import{_}from"./settings.consts-BmuAyinH.js";import{d as U,e as j,a as A,b as G,f as r,i as a,t as b,x as l,j as d,k as K,m as Y,F as J,r as Q,T as X,n as Z}from"./vendor-vue-runtime-core-DwK6Ry68.js";import{t as ee,r as u,u as s}from"./vendor-vue-reactivity-CheHbvBM.js";import{a as S,b as te}from"./vendor-vue-shared-DrzsEcag.js";const oe={key:0,class:"ccb-dropdown__required"},ne={class:"ccb-dropdown-input"},ae=["onClick"],g=4,T=8,se=120,pe=U({__name:"Dropdown",props:{label:{},items:{},modelValue:{},required:{type:Boolean},name:{},variant:{},showOriginal:{type:Boolean}},emits:["update:modelValue","change"],setup(B,{emit:N}){const V=B,h=N,{label:k,items:x,modelValue:z,required:H,name:P,variant:$,showOriginal:I}=ee(V),n=u(!1),p=u(null),m=u(null),y=u({}),O=()=>{var C;const t=(C=p.value)==null?void 0:C.querySelector(".ccb-dropdown-input");if(!t)return;const e=t.getBoundingClientRect(),o=window.innerHeight,i=m.value,v=(i==null?void 0:i.offsetHeight)||220,w=o-e.bottom-T,R=e.top-T,f=w<Math.min(v,se)&&R>w,W=Math.max((f?R:w)-g,0);y.value={position:"fixed",left:`${e.left}px`,width:`${e.width}px`,zIndex:"99999",maxHeight:`${W}px`,overflowY:"auto",top:f?"auto":`${e.bottom+g}px`,bottom:f?`${o-e.top+g}px`:"auto"}},c=()=>{n.value&&O()},D=()=>{n.value=!n.value,n.value&&Z(()=>{O()})},q=t=>{if(t.disabled)return;const e=t.value;h("update:modelValue",e),h("change",P.value||"",e),n.value=!1},E=t=>{if(!n.value)return;const e=p.value,o=m.value;if(t.target instanceof Node){const i=e==null?void 0:e.contains(t.target),v=o==null?void 0:o.contains(t.target);!i&&!v&&(n.value=!1)}},L=t=>{n.value&&t.key==="Escape"&&(n.value=!1)},F=j(()=>t=>{var e;return((e=x.value.find(o=>o.value.toString()===t.toString()))==null?void 0:e.label)||"Select item"});return A(()=>{document.addEventListener("click",E),document.addEventListener("keydown",L),window.addEventListener("resize",c),window.addEventListener("scroll",c,!0)}),G(()=>{document.removeEventListener("click",E),document.removeEventListener("keydown",L),window.removeEventListener("resize",c),window.removeEventListener("scroll",c,!0)}),(t,e)=>(a(),r("div",{class:S(["ccb-dropdown",{"ccb-dropdown-open":n.value,"ccb-dropdown-variant-innerLabel":s($)==="innerLabel"}]),ref_key:"rootRef",ref:p},[s(k)?(a(),r("div",{key:0,class:"ccb-dropdown__label",onClick:D},[d(_,{text:s(k),size:"s",weight:"regular"},null,8,["text"]),s(H)?(a(),r("span",oe,"*")):b("",!0)])):b("",!0),l("div",ne,[l("div",{class:"ccb-dropdown-input__wrapper",onClick:D},[d(_,{text:F.value(s(z)),class:"ccb-dropdown-input__text",size:"m",weight:"medium",showOriginal:!0},null,8,["text"]),e[0]||(e[0]=l("span",{class:"ccb-dropdown-input__icon"},[l("i",{class:"ccb-icon-ic_caret_down"})],-1))]),(a(),K(X,{to:"body"},[d(M,{name:"dropdown"},{default:Y(()=>[n.value?(a(),r("div",{key:0,class:"ccb-dropdown-options ccb-custom-scrollbar",style:te(y.value),ref_key:"optionsRef",ref:m},[(a(!0),r(J,null,Q(s(x),o=>(a(),r("div",{class:S(["ccb-dropdown-options__item",{"ccb-dropdown-options__item--disabled":o.disabled}]),key:o.value,onClick:i=>q(o)},[d(_,{text:o.label,size:"m",weight:"medium",showOriginal:s(I)},null,8,["text","showOriginal"])],10,ae))),128))],4)):b("",!0)]),_:1})]))])],2))}});export{pe as _};
//# sourceMappingURL=Dropdown.vue_vue_type_script_setup_true_lang-vYYwSDyA.js.map
