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-BGoV7aa6.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-Bb7Y_hk3.js";import{B as W}from"./BaseLayout-CMa6UuLt.js";import{F as X}from"./FormFooterLayout-6fxJS5rR.js";import"./FormMenuItem-DL6BRTfq.js";import"./AutoExpandingTextArea-BSccmSbv.js";import"./formFields-Bl9l8MgP.js";import"./SshKeyForm-CUKak12D.js";import"./limits-CLEFMbq-.js";import"./scroll-BEbDVMxI.js";import"./ConfigFieldDescription-DJQj4qcy.js";import"./snapshots-DaF1fk6i.js";import"./StoragePoolSelector-C3ukTuXY.js";import"./StoragePoolSize-CMqudFqH.js";import"./Meter-Dgx5-6Vk.js";import"./NetworkSelector-CPTW70Fb.js";import"./useNetworks-DAjhMC6T.js";import"./networks-C4OkUUfr.js";import"./DiskSizeSelector-CdqrTfL2.js";import"./useClusterGroups-B5NyTpyb.js";import"./NotificationRow-TiNMatDC.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};
