import{n as D,f as I,d as t,k as v,o as O,l as g,r,j as e,M as R,D as b,c as T,E as k,F as L,H as M,O as Y,q as y}from"./index-CzUo07dn.js";import{c as B,a as _}from"./index.esm-BBoKC3tX.js";import{P as A,c as V,y as G,d as U}from"./YamlSwitch-DLbjsyg1.js";import{R as $,S as q,I as w,M as H,B as K,C as Q,Y as z,f as J,a as W,s as X,b as Z,m as ee,c as se,d as oe}from"./FormMenuItem-D-3tk9Lf.js";import{M as j,Y as n,P as ae,a as ie,D as te,N as re,G as ne,O as me,R as ce,S as le,b as pe,c as de,B as fe,C as ue,p as ye}from"./ProfileDetailsForm-zcnDsI1t.js";import{D as je,N as xe,G as Se,P as he,O as Pe}from"./ProxyDeviceForm-DGDXe4Hk.js";import{N as Fe}from"./NotificationRow-IVGrYQV6.js";import{B as Ne}from"./BaseLayout-D6pt0Et9.js";import{F as Ce}from"./FormFooterLayout-CkQ9739Z.js";import{Y as Ee}from"./YamlNotification-DqaTFbgr.js";import{R as De}from"./ResourceLink-5fvv3Myt.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-DYgLBIgn.js";import"./AutoExpandingTextArea-DbenJele.js";import"./ScrollableTable-COas1_r_.js";import"./formFields-BDRvqvBI.js";import"./snapshots-DWXTDgvk.js";import"./StoragePoolSelector-B0M_DZ36.js";import"./CustomSelect-D8P9H5Av.js";import"./StoragePoolSize-DCNPXe9o.js";import"./DiskSizeSelector-C28v9MJO.js";import"./loadCustomVolumes-ByIJGQc6.js";import"./loadIsoVolumes-4uRUCwQb.js";import"./images-3_6Q_8pa.js";import"./StorageVolumeForm-Den1BhUT.js";import"./FormLink-fH1VctPr.js";import"./networks-AOdNDxHC.js";import"./ScrollableContainer-CSFAM_C4.js";import"./ResourceIcon-CQum9kVZ.js";const ss=()=>{var u;const x=D(),m=I(),c=t.useNotify(),S=v(),{project:i}=O(),l=g(),h=r.useState(null),[a,P]=r.useState(j);if(!i)return e.jsx(e.Fragment,{children:"Missing project"});const F=B().shape({name:_().test("deduplicate","A profile with this name already exists",o=>R(o,i,h,"profiles")).required()}),p=()=>{M("form-contents","p-bottom-controls")};r.useEffect(p,[(u=c.notification)==null?void 0:u.message,a]),b("resize",p);const s=T({initialValues:{name:"",devices:[],readOnly:!1,entityType:"profile"},validationSchema:F,onSubmit:o=>{const C=o.yaml?G(o.yaml):d(o);Y(JSON.stringify(C),i).then(()=>{m(`/ui/project/${i}/profiles`),S.success(e.jsxs(e.Fragment,{children:["Profile"," ",e.jsx(De,{type:"profile",value:o.name,to:`/ui/project/${i}/profile/${o.name}`})," ","created."]}))}).catch(E=>{s.setSubmitting(!1),c.failure("Profile creation failed",E)}).finally(()=>{l.invalidateQueries({queryKey:[y.profiles]}),l.invalidateQueries({queryKey:[y.projects,i]})})}}),d=o=>({...ye(o),devices:J(o.devices),config:{...W(o),...X(o),...Z(o),...ee(o),...se(o),...oe(o)}}),f=o=>{s.values.yaml&&o!==n&&s.setFieldValue("yaml",void 0),P(o)};function N(){const o=d(s.values);return U(o)}return e.jsxs(Ne,{title:"Create a profile",contentClassName:"create-profile",children:[e.jsxs(t.Form,{onSubmit:s.handleSubmit,className:"form",children:[a!==n&&e.jsx(ae,{active:a,setActive:f,isDisabled:!s.values.name,formik:s}),e.jsx(t.Row,{className:"form-contents",children:e.jsxs(t.Col,{size:12,children:[e.jsx(Fe,{}),a===j&&e.jsx(ie,{formik:s,isEdit:!1}),a===te&&e.jsx(je,{formik:s,project:i}),a===re&&e.jsx(xe,{formik:s,project:i}),a===ne&&e.jsx(Se,{formik:s,project:i}),a===A&&e.jsx(he,{formik:s,project:i}),a===me&&e.jsx(Pe,{formik:s,project:i}),a===ce&&e.jsx($,{formik:s}),a===le&&e.jsx(q,{formik:s}),a===pe&&e.jsx(w,{formik:s}),a===de&&e.jsx(H,{formik:s}),a===fe&&e.jsx(K,{formik:s}),a===ue&&e.jsx(Q,{formik:s}),a===n&&e.jsx(z,{yaml:N(),setYaml:o=>void s.setFieldValue("yaml",o),children:e.jsx(Ee,{entity:"profile",href:`${x}/profiles`})})]})},a)]}),e.jsxs(Ce,{children:[e.jsx("div",{className:"yaml-switch",children:e.jsx(V,{formik:s,section:a,setSection:f,disableReason:s.values.name?void 0:"Please enter a profile name before adding custom configuration"})}),e.jsx(t.Button,{appearance:"base",onClick:()=>m(`/ui/project/${i}/profiles`),children:"Cancel"}),e.jsx(t.ActionButton,{appearance:"positive",loading:s.isSubmitting,disabled:!s.isValid||!s.values.name||k(s)||L(s),onClick:()=>void s.submitForm(),children:"Create"})]})]})};export{ss as default};
