import{j as m,Q as M,x as R,b4 as T,r as i,a as h,aS as N,aY as A,a_ as v,cg as I,c as L,b,ch as k,ci as x,aZ as w}from"./index-ea7817a2.js";import{u as F,R as O}from"./AddMembers-1f193345.js";import{P as y}from"./ProjectForm-fdbc7e29.js";import"./dumbPluralize-86a9b9d6.js";import"./utils-297973b8.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./props-31bc4ea7.js";import"./zipObj-08c84ab1.js";const z=({children:o})=>m.jsxs(M,{width:"100%",flexDirection:"column",alignItems:"center",children:[m.jsx(R,{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}=h(void 0,{skip:!s}),[g,{isUninitialized:E}]=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&&E&&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,E,r,o,g,t,l]),n},W=()=>{const o=N();A(w.createProject);const l=v(),{data:s,isLoading:d}=h(),[p]=I(),[t,n]=i.useState({isProgressing:!1,isSuccess:!1,isError:!1}),c=i.useCallback(e=>{o(L(b.project.view,b.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}),E=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 S=(u=j==null?void 0:j.response)==null?void 0:u.data;l.error({title:"Error",content:`${S.errorMsg||""} ${S.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:E,isProgressingSubmit:r,isSuccessSubmit:a,progressElement:m.jsx(z,{children:m.jsx(k,{isAnimating:r,animationDuration:x/100,incrementDuration:x/25})})})};export{W as default};
