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