import{j as m,a as R,c as M,b3 as T,r as i,b as x,aR as N,aX as A,aZ as L,cf as v,g as I,e as S,cg as k,ch as h,aY as w}from"./index-d6499a22.js";import{u as F,R as O}from"./AddMembers-a0e0cff6.js";import{P as y}from"./ProjectForm-3f30231f.js";import"./dumbPluralize-86a9b9d6.js";import"./utils-2832fe88.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.js";import"./FileUploaderButton-c4f1b533.js";import"./useDownload-7167ff3b.js";import"./props-01648cd9.js";import"./zipObj-e651182a.js";const z=({children:o})=>m.jsxs(R,{width:"100%",flexDirection:"column",alignItems:"center",children:[m.jsx(M,{bold:!0,color:"gray",fontSize:"18px",mb:"8px",children:"Building new project"}),m.jsx(T,{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.memebersEmailsToAdd,n=i.useCallback(a=>{d(a)},[d]),{currentData:c,isLoading:P,isFetching:f}=x(void 0,{skip:!s}),[g,{isUninitialized:b}]=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&&!f&&b&&r)if(t!=null&&t.length){const a=t==null?void 0:t.map(e=>({projectTeamPK:{projectId:r,teamMember:e},teamRole:O.DataScientist}));g({id:r,data:{projectTeam:a}}).unwrap().catch(l).finally(()=>{o(r)})}else o(r)},[f,P,b,r,o,g,t,l]),n},W=()=>{const o=N();A(w.createProject);const l=L(),{data:s,isLoading:d}=x(),[p]=v(),[t,n]=i.useState({isProgressing:!1,isSuccess:!1,isError:!1}),c=i.useCallback(e=>{o(I(S.project.view,S.project.value,{id:e}))},[o]),P=i.useCallback(e=>{n(u=>({...u,isProgressing:!1,isSuccess:!0})),setTimeout(()=>{c(e)},1e3)},[c]),f=i.useCallback(e=>{n(u=>({...u,isProgressing:!1,isSuccess:!1}))},[]),g=D({onFinish:P,onError:f}),b=i.useCallback(async e=>{var u;try{n(j=>({...j,isProgressing:!0,isError:!1})),await p({services:["JOBS","JUPYTER","HIVE","KAFKA","FEATURESTORE","SERVING","AIRFLOW"],projectName:e.projectName,description:e.description,featureStoreTopic:e.featureStoreTopic}).unwrap(),g({projectName:e.projectName,memebersEmailsToAdd:e.membersEmails})}catch(j){n(C=>({...C,isProgressing:!1,isError:!0}));const E=(u=j==null?void 0:j.response)==null?void 0:u.data;l.error({title:"Error",content:`${E.errorMsg||""} ${E.usrMsg||""}`})}},[p,g,l]),{isProgressing:r,isSuccess:a}=t;return m.jsx(y,{projectsNames:s==null?void 0:s.map(({projectName:e})=>e),isLoading:d,onSubmit:b,isProgressingSubmit:r,isSuccessSubmit:a,progressElement:m.jsx(z,{children:m.jsx(k,{isAnimating:r,animationDuration:h/100,incrementDuration:h/25})})})};export{W as default};
