import{s as R,d as o,n as C,r as c,au as m,Q as b,a as F,aD as N,f as D,h as E,z as $,l as T,aE as q,aF as z,aG as A,R as j,q as B,aH as L,aI as O,j as t,ah as H,P as I}from"./index-C88DWJny.js";import{P as Q,i as U,n as G,d as J,a as K,c as V,r as M,p as Z,b as W,e as X}from"./ProjectForm-CEGEBzcs.js";import{B as Y}from"./BaseLayout-axPPiMeo.js";import{F as v}from"./FormFooterLayout-BHqxrLH2.js";import"./FormMenuItem-f1QSo43l.js";import"./AutoExpandingTextArea-BSlqPK2l.js";import"./ScrollableForm-ChpocQAZ.js";import"./NetworkSelector-xhyKiiYo.js";import"./useNetworks-C8634WBO.js";import"./ProfileRichChip-BlhTHgMo.js";import"./ProfileResourceLimits-ChaqL2tV.js";import"./DiskSizeSelector-BLS6z1wW.js";import"./useResources-CnZxMPQp.js";import"./useClusterGroups-BLU5gYBu.js";import"./useImageRegistries-BkMVQO8F.js";import"./image-registries-T9CKqPfx.js";const ye=()=>{const i=R(),u=o.useNotify(),f=o.useToastNotification(),y=C(),_=c.useState(null),[l,h]=c.useState(m(Q)),{hasProjectsNetworksZones:g,hasStorageBuckets:P}=b(),{isFineGrained:k}=F(),{data:s}=N("default","default"),S=D().shape({name:E().test("deduplicate","A project with this name already exists",async e=>$(e,"",_,"projects")).required()}),p=()=>{H("form-contents","p-bottom-controls")};c.useEffect(p,[u.notification?.message,l]),o.useListener(window,p,"resize",!0);const d=e=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),f.success(t.jsxs(t.Fragment,{children:["Project"," ",t.jsx(I,{projectName:e.name,urlSuffix:"/instances"})," ","created."]}))},a=T({initialValues:{name:"",restricted:!1,readOnly:!1,entityType:"project",default_instance_storage_pool:s?O(s):"",default_project_network:s?L(s):"",features_images:!0,features_profiles:!0,features_networks:!1,features_networks_zones:!1,features_storage_buckets:!0,features_storage_volumes:!0},enableReinitialize:!0,validationSchema:S,onSubmit:e=>{const w=e.restricted?{...V(e),...K(e),...J(e),...G(e),...U(e)}:{};g||(e.features_networks_zones=void 0),P||(e.features_storage_buckets=void 0);const n=e.default_project_network!=="none";q(JSON.stringify({...W(e),config:{...Z(e),...M(e),...w}})).then(async()=>{if(!e.default_instance_storage_pool&&!n||e.features_profiles===!1){d(e);return}const r=await z("default",e.name,k);r.devices={root:{path:"/",pool:e.default_instance_storage_pool,type:"disk"},...n&&{eth0:{name:"eth0",network:e.default_project_network,type:"nic"}}},A(r,e.name).then(()=>{d(e)}).catch(x=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),f.failure(`Successfully created ${e.name} project. Failed to attach storage pool${n?" and network":""}.`,x)})}).catch(r=>{a.setSubmitting(!1),u.failure("Project creation failed",r)}).finally(()=>{y.invalidateQueries({queryKey:[B.projects]})})}});return t.jsxs(Y,{title:"Create a project",contentClassName:"create-project",children:[t.jsx(X,{formik:a,section:l,updateSection:e=>{h(m(e))},isEdit:!1}),t.jsxs(v,{children:[t.jsx(o.Button,{appearance:"base",onClick:async()=>i(-1),children:"Cancel"}),t.jsx(o.ActionButton,{appearance:"positive",loading:a.isSubmitting,disabled:!a.isValid||a.isSubmitting||!a.values.name,onClick:()=>{a.submitForm()},children:"Create"})]})]})};export{ye as default};
