import{k as C,d as a,h as R,r as c,V as j,G as b,u as F,a2 as N,c as D,b as E,Y as $,f as L,a3 as q,a4 as B,a5 as T,a6 as A,a7 as I,q as U,j as e,T as z,R as O}from"./index-DET0E_3l.js";import{P as V,n as G,d as H,i as J,c as K,r as Q,p as M,a as Y,b as Z}from"./ProjectForm-C0mlNKld.js";import{B as W}from"./BaseLayout-CzqnKJIH.js";import{F as X}from"./FormFooterLayout-YMKZRDmQ.js";import"./FormMenuItem-CafR0V9n.js";import"./AutoExpandingTextArea-C0eJ1NqN.js";import"./formFields-D4E6x_f1.js";import"./SshKeyForm-CCywfCqi.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-9ZU6uOm7.js";import"./snapshots-Bv7XY7g-.js";import"./StoragePoolSelector-Ca2FS7Dt.js";import"./StoragePoolSize-BLDpiQif.js";import"./Meter-BDgVCBc0.js";import"./NetworkSelector-MWjm_jIc.js";import"./useNetworks-B0Ui0BRT.js";import"./networks-Iph4Lp3C.js";import"./DiskSizeSelector-DzL40sWO.js";import"./useClusterGroups-DzUw0c4L.js";import"./NotificationRow-BgqB5Xch.js";const _t=()=>{var f;const r=C(),p=a.useNotify(),d=a.useToastNotification(),y=R(),h=c.useState(null),[m,g]=c.useState(j(V)),{hasProjectsNetworksZones:P,hasStorageBuckets:_}=b(),{isFineGrained:k}=F(),{data:i}=N("default","default"),S=D().shape({name:E().test("deduplicate","A project with this name already exists",async t=>$(t,"",h,"projects")).required()}),l=()=>{z("form-contents","p-bottom-controls")};c.useEffect(l,[(f=p.notification)==null?void 0:f.message,m]),a.useListener(window,l,"resize",!0);const u=t=>{r(`/ui/project/${encodeURIComponent(t.name)}/instances`),d.success(e.jsxs(e.Fragment,{children:["Project"," ",e.jsx(O,{type:"project",value:t.name,to:`/ui/project/${encodeURIComponent(t.name)}/instances`})," ","created."]}))},o=L({initialValues:{name:"",restricted:!1,readOnly:!1,entityType:"project",default_instance_storage_pool:i?B(i):"",default_project_network:i?q(i):""},enableReinitialize:!0,validationSchema:S,onSubmit:t=>{const w=t.restricted?{...K(t),...J(t),...H(t),...G(t)}:{};P||(t.features_networks_zones=void 0),_||(t.features_storage_buckets=void 0);const n=t.default_project_network!=="none";T(JSON.stringify({...Y(t),config:{...M(t),...Q(t),...w}})).then(async()=>{if(!t.default_instance_storage_pool&&!n||t.features_profiles===!1){u(t);return}const s=await A("default",t.name,k);s.devices={root:{path:"/",pool:t.default_instance_storage_pool,type:"disk"},...n&&{eth0:{name:"eth0",network:t.default_project_network,type:"nic"}}},I(s,t.name).then(()=>{u(t)}).catch(x=>{r(`/ui/project/${encodeURIComponent(t.name)}/instances`),d.failure(`Successfully created ${t.name} project. Failed to attach storage pool${n?" and network":""}.`,x)})}).catch(s=>{o.setSubmitting(!1),p.failure("Project creation failed",s)}).finally(()=>{y.invalidateQueries({queryKey:[U.projects]})})}});return e.jsxs(W,{title:"Create a project",contentClassName:"create-project",children:[e.jsx(Z,{formik:o,section:m,updateSection:t=>{g(j(t))},isEdit:!1}),e.jsxs(X,{children:[e.jsx(a.Button,{appearance:"base",onClick:async()=>r(-1),children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:!o.isValid||o.isSubmitting||!o.values.name,onClick:()=>void o.submitForm(),children:"Create"})]})]})};export{_t as default};
