import{R as d,bE as g,n as b,d as t,s as x,u as y,f,h as p,l as j,fc as v,q as C,j as e,p as N,e as S,D as E}from"./index-C88DWJny.js";import{C as q}from"./ClusterMemberHardware-M0c_UT1C.js";import{B as A}from"./BaseLayout-axPPiMeo.js";import{T as P}from"./TabLinks-DP94LlMA.js";import"./scroll-Dc7Cgzms.js";const T=async s=>fetch(`${d}/1.0/cluster`,{method:"PUT",headers:{"Content-Type":"application/json"},body:s}).then(g).then(r=>r.metadata),F=({onClose:s})=>{const r=b(),n=t.useNotify(),l=t.useToastNotification(),o=x(),{data:i}=y(),u=f().shape({serverName:p().required("This field is required"),clusterAddress:p().required("This field is required")}),a=j({initialValues:{serverName:"",clusterAddress:i?.config?.["cluster.https_address"]??""},enableReinitialize:!0,validationSchema:u,onSubmit:async m=>{try{await v({"cluster.https_address":String(m.clusterAddress)})}catch(c){n.failure("Failed to update cluster address",c);return}const h=JSON.stringify({server_name:m.serverName,enabled:!0});T(h).then(()=>{l.success("Clustering enabled."),r.invalidateQueries({queryKey:[C.settings]}),o(`${d}/ui/cluster/members`)}).catch(c=>{n.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:()=>{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")})]})},R=()=>{const{canEditServerConfiguration:s}=N(),{openPortal:r,closePortal:n,isOpen:l,Portal:o}=t.usePortal({programmaticallyOpen:!0}),i=s(),u=i?"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:!i,title:u,children:[e.jsx(t.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Enable clustering"})]}),l&&e.jsx(o,{children:e.jsx(F,{onClose:n})})]})},$=({activeTab:s})=>{const r=["Hardware","Clustering"];return e.jsxs(A,{title:"Server",contentClassName:"detail-page cluster-member-details",children:[e.jsx(S,{}),e.jsxs(t.Row,{children:[e.jsx(P,{tabs:r,activeTab:s,tabUrl:`${d}/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(E,{docPath:"/explanation/clustering/",hasExternalIcon:!0,children:"Learn more about clustering"})}),e.jsx(R,{})]})]})]})};export{$ as default};
