import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{c as n,l as r}from"./emotion-styled.browser.esm.DmHEQgFq.js";import{S as i,o as a}from"./protobuf.Cj15o6C6.js";import{N as o}from"./utils.CmclnrwZ.js";import{p as s}from"./StreamlitMarkdown.CwaSe4JX.js";import{C as c,E as l,a as u,g as d}from"./styled-components.BnwjjA8j.js";import{En as f,at as p,it as m,tn as h}from"./index.BfkDCGNp.js";import{n as g}from"./useBasicWidgetState.Bj6bxpQq.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,I]=g({getStateFromWidgetMgr:x,getDefaultStateFromProto:S,getCurrStateFromProto:C,updateWidgetMgrState:w,element:y,widgetMgr:E,fragmentId:T,formClearBehavior:`resetValueOnly`,queryParamBinding:y.queryParamKey?{paramKey:y.queryParamKey,valueType:`string_array_value`,clearable:!0,urlFormat:`repeated`}:void 0}),L=f(D),R=(0,_.useRef)(null);(0,_.useEffect)(()=>{R.current&&(P?R.current.setAttribute(`aria-required`,`true`):R.current.removeAttribute(`aria-required`))},[P]),(0,_.useEffect)(()=>{if(F.length===0||b(k,F).length>0)return;let e=C(y);I({value:e.length>0?e:S(y),fromUi:!1})},[k,F,I,y]);let z=O===a.ClickMode.MULTI_SELECT?`multiple`:`single`,B=(0,_.useCallback)(e=>`${y.id}-${e}`,[y.id]),V=(0,_.useMemo)(()=>new Set(b(k,F).map(e=>B(e))),[k,F,B]),H=(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(F);n.length===F.length&&n.every(e=>r.has(e))||I({value:n,fromUi:!0})},[k,F,I,y.id]),U=A===a.Style.PILLS,W=(0,_.useMemo)(()=>{let e=U?d:c,t=U?`pills`:`segmented_control`;return k.map((r,i)=>n(e,{id:B(i),"data-variant":t,$containerWidth:L,children:n(h,{icon:r.contentIcon??void 0,label:r.content??``,iconSize:`base`})},`${v(r)}-${i}`))},[k,U,L,B]);return r(u,{className:`stButtonGroup`,"data-testid":`stButtonGroup`,containerWidth:L,children:[n(p,{label:j,disabled:t,labelVisibility:o(M?.value??i.LabelVisibilityOptions.COLLAPSED),children:N&&n(m,{content:N,placement:s.TOP,label:j})}),n(l,{ref:R,selectionMode:z,selectedKeys:V,onSelectionChange:H,isDisabled:t,disallowEmptySelection:P&&z===`single`,"aria-label":y.label,$isPills:U,$containerWidth:L,children:W})]})}var E=(0,_.memo)(T);export{E as default};