1import{b0 as P,b1 as $,b2 as D,b3 as _,f as k,r as s,o as N,ag as F,j as h,h as j,q,aj as K,O as U,ai as Y}from"./index.RuhrnD1v.js";import{S as y,a as v,u as X,V as G}from"./useSelectCommon.CZJ9OUIq.js";import{W as Z}from"./WidgetLabel.CgwydhVR.js";import{W as J}from"./WidgetLabelHelpIcon.BKLcvqEy.js";import{u as Q}from"./useBasicWidgetState.CI9LlGGe.js";import{a as ee}from"./_arrayIncludes.B19Iyn2B.js";import{b as te,a as oe,C as re,T as ie}from"./select.C3diGM4n.js";import"./styled-components.BjCveN31.js";import"./_baseMap.BQYfXAcQ.js";import"./styled-components.CXqQ-NdV.js";import"./FormClearHelper.DFo50Lfo.js";import"./_baseIndexOf.BTknn6Gb.js";import"./constants.BZvTtNRL.js";var ne=200;function se(i,t,g,u){var e=-1,f=ee,c=!0,p=i.length,d=[],S=t.length;if(!p)return d;t.length>=ne&&(f=$,c=!1,t=new P(t));e:for(;++e<p;){var o=i[e],l=o;if(o=o!==0?o:0,c&&l===l){for(var m=S;m--;)if(t[m]===l)continue e;d.push(o)}else f(t,l,u)||d.push(o)}return d}var ae=D(function(i,t){return _(i)?se(i,t):[]});const le=k("div",{target:"ekqzr6e0"})(({theme:i})=>({"span[aria-disabled='true']":{background:i.colors.fadedText05}})),ce=(i,t)=>i.getStringArrayValue(t),de=i=>i.default.map(t=>i.options[t])??null,ge=i=>i.rawValues??null,ue=(i,t,g,u)=>{t.setStringArrayValue(i,g.value,{fromUi:g.fromUi},u)},pe=i=>{const{element:t,widgetMgr:g,fragmentId:u}=i,e=N(),f=s.useContext(F),c=s.useRef(null),p=s.useRef(0),d=t.queryParamKey?{paramKey:t.queryParamKey,valueType:"string_array_value",clearable:!0,urlFormat:"repeated"}:void 0,S=s.useRef([]),[o,l]=Q({getStateFromWidgetMgr:ce,getDefaultStateFromProto:de,getCurrStateFromProto:ge,updateWidgetMgrState:ue,element:t,widgetMgr:g,fragmentId:u,formClearBehavior:"resetValueOnly",queryParamBinding:d}),m=t.maxSelections>0&&o.length>=t.maxSelections,T=s.useMemo(()=>{if(t.maxSelections===0)return"No results";if(o.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,o.length]),x=s.useCallback(r=>{switch(r.type){case"remove":return ae(o,r.option?.value);case"clear":return[];case"select":{if(r.option?.value===y){const n=t.options.filter(a=>!o.includes(a));if(t.maxSelections>0){const a=t.maxSelections-o.length;return[...o,...n.slice(0,a)]}return[...o,...n]}if(r.option?.value===v){const n=S.current;if(t.maxSelections>0){const a=t.maxSelections-o.length;return[...o,...n.slice(0,a)]}return[...o,...n]}return o.concat([r.option?.value])}default:throw new Error(`State transition is unknown: ${r.type}`)}},[o,t.maxSelections,t.options]),M=s.useCallback(r=>{t.maxSelections&&r.type==="select"&&o.length>=t.maxSelections||l({value:x(r),fromUi:!0})},[t.maxSelections,x,l,o.length]),{options:R}=t,{placeholder:I,disabled:L,selectOptions:B,inputReadOnly:H,valuesToUiMulti:C,createFilterOptions:w}=X({options:R,isMulti:!0,acceptNewOptions:t.acceptNewOptions??!1,placeholderInput:t.placeholder}),W=s.useCallback((r,n)=>{if(m)return[];const a=w(o)(r,n);return a.length>1?n.trim()?(S.current=a.map(A=>A.value),[{label:`Select ${a.length} matches`,value:v,id:v},...a]):[{label:"Select all",value:y,id:y},...a]:a},[w,m,o]),b=i.disabled||L,V=s.useMemo(()=>C(o),[C,o]),E=s.useMemo(()=>`calc(4.5 * ${`calc(${e.sizes.elementHighlightHeight} + ${e.sizes.tagMarginInsideBorder})`} + ${e.sizes.tagMarginInsideBorder} + 2 * ${e.sizes.borderWidth})`,[e.sizes.elementHighlightHeight,e.sizes.tagMarginInsideBorder,e.sizes.borderWidth]);s.useLayoutEffect(()=>{c.current&&(c.current.scrollTop=p.current)});const z=s.useCallback(r=>{p.current=r.currentTarget.scrollTop},[]),O=s.useMemo(()=>(function(n){return h(te,{...n,ref:c,onScroll:z})}),[z]);return j("div",{className:"stMultiSelect","data-testid":"stMultiSelect",children:[h(Z,{label:t.label,disabled:b,labelVisibility:q(t.labelVisibility?.value),children:t.help&&h(J,{content:t.help,label:t.label})}),h(le,{children:h(oe,{creatable:t.acceptNewOptions??!1,options:B,labelKey:"label",valueKey:"value","aria-label":t.label,placeholder:I,type:ie.select,multi:!0,onChange:M,value:V,disabled:b,size:"compact",noResultsMsg:T,filterOptions:W,closeOnSelect:!1,ignoreCase:!1,overrides:{DropdownContainer:{style:()=>({...Y(e),maxHeight:`min(${e.sizes.maxDropdownHeight}, 70vh)`,overflow:"hidden"})},Popover:{props:{ignoreBoundary:f,popoverMargin:U(e.spacing.twoXS),overrides:{Body:{style:()=>({overflow:"hidden"})}}}},SelectArrow:{component:re,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 n=K(e.colors,r);return{maxHeight:E,minHeight:e.sizes.minElementHeight,borderLeftWidth:e.sizes.borderWidth,borderRightWidth:e.sizes.borderWidth,borderTopWidth:e.sizes.borderWidth,borderBottomWidth:e.sizes.borderWidth,borderTopColor:n,borderRightColor:n,borderBottomColor:n,borderLeftColor:n}}},Placeholder:{style:()=>({flex:"inherit",color:b?e.colors.fadedText40:e.colors.fadedText60,position:"absolute",top:"50%",transform:"translateY(-50%)",paddingLeft:e.spacing.sm,pointerEvents:"none"})},ValueContainer:{component:O,style:()=>({overflowY:"auto",paddingLeft:e.sizes.tagMarginInsideBorder,paddingTop:e.sizes.tagMarginInsideBorder,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.md2,borderTopRightRadius:e.radii.md2,borderBottomRightRadius:e.radii.md2,borderBottomLeftRadius:e.radii.md2,fontSize:e.fontSizes.md,paddingLeft:e.spacing.sm,marginTop:e.spacing.none,marginLeft:e.spacing.none,marginRight:e.spacing.twoXS,marginBottom:e.sizes.tagMarginInsideBorder,height:e.sizes.elementHighlightHeight,maxWidth:`calc(100% - ${e.spacing.lg})`,cursor:"default !important",pointerEvents:"none"}},Action:{style:{paddingLeft:e.spacing.none,pointerEvents:"auto"}},ActionIcon:{props:{overrides:{Svg:{style:{width:"0.625em",height:"0.625em"}}}}}}}},MultiValue:{props:{overrides:{Root:{style:{fontSize:e.fontSizes.sm}}
1}}},InputContainer:{style:({$isFocused:r})=>({height:e.sizes.elementHighlightHeight,alignSelf:"flex-start",marginLeft:e.spacing.none,marginTop:e.spacing.none,marginBottom:e.sizes.tagMarginInsideBorder,position:r?"relative":"absolute",width:"fit-content",flexGrow:0,display:"flex"})},Input:{props:{readOnly:H},style:()=>({color:e.colors.bodyText,caretColor:e.colors.bodyText,paddingLeft:e.spacing.sm,fieldSizing:"content"})},Dropdown:{component:G}}})})]})},Le=s.memo(pe);export{Le as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.