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-BGoV7aa6.js";import{y as U,c as L,o as M}from"./YamlSwitch-3bR2x_mM.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-CUKak12D.js";import{Y as Z}from"./FormMenuItem-DL6BRTfq.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-BHt5m6c5.js";import{D as ue,N as ye,G as je,P as xe,O as he}from"./ProxyDeviceForm-CJuqb0Qb.js";import{N as Pe}from"./NotificationRow-TiNMatDC.js";import{B as Se}from"./BaseLayout-CMa6UuLt.js";import{F as Ce}from"./FormFooterLayout-6fxJS5rR.js";import{Y as Fe}from"./YamlNotification-DZTRn--p.js";import"./formFields-Bl9l8MgP.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-BSccmSbv.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-DJQj4qcy.js";import"./snapshots-DaF1fk6i.js";import"./StoragePoolSelector-C3ukTuXY.js";import"./StoragePoolSize-CMqudFqH.js";import"./Meter-Dgx5-6Vk.js";import"./DiskSizeSelector-CdqrTfL2.js";import"./StorageVolumeForm-sAEwEZsp.js";import"./ClusterMemberSelector-DgK9Dzlt.js";import"./projects-DqKy-mDU.js";import"./useVolumes-DDlw4HJp.js";import"./images-CvhzZeaL.js";import"./storage-volumes-BT7spW4Z.js";import"./FormLink-bdcwK5oX.js";import"./useNetworks-DAjhMC6T.js";import"./networks-C4OkUUfr.js";import"./ExpandableList-BGG1B3Pl.js";import"./NetworkSelector-CPTW70Fb.js";import"./useNetworkAcls-Cr7WQaRO.js";import"./network-acls-s7ps2U5o.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};
