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-Cziemgsu.js";import{c as B,a as _}from"./index.esm-dDZ7-lOE.js";import{P as A,c as V,y as G,d as U}from"./YamlSwitch-GKWclbu0.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-phSiN9Ls.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-DDEMx7zg.js";import{D as je,N as xe,G as Se,P as he,O as Pe}from"./ProxyDeviceForm-BTkaAeHm.js";import{N as Fe}from"./NotificationRow-BJRTvUVl.js";import{B as Ne}from"./BaseLayout-7LTMOawH.js";import{F as Ce}from"./FormFooterLayout-BJQGpdhQ.js";import{Y as Ee}from"./YamlNotification-hNvwvtOz.js";import{R as De}from"./ResourceLink-D2AYI_En.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-1GO19eHS.js";import"./AutoExpandingTextArea-Bc4N4lSt.js";import"./ScrollableTable-D1yV1_jU.js";import"./formFields-BDRvqvBI.js";import"./snapshots-AEdTpwkf.js";import"./StoragePoolSelector-BZZPCPdz.js";import"./CustomSelect-1ZX4nHvi.js";import"./StoragePoolSize-DPO2JD2N.js";import"./DiskSizeSelector--EFhW8D8.js";import"./loadCustomVolumes-SPkmqkDH.js";import"./loadIsoVolumes-DrpDOMmD.js";import"./images-BCSn6jQa.js";import"./StorageVolumeForm-0gLpkZqf.js";import"./ClusterMemberSelector--J9qxfzT.js";import"./FormLink-DCIl5gxX.js";import"./networks-mhWNV24c.js";import"./ScrollableContainer-C6sud4ax.js";import"./ResourceIcon-DRRIqKSs.js";const os=()=>{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{os as default};
