| Current Path : /proc/thread-self/root/snap/lxd/38768/share/lxd-ui/assets/ |
| Current File : //proc/thread-self/root/snap/lxd/38768/share/lxd-ui/assets/ClusterSpecificInput-7EvfCd3b.js |
import{j as e,d as i,r as j}from"./index-BsQN_SZU.js";import{a as S}from"./ClusterMemberRichChip-Di9w-E3M.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"})}),M=({disableReason:n,values:c,id:u,isReadOnly:p,memberNames:m,onChange:h,toggleReadOnly:v=()=>{},canToggleSpecific:b=!0,isDefaultSpecific:E=null,disabled:o=!1,helpText:f,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={};m.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:[m.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:m.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)}),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(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:f,placeholder:g,title:l})})]})};export{M as C,N as F};