import{C as g,h as b,d as t,k as x,y,c as f,b as p,f as j,cp as v,q as C,j as e,i as N,b3 as S}from"./index-lOezWVmi.js";import{N as E}from"./NotificationRow-DdxAfFhk.js";import{C as q}from"./ClusterMemberHardware-DfVo4oTD.js";import{B as k}from"./BaseLayout-CM5eWMFT.js";import{T as A}from"./TabLinks-C_bdonmQ.js";import"./Meter-CCMCY0F-.js";import"./scroll-BEbDVMxI.js";const F=async s=>fetch("/1.0/cluster",{method:"PUT",headers:{"Content-Type":"application/json"},body:s}).then(g).then(r=>r.metadata),P=({onClose:s})=>{var d;const r=b(),i=t.useNotify(),o=t.useToastNotification(),l=x(),{data:n}=y(),u=f().shape({serverName:p().required("This field is required"),clusterAddress:p().required("This field is required")}),a=j({initialValues:{serverName:"",clusterAddress:((d=n==null?void 0:n.config)==null?void 0:d["cluster.https_address"])??""},enableReinitialize:!0,validationSchema:u,onSubmit:async m=>{try{await v({"cluster.https_address":String(m.clusterAddress)})}catch(c){i.failure("Failed to update cluster address",c);return}const h=JSON.stringify({server_name:m.serverName,enabled:!0});F(h).then(()=>{o.success("Clustering enabled."),r.invalidateQueries({queryKey:[C.settings]}),l("/ui/cluster/members")}).catch(c=>{i.failure("Failed to enable clustering",c)}).finally(()=>{a.setSubmitting(!1)})}});return e.jsxs(t.Modal,{close:s,title:"Enable clustering",className:"enable-clustering-modal",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{"aria-label":"Close",className:"u-no-margin--bottom",onClick:s,type:"button",children:"Close"}),e.jsx(t.ActionButton,{appearance:"positive",loading:a.isSubmitting,className:"u-no-margin--bottom",onClick:()=>void a.submitForm(),disabled:!a.values.serverName||!a.values.clusterAddress,type:"button",children:"Enable clustering"})]}),children:[e.jsx(t.NotificationConsumer,{}),e.jsx(t.Notification,{severity:"caution",title:"Are you sure you want to enable clustering?",children:"This action cannot be undone."}),e.jsx(t.Input,{label:"Server name",type:"text",required:!0,...a.getFieldProps("serverName")}),e.jsx(t.Input,{label:"Cluster address",type:"text",help:"Address to use for clustering traffic by this server",required:!0,...a.getFieldProps("clusterAddress")})]})},w=()=>{const{canEditServerConfiguration:s}=N(),{openPortal:r,closePortal:i,isOpen:o,Portal:l}=t.usePortal({programmaticallyOpen:!0}),n=s(),u=n?"Enable clustering":"You do not have permission to edit the server";return e.jsxs(e.Fragment,{children:[e.jsxs(t.Button,{appearance:"positive",hasIcon:!0,onClick:r,disabled:!n,title:u,children:[e.jsx(t.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Enable clustering"})]}),o&&e.jsx(l,{children:e.jsx(P,{onClose:i})})]})},_=({activeTab:s})=>{const r=["Hardware","Clustering"];return e.jsxs(k,{title:"Server",contentClassName:"detail-page cluster-member-details",children:[e.jsx(E,{}),e.jsxs(t.Row,{children:[e.jsx(A,{tabs:r,activeTab:s,tabUrl:"/ui/server"}),!s&&e.jsx(q,{}),s==="clustering"&&e.jsxs(t.EmptyState,{className:"empty-state",image:e.jsx(t.Icon,{name:"cluster-host",className:"empty-state-icon"}),title:"This server is not clustered",children:[e.jsx("p",{children:e.jsx(S,{docPath:"/explanation/clustering/",hasExternalIcon:!0,children:"Learn more about clustering"})}),e.jsx(w,{})]})]})]})};export{_ as default};
