import{g as Pe,t as Ae,b1 as ke,r as o,b2 as he,b3 as ne,b4 as _e,b5 as ve,b6 as Fe,b7 as Ee,b8 as Ie,b9 as Re,ba as We,bb as qe,D as ze,bc as De,O as Ce,bd as Be,a as B,m as I,n as Te,b as Y,a1 as He,u as Je,e as oe,j as g,z as Ue,be as xe,ac as T,F as Ze,aZ as Ge,$ as Ke,bf as Qe,bg as Xe,bh as Ye}from"./entry.client-CV0PzNS2.js";import{i as we}from"./isNil-DJ_omAdg.js";import{t as et}from"./trim-BKnRwbL4.js";import{u as tt}from"./useFlexiblePrefillValues-CdKhmvNK.js";import{u as at}from"./useFlexibleOptions-BzusANQ_.js";var nt=Ae;function ot(){var t=arguments,e=nt(t[0]);return t.length<3?e:e.replace(t[1],t[2])}var st=ot;const $e=Pe(st);var rt=["allowCreateWhileLoading","createOptionPosition","formatCreateLabel","isValidNewOption","getNewOptionData","onCreateOption","options","onChange"],Oe=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"",n=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,i=String(e).toLowerCase(),s=String(r.getOptionValue(n)).toLowerCase(),m=String(r.getOptionLabel(n)).toLowerCase();return s===i||m===i},se={formatCreateLabel:function(e){return'Create "'.concat(e,'"')},isValidNewOption:function(e,n,r,i){return!(!e||n.some(function(s){return Oe(e,s,i)})||r.some(function(s){return Oe(e,s,i)}))},getNewOptionData:function(e,n){return{label:n,value:e,__isNew__:!0}}};function lt(t){var e=t.allowCreateWhileLoading,n=e===void 0?!1:e,r=t.createOptionPosition,i=r===void 0?"last":r,s=t.formatCreateLabel,m=s===void 0?se.formatCreateLabel:s,O=t.isValidNewOption,S=O===void 0?se.isValidNewOption:O,P=t.getNewOptionData,L=P===void 0?se.getNewOptionData:P,A=t.onCreateOption,q=t.options,$=q===void 0?[]:q,k=t.onChange,d=ke(t,rt),b=d.getOptionValue,H=b===void 0?Fe:b,M=d.getOptionLabel,J=M===void 0?Ee:M,h=d.inputValue,p=d.isLoading,U=d.isMulti,N=d.value,z=d.name,V=o.useMemo(function(){return S(h,he(N),$,{getOptionValue:H,getOptionLabel:J})?L(h,m(h)):void 0},[m,L,J,H,h,S,$,N]),Z=o.useMemo(function(){return(n||!p)&&V?i==="first"?[V].concat(ne($)):[].concat(ne($),[V]):$},[n,i,p,V,$]),_=o.useCallback(function(v,C){if(C.action!=="select-option")return k(v,C);var y=Array.isArray(v)?v:[v];if(y[y.length-1]===V){if(A)A(h);else{var j=L(h,h),x={action:"create-option",name:z,option:j};k(_e(U,[].concat(ne(he(N)),[j]),j),x)}return}k(v,C)},[L,h,U,z,V,A,k,N]);return ve(ve({},d),{},{options:Z,onChange:_})}var it=o.forwardRef(function(t,e){var n=Ie(t),r=lt(n);return o.createElement(Re,We({ref:e},r))}),Ve=it;const R=(t,e)=>{const[n,r]=o.useState(e);return o.useEffect(()=>{r(`${$e(et(window.getComputedStyle(document.body).getPropertyValue(t)),"#","")}`)},[t]),n},ct=Xe(Ve),Se={page:1},ye=t=>({control:e=>({...e,border:0,boxShadow:0,backgroundColor:"transparent",minHeight:36}),menu:e=>({...e,zIndex:10,margin:0}),menuList:e=>({...e,padding:"2px",borderRadius:5}),singleValue:e=>({...e,color:t.primary}),input:e=>({...e,color:t.primary}),valueContainer:e=>({...e,padding:"2px 4px"}),multiValue:e=>({...e,backgroundColor:"#eee",borderRadius:5,overflow:"hidden"}),multiValueLabel:e=>({...e,paddingLeft:10,paddingRight:10}),multiValueRemove:e=>({...e,borderRadius:0,color:"hsl(0, 0%, 60%)",transition:"color .15s ease",":hover":{...e[":hover"],color:"hsl(0, 0%, 40%)",backgroundColor:"transparent"}}),option:(e,{isDisabled:n,isFocused:r,isSelected:i})=>({...e,transition:"background-color .15s ease, color .15s ease",borderRadius:5,backgroundColor:n?null:i?t.accent:r?t.lightAccent:null,color:n?t.light:i||r?t.overAccent:t.primary,cursor:n?"not-allowed":"default",marginBottom:"2px",":last-child":{...e[":last-child"],marginBottom:0},":active":{...e[":active"],backgroundColor:!n&&t.darkAccent,color:n?t.light:t.overAccent},":hover":{backgroundColor:"#efefef"}})}),W={theme:{extend:{colors:{overAccent:"",primary:"",light:"",accent:{500:"",700:"",300:""}}}}},Me=t=>{const e=R("--accent-500",W.theme.extend.colors.accent[500]),n=R("--accent-700",W.theme.extend.colors.accent[700]),r=R("--accent-300",W.theme.extend.colors.accent[300]),i=R("--over-accent",W.theme.extend.colors.overAccent),s=R("--primary",W.theme.extend.colors.primary),m=R("--light",W.theme.extend.colors.light),[O,S]=o.useState(t||{accent:e,darkAccent:n,lightAccent:r,overAccent:i,primary:s,light:m});return o.useEffect(()=>{S(t||{accent:e,darkAccent:n,lightAccent:r,overAccent:i,primary:s,light:m})},[e,t,n,m,r,i,s]),o.useMemo(()=>ye(O),[O])},Le={base:"w-full flex flex-col px-1",width:{...Ye("md")}},ut=t=>{var fe,be;const{id:e,className:n="",label:r,placeholder:i="",multi:s=!1,searchable:m=!0,noOptionsMessage:O="",loadingMessage:S="",createMessage:P="",clearable:L=!0,creatable:A=!1,icon:q=void 0,defaultLabel:$=void 0,defaultValue:k=void 0,ajax:d=void 0,hubspotInternalValue:b,colors:H=void 0,menuPlacement:M="auto",showError:J=!0,width:h="100"}=t,p=o.useMemo(()=>t.dependencies??[],[t.dependencies]),U=o.useMemo(()=>t.options??[],[t.options]),{register:N,unregister:z,watch:V,trigger:Z,setValue:_,formState:v,getValues:C}=qe(),{locale:y}=ze(),j=De(t.validation),x=at(U??[]),re=tt({id:e}),w=re.defaultValue||k,D=re.defaultLabel||$,le=o.useMemo(()=>w&&x?Ce(x,a=>!we(a.value)&&a.value===w):null,[w,x]),[f,ie]=o.useState([D&&w?[{label:D,value:w}]:le?[le]:[]]),{addInputId:ce,removeInputId:ue}=Be();o.useEffect(()=>(ce(e),()=>{ue(e)}),[ce,ue,e]),o.useEffect(()=>{let a=f!=null?B(I(f,c=>b?c==null?void 0:c.value:c==null?void 0:c.label),c=>c!=null):[];return a=s?a:a.length>0?a[0]:null,N(e,{...j,value:a}),()=>{z(e)}},[b,e,f,s,N,z,j]);const de=o.useCallback(async(a,c,l)=>{if(d){const u=(l==null?void 0:l.page)||1,te={s:a,page:u,locale:y};Te(p,E=>{if(Y(E)){const ae=C(E[0]);ae&&(te[E[1]]=ae)}else C(E)&&(te[E]=C(E))});const X=await He.get(d,{params:te,headers:{"Accept-Language":y}});return X.status===200?{options:X.data.data,hasMore:X.data.current_page<X.data.last_page,additional:{page:u+1}}:{options:[],hasMore:!1,additional:{page:u+1}}}return{options:[],hasMore:!1,additional:{page:1}}},[d,p,C,y]),{t:F}=Je("core"),G=o.useCallback(()=>oe(O)?F("form.select.no_options"):O,[O,F]),ge=o.useCallback(a=>$e(oe(P)?F("form.select.create"):P,"{userInput}",a),[P,F]),me=o.useCallback(()=>oe(S)?F("form.select.loading"):S,[S,F]),Ne=o.useMemo(()=>Y(p)&&p.length>0?I(p,a=>Y(a)?a[0]:a):[],[p]),ee=V(Ne),je=JSON.stringify(ee);o.useEffect(()=>{const a=[];if(D&&w)a.push({label:D,value:w});else if(w&&x){const l=Ce(x,u=>!we(u.value)&&u.value===w);l&&a.push(l)}const c=B(I(a,l=>b?l==null?void 0:l.value:l==null?void 0:l.label),l=>l!=null);_(e,s?c:c.length>0?c[0]:null),ie(B(a,l=>l!=null))},[D,w,b,e,s,x,_,je]);const K=o.useCallback(a=>{const c=Y(a)?a:[a],l=c!=null?B(I(c,u=>b?u==null?void 0:u.value:u==null?void 0:u.label),u=>u!=null):[];_(e,s?l:l.length>0?l[0]:null),Z(e).catch(),ie(B(c,u=>u!=null))},[b,e,s,_,Z]),pe=o.useMemo(()=>[d,p,ee,C,y],[d,p,ee,C,y]),Q=Me(H);return g.jsxs("div",{className:Ue(Le.base,Le.width[h],n),children:[r&&g.jsx(xe,{htmlFor:`select-${e}`,required:T(j,"required.value",!1),children:r}),g.jsx("div",{className:"relative rounded-md shadow-sm flex h-full",children:g.jsxs("div",{className:`relative flex-1 flex rounded-md transition-all duration-200 ${T(v.errors,e)?"ring-2 ring-error-500 focus-within:ring-accent-300 focus-within:ring-1":f&&f.length>0?"ring-1 ring-valid-500 focus-within:ring-accent-500 focus-within:ring-2":"ring-1 ring-gray-300 focus-within:ring-accent-500 focus-within:ring-2"}`,children:[q&&g.jsx("div",{className:"pl-3 pr-1 flex items-center pointer-events-none",children:g.jsx(Ze,{name:q})}),d&&(A?g.jsx(ct,{id:`select-${e}`,name:`reactselect-${e}`,styles:Q,className:"react-select bg-transparent border-0 flex-1 min-w-0 block w-full sm:text-sm outline-none focus:shadow-none focus:ring-0",isMulti:s,isSearchable:m,isClearable:L,placeholder:i,value:f,loadOptions:de,cacheUniqs:pe,additional:Se,noOptionsMessage:G,loadingMessage:me,onChange:K,formatCreateLabel:ge,menuPlacement:M}):g.jsx(Ge,{id:`select-${e}`,name:`reactselect-${e}`,styles:Q,className:"react-select bg-transparent border-0 flex-1 min-w-0 block w-full sm:text-sm outline-none focus:shadow-none focus:ring-0",isMulti:s,isSearchable:m,isClearable:L,placeholder:i,value:f,loadOptions:de,cacheUniqs:pe,additional:Se,noOptionsMessage:G,loadingMessage:me,onChange:K,menuPlacement:M})),!d&&(A?g.jsx(Ve,{id:`select-${e}`,name:`reactselect-${e}`,styles:Q,className:"react-select bg-transparent border-0 flex-1 min-w-0 block w-full sm:text-sm outline-none focus:shadow-none focus:ring-0",isMulti:s,isSearchable:m,isClearable:L,placeholder:i,value:f,options:x,noOptionsMessage:G,onChange:K,formatCreateLabel:ge,menuPlacement:M}):g.jsx(Ke,{id:`select-${e}`,name:`reactselect-${e}`,styles:Q,className:"react-select bg-transparent border-0 flex-1 min-w-0 block w-full sm:text-sm outline-none focus:shadow-none focus:ring-0",isMulti:s,isSearchable:m,isClearable:L,placeholder:i,value:f,options:x,noOptionsMessage:G,onChange:K,menuPlacement:M}))]})}),g.jsx(xe,{htmlFor:e,className:"hidden",children:r}),g.jsx("select",{name:e,value:I(f,a=>a.value),multiple:!0,className:"hidden",children:I(f,(a,c)=>g.jsx("option",{value:a.value,children:b?a.value:a.label},c))}),J&&T(v.errors,e)&&((fe=T(v.errors,e))==null?void 0:fe.message)&&g.jsx(Qe,{children:`${(be=T(v.errors,e))==null?void 0:be.message}`})]})},bt=Object.freeze(Object.defineProperty({__proto__:null,Select:ut,SelectStyle:ye,useSelectStyle:Me},Symbol.toStringTag,{value:"Module"}));export{ut as S,bt as a,$e as r,Me as u};