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,aA as k,R as y,q as j,ak as _,al as w,am as A,an as Y,ao as B,ap as M,aq as L,aB as U,ar as V,aC as q,e as G,ah as H}from"./index-Dz5JRQhj.js";import{y as K,c as $,d as z,o as Q}from"./YamlSwitch-BsfuLnhQ.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-Fa5HVEEA.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 Ce,C as Ne}from"./ProfileDetailsForm-CyUDV6Jb.js";import{B as Fe}from"./BaseLayout-Zdoa_UmA.js";import{F as De}from"./FormFooterLayout-Da4gzEk-.js";import{Y as Ie}from"./NetworkDefaultACLSelector-CFVSHPge.js";import{P as Ee}from"./ProfileRichChip-SxdUk4Mb.js";import{u as Oe,p as h}from"./usePanelParams-Ct0mzMbg.js";import"./FormMenuItem-lDrBwrvi.js";import"./AutoExpandingTextArea-D6xwa84K.js";import"./scroll-Dc7Cgzms.js";import"./StorageVolumeForm-B5KAdmrq.js";import"./DiskSizeSelector-Dnnbm-Yn.js";import"./ScrollableForm-1W--OJbe.js";import"./snapshots-BXX_Csz7.js";import"./useResources-7atCbUko.js";import"./formChangeCount-BuqgS6kd.js";import"./useNetworks-kWi7yZ5O.js";import"./ExpandableList-C5toH4xB.js";import"./NetworkRichChip-Cbl_TiNv.js";import"./NetworkSelector-CahzGzng.js";import"./useNetworkAcls-cogdr8p1.js";import"./network-acls-AXDaDgjx.js";import"./ProfileResourceLimits-Bjfzp666.js";const Ze=()=>{const l=E(),m=t.useNotify(),x=t.useToastNotification(),{project:i}=O(),p=g(),S=n.useState(null),[o,C]=n.useState(P),d=Oe();if(!i)return e.jsx(e.Fragment,{children:"Missing project"});const N=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:N,onSubmit:s=>{const D=s.yaml?K(s.yaml):u(s);k(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),...M(s),...B(s),...Y(s),...A(s),...w(s),..._(s)}}),r=s=>{a.values.yaml&&s!==c&&a.setFieldValue("yaml",void 0),C(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===Ce&&e.jsx(te,{formik:a}),o===Ne&&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};
