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-BTX30BGB.js";import{c as B,a as _}from"./index.esm-BV12eBbn.js";import{P as A,c as V,y as G,d as U}from"./YamlSwitch-DkgRZQ-2.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-DWiPu6Qh.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-De11cmSZ.js";import{D as je,N as xe,G as Se,P as he,O as Pe}from"./ProxyDeviceForm-Im1_fdN2.js";import{N as Fe}from"./NotificationRow-BrFpgHY8.js";import{B as Ne}from"./BaseLayout-C9qzVjMS.js";import{F as Ce}from"./FormFooterLayout-C8pm2C5J.js";import{Y as Ee}from"./YamlNotification-tLZQVPt8.js";import{R as De}from"./ResourceLink-O9uDwzG_.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-BRIgBWxu.js";import"./AutoExpandingTextArea-DKXPgS_L.js";import"./ScrollableTable-CbBkBQ-n.js";import"./formFields-BDRvqvBI.js";import"./snapshots-L1dGj61Z.js";import"./StoragePoolSelector-CKTl-q9P.js";import"./CustomSelect-CW7z77eu.js";import"./StoragePoolSize-DSKdgV_O.js";import"./DiskSizeSelector-DAjbyRDE.js";import"./loadCustomVolumes-CM8-iGgW.js";import"./loadIsoVolumes-98-b-df8.js";import"./images-C54fVgI_.js";import"./StorageVolumeForm-CMEZiFCf.js";import"./ClusterMemberSelector-DcVN_9Mu.js";import"./FormLink-DTTNHKE7.js";import"./networks-CpaxpXQg.js";import"./ScrollableContainer-BFMZMaL4.js";import"./ResourceIcon-ppn0Y8QG.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};
