import{aP as M,aQ as W,aR as I,aS as L,z as V,r as n,g as O,aB as B,aT as H,l as P,j as g,m as A,ad as E,T as N,P as $,ae as F,aU as k,aV as D,ax as U,aW as j,ag as Y}from"./index.BN4Hj9cC.js";import{u as _}from"./useBasicWidgetState.BL6Uby3R.js";import{a as G}from"./_arrayIncludes.B19Iyn2B.js";import"./FormClearHelper.D2cMsU2H.js";import"./_baseIndexOf.BTknn6Gb.js";var K=200;function Q(o,t,d,p){var e=-1,h=G,s=!0,u=o.length,a=[],f=t.length;if(!u)return a;t.length>=K&&(h=W,s=!1,t=new M(t));e:for(;++e<u;){var i=o[e],c=i;if(i=i!==0?i:0,s&&c===c){for(var m=f;m--;)if(t[m]===c)continue e;a.push(i)}else h(t,c,p)||a.push(i)}return a}var X=I(function(o,t){return L(o)?Q(o,t):[]});const Z=V("div",{target:"euzcfsp0"})(({theme:o})=>({"span[aria-disabled='true']":{background:o.colors.fadedText05}})),q=(o,t)=>o.getStringArrayValue(t),J=o=>o.default.map(t=>o.options[t])??null,ee=o=>o.rawValues??null,te=(o,t,d,p)=>{t.setStringArrayValue(o,d.value,{fromUi:d.fromUi},p)},oe=o=>{const{element:t,widgetMgr:d,fragmentId:p}=o,e=O(),h=n.useContext(B),[s,u]=_({getStateFromWidgetMgr:q,getDefaultStateFromProto:J,getCurrStateFromProto:ee,updateWidgetMgrState:te,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:m}=t,{placeholder:y,disabled:C,selectOptions:v,inputReadOnly:z,valuesToUiMulti:b,createFilterOptions:x}=H({options:m,isMulti:!0,acceptNewOptions:t.acceptNewOptions??!1,placeholderInput:t.placeholder}),R=n.useCallback((r,l)=>a?[]:x(s)(r,l),[x,a,s]),S=o.disabled||C,w=n.useMemo(()=>b(s),[b,s]),T=n.useMemo(()=>{const r=e.fontSizes.baseFontSize*1.6+14;return`${Math.round(r*4.25)}px`},[e.fontSizes.baseFontSize]);return P("div",{className:"stMultiSelect","data-testid":"stMultiSelect",children:[g(F,{label:t.label,disabled:S,labelVisibility:A(t.labelVisibility?.value),children:t.help&&g(E,{children:g(N,{content:t.help,placement:$.TOP_RIGHT})})}),g(Z,{children:g(k,{creatable:t.acceptNewOptions??!1,options:v,labelKey:"label",valueKey:"value","aria-label":t.label,placeholder:y,type:j.select,multi:!0,onChange:c,value:w,disabled:S,size:"compact",noResultsMsg:f,filterOptions:R,closeOnSelect:!1,ignoreCase:!1,overrides:{Popover:{props:{ignoreBoundary:h,overrides:{Body:{style:()=>({marginTop:e.spacing.px})}}}},SelectArrow:{component:U,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=Y(e.colors,r);return{maxHeight:T,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:S?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:z}},Dropdown:{component:D}}})})]})},le=n.memo(oe);export{le as default};
