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-C88DWJny.js";import{y as K,c as $,d as z,o as Q}from"./YamlSwitch-BOxCVwX4.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-CDw1e73J.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-Kh6Eu2sp.js";import{B as Fe}from"./BaseLayout-axPPiMeo.js";import{F as De}from"./FormFooterLayout-BHqxrLH2.js";import{Y as Ie}from"./NetworkDefaultACLSelector-BRkbz2SG.js";import{P as Ee}from"./ProfileRichChip-BlhTHgMo.js";import{u as Oe,p as h}from"./usePanelParams-ip2hqi_i.js";import"./FormMenuItem-f1QSo43l.js";import"./AutoExpandingTextArea-BSlqPK2l.js";import"./scroll-Dc7Cgzms.js";import"./StorageVolumeForm-Ck8O6_vx.js";import"./DiskSizeSelector-BLS6z1wW.js";import"./ScrollableForm-ChpocQAZ.js";import"./snapshots-CbUcgdkb.js";import"./useResources-CnZxMPQp.js";import"./formChangeCount-DduUrcE8.js";import"./useNetworks-C8634WBO.js";import"./ExpandableList-DztXpwLZ.js";import"./NetworkRichChip-DxyZjHa7.js";import"./NetworkSelector-xhyKiiYo.js";import"./useNetworkAcls-P_dd657c.js";import"./network-acls-DoFbevfN.js";import"./ProfileResourceLimits-ChaqL2tV.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};
