import{s as E,d as t,H as O,n as g,r as n,j as e,f as R,h as v,z as b,l as T,aD as _,R as y,q as j,an as k,ao as w,ap as Y,aq as A,ar as M,as as B,at as L,aE as U,au as V,aF as q,e as G,ah as H}from"./index-66XtK6kJ.js";import{y as K,c as $,d as z,o as Q}from"./YamlSwitch-CYh-6cCu.js";import{D as J,N as W,G as X,P as Z,O as ee,R as ae,c as se,I as oe,M as ie,B as te,C as re,h as ne,a as ce,d as le}from"./NetworkDevicePanel-CFETAerX.js";import{M as P,Y as c,P as me,a as pe,D as de,N as fe,G as ue,b as ye,O as je,R as Pe,S as he,c as xe,d as Se,B as Ne,C as Ce}from"./ProfileDetailsForm-B3xOyJBQ.js";import{B as Fe}from"./BaseLayout-DHllEyf6.js";import{F as De}from"./FormFooterLayout-CcTAlRx3.js";import{Y as Ie}from"./NetworkDefaultACLSelector-DEbhhV0K.js";import{P as Ee}from"./ProfileRichChip-BYCO4lqY.js";import{u as Oe,p as h}from"./usePanelParams-D2E5KqJl.js";import"./FormMenuItem-DRWC8EpE.js";import"./AutoExpandingTextArea-BdkUE9YB.js";import"./scroll-Dc7Cgzms.js";import"./StorageVolumeForm-Dy1hN1dM.js";import"./DiskSizeSelector-CY9M2-VV.js";import"./ScrollableForm-DnwqOi93.js";import"./snapshots-C1yg8XCr.js";import"./useResources-9vpG47dy.js";import"./formChangeCount-DjaUj6hM.js";import"./useNetworks-CRf3hLWI.js";import"./ExpandableList-DpOIpfcf.js";import"./NetworkRichChip--TmCCnRo.js";import"./NetworkSelector-Cw3ouSc2.js";import"./useNetworkAcls-CY4xdGt5.js";import"./network-acls-BNDCHn0O.js";import"./ProfileResourceLimits-Bgn_DF19.js";const Ze=()=>{const l=E(),m=t.useNotify(),x=t.useToastNotification(),{project:i}=O(),p=g(),S=n.useState(null),[o,N]=n.useState(P),d=Oe();if(!i)return e.jsx(e.Fragment,{children:"Missing project"});const C=R().shape({name:v().test("deduplicate","A profile with this name already exists",async s=>b(s,i,S,"profiles")).required()}),f=()=>{H("form-contents","p-bottom-controls")};n.useEffect(f,[m.notification?.message,o]),t.useListener(window,f,"resize",!0);const a=T({initialValues:{name:"",devices:[],cloud_init_ssh_keys:[],readOnly:!1,entityType:"profile"},validationSchema:C,onSubmit:s=>{const D=s.yaml?K(s.yaml):u(s);_(JSON.stringify(D),i).then(()=>{l(`${y}/ui/project/${encodeURIComponent(i)}/profiles`),x.success(e.jsxs(e.Fragment,{children:["Profile"," ",e.jsx(Ee,{profileName:s.name,projectName:i})," ","created."]}))}).catch(I=>{a.setSubmitting(!1),m.failure("Profile creation failed",I)}).finally(()=>{p.invalidateQueries({queryKey:[j.profiles]}),p.invalidateQueries({queryKey:[j.projects,i]})})}}),u=s=>({...q(s),devices:V(s.devices),config:{...U(s),...L(s),...B(s),...M(s),...A(s),...Y(s),...w(s),...k(s)}}),r=s=>{a.values.yaml&&s!==c&&a.setFieldValue("yaml",void 0),N(s)};function F(){const s=u(a.values);return Q(s)}return e.jsxs(Fe,{title:"Create a profile",contentClassName:"create-profile",children:[e.jsxs(t.Form,{onSubmit:a.handleSubmit,className:"form",children:[o!==c&&e.jsx(me,{active:o,setActive:r,isDisabled:!a.values.name,formik:a}),e.jsx(t.Row,{className:"form-contents",children:e.jsxs(t.Col,{size:12,children:[e.jsx(G,{}),o===P&&e.jsx(pe,{formik:a,isEdit:!1,project:i}),o===de&&e.jsx(J,{formik:a,project:i}),o===fe&&e.jsx(W,{formik:a,project:i}),o===ue&&e.jsx(X,{formik:a,project:i}),o===ye&&e.jsx(Z,{formik:a,project:i}),o===je&&e.jsx(ee,{formik:a,project:i}),o===Pe&&e.jsx(ae,{formik:a}),o===he&&e.jsx(se,{formik:a,setSection:r}),o===xe&&e.jsx(oe,{formik:a}),o===Se&&e.jsx(ie,{formik:a}),o===Ne&&e.jsx(te,{formik:a}),o===Ce&&e.jsx(re,{formik:a,project:i}),o===c&&e.jsx($,{yaml:F(),setYaml:s=>{a.setFieldValue("yaml",s)},children:e.jsx(Ie,{entity:"profile",docPath:"/profiles"})})]})},o)]}),e.jsxs(De,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(z,{formik:a,section:o,setSection:r,disableReason:a.values.name?void 0:"Please enter a profile name before adding custom configuration"})}),e.jsx(t.Button,{appearance:"base",onClick:async()=>l(`${y}/ui/project/${encodeURIComponent(i)}/profiles`),children:"Cancel"}),e.jsx(t.ActionButton,{appearance:"positive",loading:a.isSubmitting,disabled:!a.isValid||a.isSubmitting||!a.values.name||ne(a)||ce(a),onClick:()=>{a.submitForm()},children:"Create"})]}),(d.panel===h.editNetworkDevice||d.panel===h.createNetworkDevice)&&e.jsx(le,{project:i,formik:a})]})};export{Ze as default};
