import{j as u,d as h,y as M,aV as R,r as i,b as T,bX as A,b4 as N,bb as I,bd as v,bY as y,o as L,q as S,bZ as k,b_ as C,bc as w}from"./index-CK33qGU_.js";import{u as F}from"./index-Bexex3Us.js";import{P as O}from"./ProjectForm-CZu67CSM.js";import"./utils-LzNCUvhl.js";import"./storage-connector-BuEuJyVA.js";import"./useDownload-hrjXceJg.js";import"./useProject-BzBQtp4J.js";import"./length-fOfC3W0h.js";import"./FileUploaderButton-Bppadu35.js";import"./dumbPluralize-CcxDsNiu.js";import"./props-DsctD44O.js";import"./zipObj-DQ8OxaYj.js";const z=({children:o})=>u.jsxs(h,{width:"100%",flexDirection:"column",alignItems:"center",children:[u.jsx(M,{bold:!0,color:"gray",fontSize:"18px",mb:"8px",children:"Building new project"}),u.jsx(R,{mb:"20px",children:"Project creation"}),o]}),D=({onFinish:o,onError:l})=>{const[s,d]=i.useState(),p=s==null?void 0:s.projectName,t=s==null?void 0:s.membersEmailsToAdd,n=i.useCallback(a=>{d(a)},[d]),{currentData:c,isLoading:P,isFetching:b}=T(void 0,{skip:!s}),[j,{isUninitialized:f}]=F(),r=i.useMemo(()=>{var a;return(a=c==null?void 0:c.find(e=>e.projectName===p))==null?void 0:a.projectId},[c,p]);return i.useEffect(()=>{if(!P&&!b&&f&&r)if(t!=null&&t.length){const a=t==null?void 0:t.map(e=>({projectTeamPK:{projectId:r,teamMember:e},teamRole:A.DATA_SCIENTIST}));j({id:r,data:{projectTeam:a}}).unwrap().catch(l).finally(()=>{o(r)})}else o(r)},[b,P,f,r,o,j,t,l]),n},W=()=>{const o=N();I(w.createProject);const l=v(),{data:s,isLoading:d}=T(),[p]=y(),[t,n]=i.useState({isProgressing:!1,isSuccess:!1,isError:!1}),c=i.useCallback(e=>{o(L(S.project.view,S.project.value,{id:e}))},[o]),P=i.useCallback(e=>{n(m=>({...m,isProgressing:!1,isSuccess:!0})),setTimeout(()=>{c(e)},1e3)},[c]),b=i.useCallback(e=>{n(m=>({...m,isProgressing:!1,isSuccess:!1}))},[]),j=D({onFinish:P,onError:b}),f=i.useCallback(async e=>{var m;try{n(g=>({...g,isProgressing:!0,isError:!1})),await p({services:["JOBS","JUPYTER","HIVE","KAFKA","FEATURESTORE","SERVING","AIRFLOW"],projectName:e.projectName,description:e.description,featureStoreTopic:e.featureStoreTopic}).unwrap(),j({projectName:e.projectName,membersEmailsToAdd:e.membersEmails})}catch(g){n(x=>({...x,isProgressing:!1,isError:!0}));const E=(m=g==null?void 0:g.response)==null?void 0:m.data;l.error({title:"Error",content:`${E.errorMsg||""} ${E.usrMsg||""}`})}},[p,j,l]),{isProgressing:r,isSuccess:a}=t;return u.jsx(O,{projectsNames:s==null?void 0:s.map(({projectName:e})=>e),isLoading:d,onSubmit:f,isProgressingSubmit:r,isSuccessSubmit:a,progressElement:u.jsx(z,{children:u.jsx(k,{isAnimating:r,animationDuration:C/100,incrementDuration:C/25})})})};export{W as default};
