import{k as N,d as i,n as E,h as R,r,j as e,c as g,b as D,Y as O,f as b,a1 as v,R as T,q as y,P as Y,Q as _,T as k}from"./index-lOezWVmi.js";import{y as U,c as L,o as M}from"./YamlSwitch-Dx35FPoh.js";import{s as A,c as B,b as V,m as w,d as G,e as q,f as K,g as $,R as H,a as Q,I as z,M as J,B as W,C as X}from"./SshKeyForm-DyzN8_u6.js";import{Y as Z}from"./FormMenuItem-D_mb6BGW.js";import{M as j,p as ee,Y as n,P as oe,a as se,D as ae,N as te,G as ie,b as re,O as ne,R as me,S as ce,c as le,d as pe,B as de,C as fe}from"./ProfileDetailsForm-ZPWN4K9x.js";import{D as ue,N as ye,G as je,P as xe,O as he}from"./ProxyDeviceForm-DtoEXcqU.js";import{N as Pe}from"./NotificationRow-DdxAfFhk.js";import{B as Se}from"./BaseLayout-CM5eWMFT.js";import{F as Ce}from"./FormFooterLayout-B1eckygM.js";import{Y as Fe}from"./YamlNotification-BNbKV1s_.js";import"./formFields-D9YYYKxX.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-CUTbkJs9.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-CHLzDgpY.js";import"./snapshots-ByuD-MsK.js";import"./StoragePoolSelector-IgEwUopy.js";import"./StoragePoolSize-BD_icnzk.js";import"./Meter-CCMCY0F-.js";import"./DiskSizeSelector-B_DkPsg-.js";import"./StorageVolumeForm-29nek3fs.js";import"./ClusterMemberSelector-BzqYPTQI.js";import"./projects-DygTcZJV.js";import"./useVolumes-BzsbrBKS.js";import"./images-BWRI68mm.js";import"./storage-volumes-CuHKF2BE.js";import"./FormLink-CZznyag6.js";import"./useNetworks-Dvw5If3E.js";import"./networks-C9MSk_NH.js";import"./ExpandableList-QVhlqlHQ.js";import"./NetworkSelector-Bu8cRfIi.js";import"./useNetworkAcls-Bclr5QsB.js";import"./network-acls-B9tLpGS2.js";const so=()=>{var u;const m=N(),c=i.useNotify(),x=i.useToastNotification(),{project:t}=E(),l=R(),h=r.useState(null),[a,P]=r.useState(j);if(!t)return e.jsx(e.Fragment,{children:"Missing project"});const S=g().shape({name:D().test("deduplicate","A profile with this name already exists",async s=>O(s,t,h,"profiles")).required()}),p=()=>{k("form-contents","p-bottom-controls")};r.useEffect(p,[(u=c.notification)==null?void 0:u.message,a]),i.useListener(window,p,"resize",!0);const o=b({initialValues:{name:"",devices:[],cloud_init_ssh_keys:[],readOnly:!1,entityType:"profile"},validationSchema:S,onSubmit:s=>{const F=s.yaml?U(s.yaml):d(s);v(JSON.stringify(F),t).then(()=>{m(`/ui/project/${encodeURIComponent(t)}/profiles`),x.success(e.jsxs(e.Fragment,{children:["Profile"," ",e.jsx(T,{type:"profile",value:s.name,to:`/ui/project/${encodeURIComponent(t)}/profile/${encodeURIComponent(s.name)}`})," ","created."]}))}).catch(I=>{o.setSubmitting(!1),c.failure("Profile creation failed",I)}).finally(()=>{l.invalidateQueries({queryKey:[y.profiles]}),l.invalidateQueries({queryKey:[y.projects,t]})})}}),d=s=>({...ee(s),devices:$(s.devices),config:{...K(s),...q(s),...G(s),...w(s),...V(s),...B(s),...A(s)}}),f=s=>{o.values.yaml&&s!==n&&o.setFieldValue("yaml",void 0),P(s)};function C(){const s=d(o.values);return M(s)}return e.jsxs(Se,{title:"Create a profile",contentClassName:"create-profile",children:[e.jsxs(i.Form,{onSubmit:o.handleSubmit,className:"form",children:[a!==n&&e.jsx(oe,{active:a,setActive:f,isDisabled:!o.values.name,formik:o}),e.jsx(i.Row,{className:"form-contents",children:e.jsxs(i.Col,{size:12,children:[e.jsx(Pe,{}),a===j&&e.jsx(se,{formik:o,isEdit:!1}),a===ae&&e.jsx(ue,{formik:o,project:t}),a===te&&e.jsx(ye,{formik:o,project:t}),a===ie&&e.jsx(je,{formik:o,project:t}),a===re&&e.jsx(xe,{formik:o,project:t}),a===ne&&e.jsx(he,{formik:o,project:t}),a===me&&e.jsx(H,{formik:o}),a===ce&&e.jsx(Q,{formik:o}),a===le&&e.jsx(z,{formik:o}),a===pe&&e.jsx(J,{formik:o}),a===de&&e.jsx(W,{formik:o}),a===fe&&e.jsx(X,{formik:o}),a===n&&e.jsx(Z,{yaml:C(),setYaml:s=>void o.setFieldValue("yaml",s),children:e.jsx(Fe,{entity:"profile",docPath:"/profiles"})})]})},a)]}),e.jsxs(Ce,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(L,{formik:o,section:a,setSection:f,disableReason:o.values.name?void 0:"Please enter a profile name before adding custom configuration"})}),e.jsx(i.Button,{appearance:"base",onClick:async()=>m(`/ui/project/${encodeURIComponent(t)}/profiles`),children:"Cancel"}),e.jsx(i.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:!o.isValid||o.isSubmitting||!o.values.name||Y(o)||_(o),onClick:()=>void o.submitForm(),children:"Create"})]})]})};export{so as default};
