import{r as p,j as s,d as j,R as V}from"./index-lOezWVmi.js";import{F as E}from"./ClusterSpecificInput-Dv4yt4Ow.js";const $=l=>{const i=[];return l[0].forEach(n=>{l.every(t=>t.includes(n))&&i.push(n)}),i},O=({id:l,classname:i="",isReadOnly:n,options:a,values:t,onChange:N,toggleReadOnly:d,canToggleSpecific:F=!0,isDefaultSpecific:A=!1,disableReason:v,helpText:f})=>{var S;const[o,C]=p.useState(A),g=e=>({label:e,value:e}),u=p.useMemo(()=>{const e=[];if(a.length>0){const c=a.map(m=>m.values);$(c).forEach(m=>{const I=g(m);e.push(I)})}return e.unshift({label:e.length===0?"No option available":"Select option",value:""}),e},[a]),b=Object.values(t??{})[0],h=(S=u==null?void 0:u[1])==null?void 0:S.value,x=e=>{const c={};a.forEach(r=>c[r.memberName]=e),N(c)},M=(e,c)=>{const r={...t,[c]:e};N(r)};return p.useEffect(()=>{!o&&!t&&x(h??"")},[o,t,h]),s.jsxs("div",{className:i,children:[F&&!n&&s.jsx(j.CheckboxInput,{id:`${l}-same-for-all-toggle`,label:"Same for all cluster members",checked:!o,onChange:()=>{o&&x(h??""),C(e=>!e)}}),o&&s.jsxs("div",{className:"cluster-specific-input",children:[a.map(e=>{const c=t==null?void 0:t[e.memberName],r=e.values.map(g);return r.unshift({label:r.length===0?"None available":"Select option",value:""}),s.jsxs(p.Fragment,{children:[s.jsx("div",{className:"cluster-specific-member",children:s.jsx(V,{type:"cluster-member",value:e.memberName,to:`/ui/cluster/member/${encodeURIComponent(e.memberName)}`})}),s.jsx("div",{className:"cluster-specific-value",children:n?s.jsxs(s.Fragment,{children:[c,s.jsx(E,{toggleReadOnly:d,disableReason:v})]}):s.jsx(j.Select,{id:e.memberName===a[0].memberName?l:`${l}-${e.memberName}`,className:"u-no-margin--bottom",options:r,onChange:m=>{M(m.target.value,e.memberName)},value:c})})]},e.memberName)}),f&&s.jsx("div",{className:"p-form-help-text cluster-specific-helptext",children:f})]}),!o&&s.jsx("div",{className:"cluster-specific-value-wrapper",children:n?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"cluster-specific-value",children:b===""?"-":b}),s.jsx(E,{toggleReadOnly:d,disableReason:v})]}):s.jsx(j.Select,{id:l,options:u,onChange:e=>{x(e.target.value)},value:b,help:f})})]})};export{O as C};
