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