import{r as u,aJ as e,aN as S}from"./@ui-core-DKdciH1Z.js";import{u as c,c as p,S as x,a as h,b as f}from"./form-schemas-CtQXlH0G.js";import{S as y}from"./SetPassword-CgJRXXLK.js";import{I as j,B as w,F as N,G as g,H as A,J as b,w as P,x as C,y as F}from"./index-D7KLAbvI.js";import{u as E,t as T}from"./@zod-DKyD3xVW.js";import{g as H}from"./name-Bg7MBXU_.js";import{u as M}from"./login-mutation-DXJBG58L.js";import"./@react-router-DaIuhn3X.js";import"./UpdatePasswordSchemas-C1WO1M58.js";import"./PasswordChecker-B1pCmlB2.js";import"./@reactflow-CJzATMj6.js";import"./@monaco-editor-CSMpaClf.js";const m=u.createContext(null);function I({children:t,initialSettings:s}){const[r,a]=u.useState(s||{});return e.jsx(m.Provider,{value:{serverSettings:r,setServerSettings:a},children:t})}function d(){const t=u.useContext(m);if(t===null)throw new Error("useServerActivationContext must be used within an ServerActivationProvider");return t}function U(){const{setSurveyStep:t}=c(),{setServerSettings:s}=d();function r({newPassword:a,username:n}){s(i=>({...i,admin_password:a,admin_username:n})),t(i=>i+1)}return e.jsx(y,{displayUsername:!0,headline:"Create your admin user and password",subHeadine:"Select a username and password for your admin account",submitHandler:r})}function _({submitHandler:t}){const s=u.useId(),{handleSubmit:r,register:a,formState:{isValid:n}}=E({resolver:T(p),defaultValues:{serverName:H()}});return e.jsxs("div",{className:"max-w-[570px] space-y-5",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-display-xs font-semibold",children:"Almost there! Select a server name"}),e.jsx("p",{className:"text-theme-text-secondary",children:"This will identify your ZenML server. You can use the generated name or create your own."})]}),e.jsxs("form",{onSubmit:r(t),className:"space-y-5",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("label",{htmlFor:s,className:"text-text-sm",children:"Server Name"}),e.jsx(j,{...a("serverName"),id:s,className:"w-full"})]})}),e.jsx(w,{disabled:!n,className:"w-full text-center",size:"md",children:e.jsx("span",{className:"w-full",children:"Activate your Server"})})]})]})}async function J(t){const s=A(b.activate),r=await N(s,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const a=await r.json().then(n=>Array.isArray(n.detail)?n.detail[1]:n.detail).catch(()=>"Failed to activate server");throw new g({status:r.status,statusText:r.statusText,message:a})}return r.json()}function L(t){return S({mutationFn:async s=>J(s),...t})}function k({setUsername:t}){const{serverSettings:s}=d(),{setSurveyStep:r}=c(),{setAuthState:a}=P(),{toast:n}=C(),{mutate:i}=M({onSuccess:()=>{a("true"),r(o=>o+1)}}),{mutate:l}=L({onSuccess:async o=>{t(o.name),i({username:o.name,password:s.admin_password??void 0})},onError:o=>{o instanceof Error&&n({status:"error",emphasis:"subtle",icon:e.jsx(F,{className:"h-5 w-5 shrink-0 fill-error-700"}),description:o.message,rounded:!0})}});function v({serverName:o}){l({...s,server_name:o})}return e.jsx(_,{submitHandler:v})}function z(){const{surveyStep:t}=c(),[s,r]=u.useState("");return e.jsx(e.Fragment,{children:e.jsxs(I,{children:[e.jsx(x,{stepAmount:2}),t===1&&e.jsx(U,{}),t===2&&e.jsx(k,{setUsername:r}),t===3&&e.jsx(h,{subHeader:"Your created your ZenML account",username:s})]})})}function X(){return e.jsx(f,{children:e.jsx(z,{})})}export{X as default};
