import{aT as T,aU as W,aV as I,aW as L,F as V,r as n,l as A,aA as O,aX as B,o as E,j as m,p as H,ab as F,ac as N,aY as $,aZ as k,aw as D,a_ as P,ae as U}from"./index.CS3tpmQq.js";import{u as Y}from"./useBasicWidgetState.DxPSDiCY.js";import{a as j}from"./_arrayIncludes.B19Iyn2B.js";import"./FormClearHelper.DyKNX1aO.js";import"./_baseIndexOf.BTknn6Gb.js";var _=200;function K(o,t,d,p){var e=-1,g=j,s=!0,u=o.length,a=[],f=t.length;if(!u)return a;t.length>=_&&(g=W,s=!1,t=new T(t));e:for(;++e<u;){var i=o[e],c=i;if(i=i!==0?i:0,s&&c===c){for(var h=f;h--;)if(t[h]===c)continue e;a.push(i)}else g(t,c,p)||a.push(i)}return a}var X=I(function(o,t){return L(o)?K(o,t):[]});const Z=V("div",{target:"euzcfsp0"})(({theme:o})=>({"span[aria-disabled='true']":{background:o.colors.fadedText05}})),G=(o,t)=>o.getStringArrayValue(t),q=o=>o.default.map(t=>o.options[t])??null,J=o=>o.rawValues??null,Q=(o,t,d,p)=>{t.setStringArrayValue(o,d.value,{fromUi:d.fromUi},p)},ee=o=>{const{element:t,widgetMgr:d,fragmentId:p}=o,e=A(),g=n.useContext(O),[s,u]=Y({getStateFromWidgetMgr:G,getDefaultStateFromProto:q,getCurrStateFromProto:J,updateWidgetMgrState:Q,element:t,widgetMgr:d,fragmentId:p}),a=t.maxSelections>0&&s.length>=t.maxSelections,f=n.useMemo(()=>{if(t.maxSelections===0)return"No results";if(s.length===t.maxSelections){const r=t.maxSelections!==1?"options":"option";return`You can only select up to ${t.maxSelections} ${r}. Remove an option first.`}return"No results"},[t.maxSelections,s.length]),i=n.useCallback(r=>{switch(r.type){case"remove":return X(s,r.option?.value);case"clear":return[];case"select":return s.concat([r.option?.value]);default:throw new Error(`State transition is unknown: ${r.type}`)}},[s]),c=n.useCallback(r=>{t.maxSelections&&r.type==="select"&&s.length>=t.maxSelections||u({value:i(r),fromUi:!0})},[t.maxSelections,i,u,s.length]),{options:h}=t,{placeholder:y,disabled:C,selectOptions:v,inputReadOnly:w,valuesToUiMulti:S,createFilterOptions:x}=B({options:h,isMulti:!0,acceptNewOptions:t.acceptNewOptions??!1,placeholderInput:t.placeholder}),z=n.useCallback((r,l)=>a?[]:x(s)(r,l),[x,a,s]),b=o.disabled||C,R=n.useMemo(()=>S(s),[S,s]),M=n.useMemo(()=>{const r=e.fontSizes.baseFontSize*1.6+14;return`${Math.round(r*4.25)}px`},[e.fontSizes.baseFontSize]);return E("div",{className:"stMultiSelect","data-testid":"stMultiSelect",children:[m(N,{label:t.label,disabled:b,labelVisibility:H(t.labelVisibility?.value),children:t.help&&m(F,{content:t.help,label:t.label})}),m(Z,{children:m($,{creatable:t.acceptNewOptions??!1,options:v,labelKey:"label",valueKey:"value","aria-label":t.label,placeholder:y,type:P.select,multi:!0,onChange:c,value:R,disabled:b,size:"compact",noResultsMsg:f,filterOptions:z,closeOnSelect:!1,ignoreCase:!1,overrides:{Popover:{props:{ignoreBoundary:g,overrides:{Body:{style:()=>({marginTop:e.spacing.px})}}}},SelectArrow:{component:D,props:{style:{cursor:"pointer"},overrides:{Svg:{style:()=>({width:e.iconSizes.xl,height:e.iconSizes.xl})}}}},IconsContainer:{style:()=>({paddingRight:e.spacing.sm})},ControlContainer:{style:({$isFocused:r})=>{const l=U(e.colors,r);return{maxHeight:M,minHeight:e.sizes.minElementHeight,borderLeftWidth:e.sizes.borderWidth,borderRightWidth:e.sizes.borderWidth,borderTopWidth:e.sizes.borderWidth,borderBottomWidth:e.sizes.borderWidth,borderTopColor:l,borderRightColor:l,borderBottomColor:l,borderLeftColor:l}}},Placeholder:{style:()=>({flex:"inherit",color:b?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:w}},Dropdown:{component:k}}})})]})},ne=n.memo(ee);export{ne as default};
