import{j as s,r as p,S as i,aB as M,H as b,h as l}from"./vendor-ClLR6ncd.js";import{B}from"./lodash-ZyeDnt0e.js";import{C as L,a as v,u as O,N as k,I as A}from"./NewClusterInputs-B4pi4ojE.js";import{u as N}from"./model-C9Idzwgo.js";import{B as j}from"./index-BpKmttxq.js";import{u as R}from"./inputsContext-DcO_XRZd.js";import{P as T}from"./ui-CsX5tAWu.js";import{B as f}from"./Box-Co2WcNPC.js";import{L as D}from"./LinearProgress-VUPloygu.js";import"./index-OtVJl4GC.js";import"./useCleaningReplQueriesCache-Cg0Wo1gv.js";import"./WarningMessage-4TK5GdCH.js";import"./Warning-DsmyDRzF.js";import"./SmallStandardSelect-7k6-Wr8Q.js";import"./MenuItem-CCerWMyq.js";import"./dividerClasses-DvO85-mA.js";import"./Autocomplete-Cjt7Q9VV.js";import"./Chip-DoCs8Smb.js";import"./model-mC-LLJuv.js";import"./Messages-BRmQDxrZ.js";const F=[],H=6;function $({progress:{message:r,n:a}}){return s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx(l,{variant:"h6",children:"Server messages"}),r.split(`
`).map((o,c)=>s.jsx(l,{children:o},c))]}),s.jsx(D,{variant:"determinate",value:Math.min(100,Math.round(a*100/H))})]})}const q=/^Error: (.*)$/m,w=()=>({message:"Waiting for backend response...",n:0});function E(){const{invalid:r,options:a,optionsSetter:o,queryHook:{isLoading:c}}=R(),[C,d]=p.useState(w()),[S,m]=p.useState(""),e=O(a,"growCluster",{onDownloadProgress:({event:t})=>{var h;const g=((h=t==null?void 0:t.currentTarget)==null?void 0:h.response)||"Loading...",[,x]=g.match(q)||[];x?m(x):d(({n:P})=>({message:g,n:P+1}))},onMutate:()=>{m(""),d(w())}}),n=S||e.error,{catalogs:u}=N(),y=Array.isArray(u)?u.map(({name:t})=>t):F,I=4;return p.useEffect(()=>{o.name(`repo${B(1e3)}`)},[o]),s.jsxs(T,{title:"Add instance to the cluster",SuccessMessage:!n&&e.isSuccess?s.jsxs(i,{direction:"row",alignItems:"center",spacing:2,children:[s.jsx(l,{children:"Instance created successfully!"}),s.jsx(j,{})]}):null,error:n,children:[!n&&e.isLoading?s.jsx($,{progress:C}):null,s.jsxs(i,{direction:"row",spacing:I,children:[s.jsx(f,{sx:{width:.6},children:s.jsx(M,{sx:{p:2},children:s.jsx(k,{catalogs:y})})}),s.jsx(f,{sx:{width:"0.4"},children:s.jsx(A,{startMessage:`This operation adds a new instance to the existent replication cluster.
        It overwrites an existing repository with the specified name or creates
        a new one.`,warningMessage:"The action overwrites an existing repository with the specified name"})})]}),s.jsxs(i,{direction:"row",alignSelf:"center",spacing:2,children:[s.jsx(b,{variant:"contained",disabled:e.isLoading||c||r,onClick:e.mutate,children:"add"}),!n&&e.isSuccess?null:s.jsx(j,{disabled:e.isLoading})]})]})}function ls(r){return s.jsx(L,{initOptions:v,children:s.jsx(E,{...r})})}export{ls as default};
