import{b as r,N as H,da as D,ak as L,j as O,c as b,E,bW as M,db as U,i as C,aH as K}from"./index.BdH_oWMm.js";import{u as k,V as F}from"./useSelectCommon.CpVkeMI0.js";import{W as N}from"./WidgetLabel.ZStEr2fI.js";import{W as j}from"./WidgetLabelHelpIcon.CochPswC.js";import{C as q,S as X}from"./select.ox5FKmP0.js";import{a as G}from"./useBasicWidgetState.U_bd_Q53.js";import"./styled-components.BwP7eYqe.js";import"./stateful-menu.CLeMtMha.js";import"./_baseMap.n6eSFx7L.js";import"./styled-components.jdcyFPSS.js";import"./constants.Bk9yhl7Y.js";import"./FormClearHelper.B3vyDvH9.js";const _=({disabled:o,value:t,onChange:l,options:d,label:c,labelVisibility:f,help:p,placeholder:v,clearable:g,acceptNewOptions:h})=>{const e=H(),y=r.useContext(D),[u,s]=r.useState(t),i=r.useRef(u);L(()=>{s(t),i.current=null},[t]);const S=r.useCallback(a=>{if(a.type==="remove"){i.current=a.option?.value,s(null);return}if(i.current=null,a.type==="clear"){s(null),l(null);return}const[n]=a.value;s(n.value),l(n.value)},[l]),W=r.useCallback(()=>{i.current!==null&&s(i.current)},[]),w=d,{placeholder:T,disabled:V,selectOptions:z,inputReadOnly:B,valueToUiSingle:I,createFilterOptions:x}=k({options:w,isMulti:!1,acceptNewOptions:h,placeholderInput:v}),m=o||V,P=r.useMemo(()=>x(),[x]),R=I(u);return O("div",{className:"stSelectbox","data-testid":"stSelectbox",children:[b(N,{label:c,labelVisibility:f,disabled:m,children:p&&b(j,{content:p,label:c})}),b(X,{creatable:h,disabled:m,labelKey:"label","aria-label":c||"",onChange:S,onBlur:W,options:z,filterOptions:P,clearable:g||!1,escapeClearsValue:g||!1,value:R,valueKey:"value",placeholder:T,ignoreCase:!1,overrides:{Root:{style:()=>({lineHeight:e.lineHeights.inputWidget,fontWeight:e.fontWeights.normal})},Dropdown:{component:F,style:{boxShadow:"none",overflow:"hidden"}},ClearIcon:{props:{overrides:{Svg:{style:{color:e.colors.grayTextColor,padding:e.spacing.threeXS,height:e.sizes.clearIconSize,width:e.sizes.clearIconSize,":hover":{fill:e.colors.bodyText}}}}}},ControlContainer:{style:({$isFocused:a})=>{const n=U(e.colors,a);return{height: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}}},IconsContainer:{style:()=>({paddingRight:e.spacing.sm})},ValueContainer:{style:()=>({flexGrow:1,paddingRight:e.spacing.sm,paddingLeft:e.spacing.sm,paddingBottom:e.spacing.sm,paddingTop:e.spacing.sm,marginLeft:e.sizes.tagMarginInsideBorder})},Placeholder:{style:()=>({color:m?e.colors.fadedText40:e.colors.fadedText60,position:"absolute",pointerEvents:"none"})},InputContainer:{style:()=>({marginLeft:e.spacing.none,position:"relative",minWidth:e.spacing.threeXS,flexGrow:0})},Input:{props:{readOnly:B},style:()=>({lineHeight:e.lineHeights.inputWidget,color:e.colors.bodyText,caretColor:e.colors.bodyText})},DropdownContainer:{style:()=>({...M(e),maxHeight:`min(${e.sizes.maxDropdownHeight}, 70vh)`,overflow:"hidden"})},Popover:{props:{ignoreBoundary:y,popoverMargin:E(e.spacing.twoXS),overrides:{Body:{style:()=>({overflow:"hidden"})}}}},SingleValue:{style:()=>({marginLeft:e.spacing.none})},SelectArrow:{component:q,props:{style:{...m&&{cursor:"not-allowed"}},overrides:{Svg:{style:()=>({width:e.iconSizes.xl,height:e.iconSizes.xl})}}}}}})]})},$=r.memo(_),A=(o,t)=>o.getStringValue(t),J=o=>o.options.length===0||C(o.default)?null:o.options[o.default],Q=o=>o.rawValue??null,Y=(o,t,l,d)=>{t.setStringValue(o,l.value,{fromUi:l.fromUi},d)},Z=({disabled:o,element:t,widgetMgr:l,fragmentId:d})=>{const{options:c,help:f,label:p,labelVisibility:v,placeholder:g,acceptNewOptions:h}=t,e=t.queryParamKey?{paramKey:t.queryParamKey,valueType:"string_value",clearable:C(t.default)}:void 0,[y,u]=G({getStateFromWidgetMgr:A,getDefaultStateFromProto:J,getCurrStateFromProto:Q,updateWidgetMgrState:Y,element:t,widgetMgr:l,fragmentId:d,formClearBehavior:"resetValueOnly",queryParamBinding:e}),s=r.useCallback(S=>{u({value:S,fromUi:!0})},[u]),i=C(t.default)&&!o;return b($,{label:p,labelVisibility:K(v?.value),options:c,disabled:o,onChange:s,value:y,help:f,placeholder:g,clearable:i,acceptNewOptions:h??!1})},pe=r.memo(Z);export{pe as default};
