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-lOezWVmi.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-lf-aalvO.js";import{B as W}from"./BaseLayout-CM5eWMFT.js";import{F as X}from"./FormFooterLayout-B1eckygM.js";import"./FormMenuItem-D_mb6BGW.js";import"./AutoExpandingTextArea-CUTbkJs9.js";import"./formFields-D9YYYKxX.js";import"./SshKeyForm-DyzN8_u6.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-CHLzDgpY.js";import"./snapshots-ByuD-MsK.js";import"./StoragePoolSelector-IgEwUopy.js";import"./StoragePoolSize-BD_icnzk.js";import"./Meter-CCMCY0F-.js";import"./NetworkSelector-Bu8cRfIi.js";import"./useNetworks-Dvw5If3E.js";import"./networks-C9MSk_NH.js";import"./DiskSizeSelector-B_DkPsg-.js";import"./useClusterGroups-gPFjN-2N.js";import"./NotificationRow-DdxAfFhk.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};
