import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{a as n,i as r}from"./emotion-styled.browser.esm.BYv_Qzcq.js";import{S as i,o as a}from"./protobuf.Ckf-kxfD.js";import{ot as o}from"./utils.Vs712G4Z.js";import{a as s}from"./utils.C5rmUD0V.js";import{t as c}from"./Tooltip.CcubhKj6.js";import{C as l,E as u,a as d,g as f}from"./styled-components.BjKbfR5p.js";import{t as p}from"./DynamicButtonLabel.BTjDBnmI.js";import{t as m}from"./WidgetLabel.Cr4ld6Ih.js";import{t as h}from"./WidgetLabelHelpIconInline.CxEaud35.js";import{n as g}from"./useBasicWidgetState.ssY2f7Zy.js";var _=e(t(),1);function v(e){let t=e.contentIcon,n=e.content??``;return t?`${t} ${n}`.trim():n}function y(e,t){for(let n=e.length-1;n>=0;n--)if(v(e[n])===t)return n;return-1}function b(e,t){let n=[];for(let r of t){let t=y(e,r);t>=0&&n.push(t)}return n}function x(e,t){return e.getStringArrayValue(t)}function S(e){return(e.default??[]).map(t=>{let n=e.options[t];return n?v(n):``}).filter(e=>e!==``)}function C(e){return e.rawValues??[]}function w(e,t,n,r){t.setStringArrayValue(e,n.value,{fromUi:n.fromUi},r)}function T(e){let{disabled:t,element:y,fragmentId:T,widgetMgr:E,widthConfig:D}=e,{clickMode:O,options:k,style:A,label:j,labelVisibility:M,help:N,required:P}=y,F=y.queryParamKey?{paramKey:y.queryParamKey,valueType:`string_array_value`,clearable:!0,urlFormat:`repeated`}:void 0,[I,L]=g({getStateFromWidgetMgr:x,getDefaultStateFromProto:S,getCurrStateFromProto:C,updateWidgetMgrState:w,element:y,widgetMgr:E,fragmentId:T,formClearBehavior:`resetValueOnly`,queryParamBinding:F}),R=s(D),z=(0,_.useRef)(null);(0,_.useEffect)(()=>{z.current&&(P?z.current.setAttribute(`aria-required`,`true`):z.current.removeAttribute(`aria-required`))},[P]),(0,_.useEffect)(()=>{if(I.length===0||b(k,I).length>0)return;let e=C(y);L({value:e.length>0?e:S(y),fromUi:!1})},[k,I,L,y]);let B=O===a.ClickMode.MULTI_SELECT?`multiple`:`single`,V=(0,_.useCallback)(e=>`${y.id}-${e}`,[y.id]),H=(0,_.useMemo)(()=>new Set(b(k,I).map(e=>V(e))),[k,I,V]),U=(0,_.useCallback)(e=>{if(e===`all`)return;let t=`${y.id}-`,n=[...e].map(e=>v(k[Number(String(e).slice(t.length))])),r=new Set(I);n.length===I.length&&n.every(e=>r.has(e))||L({value:n,fromUi:!0})},[k,I,L,y.id]),W=A===a.Style.PILLS,G=(0,_.useMemo)(()=>{let e=W?f:l,t=W?`pills`:`segmented_control`;return k.map((n,i)=>r(e,{id:V(i),"data-variant":t,$containerWidth:R,children:r(p,{icon:n.contentIcon??void 0,label:n.content??``,iconSize:`base`})},`${v(n)}-${i}`))},[k,W,R,V]);return n(d,{className:`stButtonGroup`,"data-testid":`stButtonGroup`,containerWidth:R,children:[r(m,{label:j,disabled:t,labelVisibility:o(M?.value??i.LabelVisibilityOptions.COLLAPSED),children:N&&r(h,{content:N,placement:c.TOP,label:j})}),r(u,{ref:z,selectionMode:B,selectedKeys:H,onSelectionChange:U,isDisabled:t,disallowEmptySelection:P&&B===`single`,"aria-label":y.label,$isPills:W,$containerWidth:R,children:G})]})}var E=(0,_.memo)(T);export{E as default};