import{j as u,B as h,b as M,bK as N,r as i,a as T,cn as R,bw as A,bC as I,aE as L,co as v,q as w,s as S,cp as k,cq as C,bD as D}from"./index-dP1W1_bd.js";import{u as F}from"./index-BjpivH0P.js";import{P as O}from"./ProjectForm-DftUkOfx.js";import"./utils-3BV3J1PE.js";import"./storage-connector-BuEuJyVA.js";import"./useDownload-C3yCvYJa.js";import"./useProject-CXVt1xnE.js";import"./length-BzpOfCdE.js";import"./FileUploaderButton-frSujVRY.js";import"./uniq-98MdbBvs.js";import"./uniqBy-6mvKp2Ip.js";import"./dumbPluralize-CcxDsNiu.js";import"./zipObj-DEkcXp9d.js";const y=({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(N,{mb:"20px",children:"Project creation"}),o]}),z=({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:f}=T(void 0,{skip:!s}),[j,{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:R.DATA_SCIENTIST}));j({id:r,data:{projectTeam:a}}).unwrap().catch(l).finally(()=>{o(r)})}else o(r)},[f,P,b,r,o,j,t,l]),n},X=()=>{const o=A();I(D.createProject);const l=L(),{data:s,isLoading:d}=T(),[p]=v(),[t,n]=i.useState({isProgressing:!1,isSuccess:!1,isError:!1}),c=i.useCallback(e=>{o(w(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]),f=i.useCallback(e=>{n(m=>({...m,isProgressing:!1,isSuccess:!1}))},[]),j=z({onFinish:P,onError:f}),b=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,namespace:e.namespace,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:b,isProgressingSubmit:r,isSuccessSubmit:a,progressElement:u.jsx(y,{children:u.jsx(k,{isAnimating:r,animationDuration:C/100,incrementDuration:C/25})})})};export{X as default};
