import{j as e,d as n,r as j,R as S}from"./index-lOezWVmi.js";const b=({toggleReadOnly:i,disableReason:s})=>e.jsx(n.Button,{onClick:i,className:"u-no-margin--bottom",type:"button",appearance:"base",title:s??"Edit",hasIcon:!0,disabled:!!s,children:e.jsx(n.Icon,{name:"edit"})}),k=({disableReason:i,values:s,id:u,isReadOnly:p,memberNames:m,onChange:h,toggleReadOnly:d=()=>{},canToggleSpecific:C=!0,isDefaultSpecific:I=null,disabled:o=!1,helpText:f,placeholder:g,classname:E="u-sv3",disabledReason:l})=>{const[a,v]=j.useState(I),x=Object.values(s??{})[0];j.useEffect(()=>{const t=Object.values(s??{});if(a===null&&t.length>0){const c=t.some(r=>r!==t[0]);v(c)}},[a,s]);const N=t=>{const c={};m.forEach(r=>c[r]=t),h(c)},F=(t,c)=>{const r={...s,[c]:t};h(r)};return e.jsxs("div",{className:E,children:[C&&!p&&e.jsx(n.CheckboxInput,{id:`${u}-same-for-all-toggle`,label:"Same for all cluster members",checked:!a,labelClassName:"cluster-specific-toggle-label",onChange:()=>{a&&N(x??""),v(t=>!t)},disabled:!!l,title:l}),a&&e.jsxs("div",{className:"cluster-specific-input",children:[m.map(t=>{const c=s==null?void 0:s[t];return e.jsxs(j.Fragment,{children:[e.jsx("div",{className:"cluster-specific-member",children:e.jsx(S,{type:"cluster-member",value:t,to:`/ui/cluster/member/${encodeURIComponent(t)}`})}),e.jsx("div",{className:"cluster-specific-value-wrapper",children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"cluster-specific-value",children:c}),!o&&e.jsx(b,{disableReason:i,toggleReadOnly:d})]}):e.jsx(n.Input,{id:m.indexOf(t)===0?u:`${u}-${t}`,type:"text",className:"u-no-margin--bottom",value:c,onChange:r=>{F(r.target.value,t)},disabled:!!l||o,placeholder:g,title:l})})]},t)}),f&&!p&&e.jsx("div",{className:"p-form-help-text cluster-specific-helptext",children:f})]}),!a&&e.jsx("div",{className:"cluster-specific-value-wrapper",children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"cluster-specific-value",children:x===""?"-":x}),!o&&e.jsx(b,{disableReason:i,toggleReadOnly:d})]}):e.jsx(n.Input,{id:u,type:"text",value:x,onChange:t=>{N(t.target.value)},disabled:!!l||o,help:f,placeholder:g,title:l})})]})};export{k as C,b as F};
