import{s as C,r as n,u as W,J as I,M as O,N as V,e as H,j as r,l as L,O as N,T as P,P as $,W as B,Q as E,R as F,X as k,Y as A}from"./index.Bzd-hLkw.js";import{u as D}from"./useBasicWidgetState.OjIRYQBB.js";import"./FormClearHelper.DHOVMdUr.js";const U=C("div",{target:"euzcfsp0"})(({theme:o})=>({"span[aria-disabled='true']":{background:o.colors.fadedText05}})),Y=(o,t)=>o.getStringArrayValue(t),j=o=>o.default.map(t=>o.options[t])??null,K=o=>o.rawValues??null,X=(o,t,a,l)=>{t.setStringArrayValue(o,a.value,{fromUi:a.fromUi},l)},G=o=>{const{element:t,widgetMgr:a,fragmentId:l}=o,e=W(),S=n.useContext(I),[i,d]=D({getStateFromWidgetMgr:Y,getDefaultStateFromProto:j,getCurrStateFromProto:K,updateWidgetMgrState:X,element:t,widgetMgr:a,fragmentId:l}),p=t.maxSelections>0&&i.length>=t.maxSelections,f=n.useMemo(()=>{if(t.maxSelections===0)return"No results";if(i.length===t.maxSelections){const s=t.maxSelections!==1?"options":"option";return`You can only select up to ${t.maxSelections} ${s}. Remove an option first.`}return"No results"},[t.maxSelections,i.length]),u=n.useCallback(s=>{switch(s.type){case"remove":return O(i,s.option?.value);case"clear":return[];case"select":return i.concat([s.option?.value]);default:throw new Error(`State transition is unknown: ${s.type}`)}},[i]),b=n.useCallback(s=>{t.maxSelections&&s.type==="select"&&i.length>=t.maxSelections||d({value:u(s),fromUi:!0})},[t.maxSelections,u,d,i.length]),{options:x}=t,{placeholder:y,disabled:v,selectOptions:z,inputReadOnly:M,valuesToUiMulti:g,createFilterOptions:m}=V({options:x,isMulti:!0,acceptNewOptions:t.acceptNewOptions??!1,placeholderInput:t.placeholder}),T=n.useCallback((s,h)=>p?[]:m(i)(s,h),[m,p,i]),c=o.disabled||v,w=n.useMemo(()=>g(i),[g,i]),R=n.useMemo(()=>{const s=e.fontSizes.baseFontSize*1.6+14;return`${Math.round(s*4.25)}px`},[e.fontSizes.baseFontSize]);return H("div",{className:"stMultiSelect","data-testid":"stMultiSelect",children:[r(B,{label:t.label,disabled:c,labelVisibility:L(t.labelVisibility?.value),children:t.help&&r(N,{children:r(P,{content:t.help,placement:$.TOP_RIGHT})})}),r(U,{children:r(E,{creatable:t.acceptNewOptions??!1,options:z,labelKey:"label",valueKey:"value","aria-label":t.label,placeholder:y,type:A.select,multi:!0,onChange:b,value:w,disabled:c,size:"compact",noResultsMsg:f,filterOptions:T,closeOnSelect:!1,ignoreCase:!1,overrides:{Popover:{props:{ignoreBoundary:S,overrides:{Body:{style:()=>({marginTop:e.spacing.px})}}}},SelectArrow:{component:k,props:{style:{cursor:"pointer"},overrides:{Svg:{style:()=>({width:e.iconSizes.xl,height:e.iconSizes.xl})}}}},IconsContainer:{style:()=>({paddingRight:e.spacing.sm})},ControlContainer:{style:{maxHeight:R,minHeight:e.sizes.minElementHeight,borderLeftWidth:e.sizes.borderWidth,borderRightWidth:e.sizes.borderWidth,borderTopWidth:e.sizes.borderWidth,borderBottomWidth:e.sizes.borderWidth}},Placeholder:{style:()=>({flex:"inherit",color:c?e.colors.fadedText40:e.colors.fadedText60})},ValueContainer:{style:()=>({overflowY:"auto",paddingLeft:e.spacing.sm,paddingTop:e.spacing.none,paddingBottom:e.spacing.none,paddingRight:e.spacing.none})},ClearIcon:{props:{overrides:{Svg:{style:{color:e.colors.grayTextColor,padding:e.spacing.threeXS,height:e.sizes.clearIconSize,width:e.sizes.clearIconSize,cursor:"pointer",":hover":{fill:e.colors.bodyText}}}}}},SearchIcon:{style:{color:e.colors.grayTextColor}},Tag:{props:{overrides:{Root:{style:{fontWeight:e.fontWeights.normal,borderTopLeftRadius:e.radii.md,borderTopRightRadius:e.radii.md,borderBottomRightRadius:e.radii.md,borderBottomLeftRadius:e.radii.md,fontSize:e.fontSizes.md,paddingLeft:e.spacing.sm,marginLeft:e.spacing.none,marginRight:e.spacing.sm,height:`calc(${e.sizes.minElementHeight} - 2 * ${e.spacing.xs})`,maxWidth:`calc(100% - ${e.spacing.lg})`,cursor:"default !important"}},Action:{style:{paddingLeft:0}},ActionIcon:{props:{overrides:{Svg:{style:{width:"0.625em",height:"0.625em"}}}}}}}},MultiValue:{props:{overrides:{Root:{style:{fontSize:e.fontSizes.sm}}}}},Input:{props:{readOnly:M}},Dropdown:{component:F}}})})]})},q=n.memo(G);export{q as default};
