import{r as N,cH as v,fl as B,j as e,ct as _,ay as I,bP as O,ae as y,aO as w,af as T,Z as k,fm as A,am as G,an as K,b4 as Y,aR as $,aF as L,K as U,a as u,aG as f,ax as F,b3 as g,aT as p,O as Q,a3 as R,a4 as Z,ci as H,aS as W,a7 as q,fn as J,ai as X,ck as M}from"./index-d6499a22.js";import{c as P}from"./utils-2832fe88.js";const D=({control:o})=>{var n,c;const{data:{email:x}={}}=v(),{data:m=[],isLoading:t,error:r}=B(),i=((c=(n=r==null?void 0:r.response)==null?void 0:n.data)==null?void 0:c.errorCode)!==160057,a=m.map(({email:s})=>s).filter(s=>s!==x);return e.jsxs(e.Fragment,{children:[e.jsx(_,{legend:"Project members"}),e.jsx(I,{control:o,name:"membersEmails",render:({field:{onChange:s,value:d}})=>i?e.jsx(O,{isMulti:!0,preventAdding:!0,value:d,label:"Members",labelAction:e.jsx(y,{position:w.right,mainText:"You can edit member roles later",children:e.jsx(T,{ml:"5px",icon:k.info_block,size:"xs"})}),placeholder:"pick members",onChange:l=>s(l),disabled:t||!a.length,options:a,noDataMessage:"No other member registered in this cluster"}):e.jsx(O,{isMulti:!0,label:"Members",value:d,labelAction:e.jsx(y,{position:w.right,mainText:"You can edit member roles later",children:e.jsx(T,{ml:"5px",icon:k.info_block,size:"xs"})}),placeholder:"enter an email",options:[],onChange:l=>s(l)})})]})},ee=N.memo(D),re=o=>q().shape({projectName:J("consecutiveUnderlines",X.notOneOf(o,"This name already exists").label("Name")),description:M.label("Description"),featureStoreTopic:M}),se=({isLoading:o,onSubmit:x,onDelete:m,isEdit:t,initialData:r,projectsNames:i=[],isProgressingSubmit:a,isSuccessSubmit:n,progressElement:c})=>{const s=N.useMemo(()=>re(i),[i]),{data:d}=A(),{handleSubmit:l,formState:{errors:h},register:j,control:S}=G({mode:"onTouched",defaultValues:{projectName:r==null?void 0:r.projectName,description:r==null?void 0:r.description,membersEmails:[],featureStoreTopic:r==null?void 0:r.featureStoreTopic},resolver:K(s),shouldUnregister:!1}),b=Y.size(h),C=b===0?"":`${b} error${b>1?"s":""}`,E=$(),[z,V]=L({name:["projectName","description"],control:S});return e.jsxs("form",{onSubmit:l(x),children:[e.jsx(U,{title:t?"Edit a project":"Create a New Project",mb:"100px",children:(a||n)&&c?c:e.jsxs(u,{flexDirection:"column",children:[e.jsxs(u,{children:[e.jsx(f,{label:"Name",readOnly:t,...j("projectName"),placeholder:"project_acme",labelAction:e.jsx(y,{mainText:"Only alphanumeric characters, dash or underscore",position:"right",children:e.jsx(T,{ml:"5px",size:"xs",icon:k.info_block})}),...F("projectName",h)}),e.jsx(f,{labelProps:{ml:"20px",flex:1},label:"Description",...j("description"),placeholder:"project about....",...F("description",h)})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(_,{legend:"External topic"}),e.jsx(f,{label:"Topic name",...j("featureStoreTopic"),placeholder:"featurestore_topic"})]}),!t&&e.jsx(ee,{control:S}),t&&m&&e.jsx(g,{text:"Danger zone",width:"fit-content",mt:0,children:e.jsx(p,{intent:"alert",disabled:o,onClick:m,children:"Delete the project"})}),e.jsxs(g,{mt:"10px",children:["Invite new members",e.jsx(Q,{mt:"5px",children:e.jsx(R,{type:Z.neutral,content:e.jsxs(u,{alignItems:"center",children:[e.jsx(g,{children:"Learn more about how to add new user"}),e.jsx(p,{type:"button",pl:"3px",my:"-8px",intent:"inline",children:e.jsx("a",{href:"https://docs.hopsworks.ai/".concat(H.docsVersion,"/user_guides/projects/project/add_members/"),target:"_blank",rel:"noreferrer",style:{color:"inherit"},children:"here↗"})})]})})})]})]})}),e.jsx(W,{title:P(z||"",24),firstValue:P(V||"",50),mainButton:e.jsx(p,{type:"submit",isLoading:a,disabled:o||n,intent:"primary",children:t?"Edit Project":"Create New Project"}),secondaryButton:e.jsx(p,{type:"button",disabled:o||a,intent:"secondary",onClick:()=>E(-1),children:"Back"}),hasScrollOnScreen:!1,errorsValue:C})]})},ae=N.memo(se);export{ae as P};
