import{f as R,d as i,k as b,l as C,r,J as f,u as E,g as N,M as q,D,c as L,P as $,Q as w,R as y,S as B,q as j,j as e,H as Q}from"./index-BTX30BGB.js";import{c as T,a as z}from"./index.esm-BV12eBbn.js";import{P as A,c as H,i as J,d as K,n as O,p as M,a as V,r as I,b as U}from"./ProjectForm-Dh6Y8j7-.js";import{B as Z}from"./BaseLayout-C9qzVjMS.js";import{F as G}from"./FormFooterLayout-C8pm2C5J.js";import{R as W}from"./ResourceLink-O9uDwzG_.js";import"./FormMenuItem-DWiPu6Qh.js";import"./instanceOptions-BVjIWe7l.js";import"./ConfigFieldDescription-BRIgBWxu.js";import"./AutoExpandingTextArea-DKXPgS_L.js";import"./ScrollableTable-CbBkBQ-n.js";import"./formFields-BDRvqvBI.js";import"./snapshots-L1dGj61Z.js";import"./StoragePoolSelector-CKTl-q9P.js";import"./CustomSelect-CW7z77eu.js";import"./StoragePoolSize-DSKdgV_O.js";import"./DiskSizeSelector-DAjbyRDE.js";import"./NotificationRow-BrFpgHY8.js";import"./ScrollableContainer-BFMZMaL4.js";import"./ResourceIcon-ppn0Y8QG.js";const gt=()=>{var u;const s=R(),c=i.useNotify(),n=b(),g=C(),h=r.useState(null),[p,P]=r.useState(f(A)),{hasProjectsNetworksZones:S,hasStorageBuckets:_}=E(),{data:l}=N({queryKey:[j.profiles,"default","default"],queryFn:()=>y("default","default")}),x=T().shape({name:z().test("deduplicate","A project with this name already exists",t=>q(t,"",h,"projects")).required()}),m=()=>{Q("form-contents","p-bottom-controls")};r.useEffect(m,[(u=c.notification)==null?void 0:u.message,p]),D("resize",m);const d=t=>{s(`/ui/project/${t.name}/instances`),n.success(e.jsxs(e.Fragment,{children:["Project"," ",e.jsx(W,{type:"project",value:t.name,to:`/ui/project/${t.name}/instances`})," ","created."]}))},o=L({initialValues:{name:"",restricted:!1,readOnly:!1,entityType:"project",default_instance_storage_pool:l?$(l):""},enableReinitialize:!0,validationSchema:x,onSubmit:t=>{const k=t.restricted?{...H(t),...J(t),...K(t),...O(t)}:{};S||(t.features_networks_zones=void 0),_||(t.features_storage_buckets=void 0),w(JSON.stringify({...M(t),config:{...V(t),...I(t),...k}})).then(async()=>{if(!t.default_instance_storage_pool||t.features_profiles===!1){d(t);return}const a=await y("default",t.name);a.devices={root:{path:"/",pool:t.default_instance_storage_pool,type:"disk"}},B(a,t.name).then(()=>{d(t)}).catch(F=>{s(`/ui/project/${t.name}/instances`),n.failure(`Successfully created ${a.name}, Failed to attach storage pool`,F)})}).catch(a=>{o.setSubmitting(!1),c.failure("Project creation failed",a)}).finally(()=>{g.invalidateQueries({queryKey:[j.projects]})})}});return e.jsxs(Z,{title:"Create a project",contentClassName:"create-project",children:[e.jsx(U,{formik:o,section:p,updateSection:t=>P(f(t)),isEdit:!1}),e.jsxs(G,{children:[e.jsx(i.Button,{appearance:"base",onClick:()=>s(-1),children:"Cancel"}),e.jsx(i.ActionButton,{appearance:"positive",loading:o.isSubmitting,disabled:!o.isValid||!o.values.name,onClick:()=>void o.submitForm(),children:"Create"})]})]})};export{gt as default};
