import{r as u,e$ as e,j as t,ez as A,f0 as B}from"./index-CNnTZTc7.js";import{u as F}from"./useWindowSize-CksQ0guy.js";const G=(l,a)=>{u.useEffect(()=>{const n=r=>{!l.current||l.current.contains(r.target)||a(r)};return document.addEventListener("mousedown",n),document.addEventListener("touchstart",n),()=>{document.removeEventListener("mousedown",n),document.removeEventListener("touchstart",n)}},[l,a])},H=({label:l,onClick:a,optionsClass:n,prefix:r="",selected:h=!1,showValueAsLabel:i,value:f,...p})=>{const g=m=>{a&&a(m,f)};return t.jsxs("div",{...p,className:`${n?"tobaccoOption":"selectOption"} option ${h?"selected":""}`,onClick:g,children:[r&&t.jsx(B,{className:"heading6",text:r}),i?f:l]})};H.propTypes={label:e.string,selected:e.bool,value:e.any,onClick:e.func,style:e.object,prefix:e.string};const S=({Option:l,contactsPage:a,disabled:n,error:r,initialValue:h,isDefaultOpen:i=!1,labelPrefix:f="",onBlur:p,onChange:g,options:m,optionsClass:k,placeholder:$,placeholderClass:M,prefix:T="",providerModal:D,selectInputBoxClass:N,showValueAlways:L=!1,showValueAsLabel:w=!1,style:R})=>{const[d,j]=u.useState(i),[v,C]=u.useState(h),x=u.useRef(),{height:O}=F();G(x,()=>{j(!1),d&&p&&p()}),u.useEffect(()=>{C(h),j(i)},[h,i]);const z=(c,s)=>{c.preventDefault(),C(s),g&&g(s),y()},y=c=>{c&&c.preventDefault(),j(s=>!s&&!n),d&&p&&p()},[P,b]=u.useMemo(()=>{j(i);const c=m.filter(o=>(o==null?void 0:o.value)===v),s=m.map(o=>({...o,selected:(o==null?void 0:o.value)===v,optionsClass:k}));return[c[0],s]},[m,v,i]),E=u.useMemo(()=>{var s;const c=d?((s=x==null?void 0:x.current)==null?void 0:s.getBoundingClientRect().top)+40:40;return O?{maxHeight:Math.max(Math.min(O-c,(b.length+1)*40),Math.min(b.length+1,3)*40)+2}:{maxHeight:0}},[b.length,d,O]),I=t.jsxs("div",{className:`${r?"has-error":""} ${L?"show-always":""} ${N||"input"} inputbox`,onClick:y,children:[v?t.jsx(l,{prefix:T,...P,showValueAsLabel:w}):t.jsx("span",{className:M||"placeholder",children:$}),t.jsx(A,{})]}),W=t.jsxs("div",{className:"select-header",children:[t.jsx("div",{className:"prefix",children:$}),t.jsx("button",{onClick:y,children:"×"})]}),q=t.jsxs("div",{className:"options",style:{maxHeight:E.maxHeight-40},children:[W,b.map((c,s)=>t.jsx(l,{prefix:f,...c,onClick:z},s))]});return t.jsx("div",{ref:x,style:R,className:`select ${a&&"contacts-dd"} ${D&&"pr-select"} ${!d&&w?"short-label":""}`,children:t.jsxs("div",{className:`select-container ${d?"opened":"closed"} ${n?"disabled":""}`,style:E,children:[I,d&&!n&&q]})})};S.propTypes={initialValue:e.string,prefix:e.string,placeholder:e.string,onChange:e.func,onBlur:e.func,Option:e.elementType,style:e.object,isDefaultOpen:e.bool,disabled:e.bool,error:e.bool};S.defaultProps={placeholder:"- Select -",prefix:"",initialValue:null,options:[],Option:H,style:{},isDefaultOpen:!1,disabled:!1,onBlur:()=>{},error:!1};export{S}; //# sourceMappingURL=index-Dik5vxIa.js.map