import{r as u,e_ as e,j as t,ey as q,e$ as A}from"./index-BbiZcFRx.js";import{u as B}from"./useWindowSize-C66I80Fn.js";const F=(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(A,{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:y}=B();F(x,()=>{j(!1),d&&p&&p()}),u.useEffect(()=>{C(h),j(i)},[h,i]);const P=(c,s)=>{c.preventDefault(),C(s),g&&g(s),O()},O=c=>{c&&c.preventDefault(),j(s=>!s&&!n),d&&p&&p()},[z,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 y?{maxHeight:Math.max(Math.min(y-c,(b.length+1)*40),Math.min(b.length+1,3)*40)+2}:{maxHeight:0}},[b.length,d,y]),I=t.jsxs("div",{className:`${r?"has-error":""} ${L?"show-always":""} ${N||"input"} inputbox`,onClick:O,children:[v?t.jsx(l,{prefix:T,...z,showValueAsLabel:w}):t.jsx("span",{className:M||"placeholder",children:$}),t.jsx(q,{})]}),W=t.jsxs("div",{className:"select-header",children:[t.jsx("div",{className:"prefix",children:$}),t.jsx("button",{onClick:O,children:"×"})]}),_=t.jsxs("div",{className:"options",style:{maxHeight:E.maxHeight-40},children:[W,b.map((c,s)=>t.jsx(l,{prefix:f,...c,onClick:P},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&&_]})})};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-CyvA8p1q.js.map