import{j as l,B as h,c as M,bG as R,r as i,a as C,cs as A,bp as I,bx as N,bz as v,ct as y,q as L,s as S,cu as k,cv as x,by as w}from"./index-C1DmWO_C.js";import{u as z}from"./index-D5tirfGC.js";import{P as D}from"./ProjectForm-V3mBA-NW.js";import"./utils-DospTenN.js";import"./storage-connector-BuEuJyVA.js";import"./FileUploaderButton-BtxUzlTS.js";import"./zipObj-D8EtfWld.js";const F=({children:o})=>l.jsxs(h,{width:"100%",flexDirection:"column",alignItems:"center",children:[l.jsx(M,{bold:!0,color:"gray",fontSize:"18px",mb:"8px",children:"Building new project"}),l.jsx(R,{mb:"20px",children:"Project creation"}),o]}),O=({onFinish:o,onError:m})=>{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}=C(void 0,{skip:!s}),[j,{isUninitialized:f}]=z(),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(m).finally(()=>{o(r)})}else o(r)},[b,P,f,r,o,j,t,m]),n},H=()=>{const o=I();N(w.createProject);const m=v(),{data:s,isLoading:d}=C(),[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(u=>({...u,isProgressing:!1,isSuccess:!0})),setTimeout(()=>{c(e)},1e3)},[c]),b=i.useCallback(e=>{n(u=>({...u,isProgressing:!1,isSuccess:!1}))},[]),j=O({onFinish:P,onError:b}),f=i.useCallback(async e=>{var u;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(T=>({...T,isProgressing:!1,isError:!0}));const E=(u=g==null?void 0:g.response)==null?void 0:u.data;m.error({title:"Error",content:`${E.errorMsg||""} ${E.usrMsg||""}`})}},[p,j,m]),{isProgressing:r,isSuccess:a}=t;return l.jsx(D,{projectsNames:s==null?void 0:s.map(({projectName:e})=>e),isLoading:d,onSubmit:f,isProgressingSubmit:r,isSuccessSubmit:a,progressElement:l.jsx(F,{children:l.jsx(k,{isAnimating:r,animationDuration:x/100,incrementDuration:x/25})})})};export{H as default};
