import{s as R,d as o,n as C,r as c,ax as m,Q as b,a as F,aG as N,f as $,h as D,z as E,l as L,aH as T,aI as q,aJ as z,R as j,q as A,aK as B,aL as O,j as t,ah as H,P as I}from"./index-66XtK6kJ.js";import{P as J,i as K,n as Q,d as U,a as G,c as V,r as M,p as Z,b as W,e as X}from"./ProjectForm-Cs_bQb42.js";import{B as Y}from"./BaseLayout-DHllEyf6.js";import{F as v}from"./FormFooterLayout-CcTAlRx3.js";import"./FormMenuItem-DRWC8EpE.js";import"./AutoExpandingTextArea-BdkUE9YB.js";import"./ScrollableForm-DnwqOi93.js";import"./NetworkSelector-Cw3ouSc2.js";import"./useNetworks-CRf3hLWI.js";import"./ProfileRichChip-BYCO4lqY.js";import"./ProfileResourceLimits-Bgn_DF19.js";import"./DiskSizeSelector-CY9M2-VV.js";import"./useResources-9vpG47dy.js";import"./useClusterGroups-BzHb3mR3.js";import"./useImageRegistries-BGzu7wSY.js";import"./image-registries-Dmf_bwCV.js";const ye=()=>{const i=R(),f=o.useNotify(),l=o.useToastNotification(),y=C(),_=c.useState(null),[p,h]=c.useState(m(J)),{hasProjectsNetworksZones:g,hasStorageBuckets:P}=b(),{isFineGrained:k}=F(),{data:s}=N("default","default"),S=$().shape({name:D().test("deduplicate","A project with this name already exists",async e=>E(e,"",_,"projects")).required()}),u=()=>{H("form-contents","p-bottom-controls")};c.useEffect(u,[f.notification?.message,p]),o.useListener(window,u,"resize",!0);const d=e=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),l.success(t.jsxs(t.Fragment,{children:["Project"," ",t.jsx(I,{projectName:e.name,urlSuffix:"/instances"})," ","created."]}))},a=L({initialValues:{name:"",restricted:!1,readOnly:!1,entityType:"project",default_instance_storage_pool:s?O(s):"",default_project_network:s?B(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),...G(e),...U(e),...Q(e),...K(e)}:{};g||(e.features_networks_zones=void 0),P||(e.features_storage_buckets=void 0);const n=e.default_project_network!=="none";T(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 q("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"}}},z(r,e.name).then(()=>{d(e)}).catch(x=>{i(`${j}/ui/project/${encodeURIComponent(e.name)}/instances`),l.failure(`Successfully created ${e.name} project. Failed to attach storage pool${n?" and network":""}.`,x)})}).catch(r=>{a.setSubmitting(!1),f.failure("Project creation failed",r)}).finally(()=>{y.invalidateQueries({queryKey:[A.projects]})})}});return t.jsxs(Y,{title:"Create a project",contentClassName:"create-project",children:[t.jsx(X,{formik:a,section:p,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};
