import{r as S,cK as v,fp as I,j as e,cu as M,az as A,bQ as E,af as y,aP as P,ag as T,z as N,fq as B,an as Q,ao as $,b5 as G,aS as U,aG as Y,E as K,Q as b,aH as f,ay as w,b4 as g,aU as p,o as L,a3 as q,a4 as H,cj as R,aT as W,a7 as J,fr as X,aj as Z,cl as z}from"./index-ea7817a2.js";import{c as C}from"./utils-297973b8.js";const D=({control:o})=>{var n,c;const{data:{email:x}={}}=v(),{data:m=[],isLoading:t,error:r}=I(),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(M,{legend:"Project members"}),e.jsx(A,{control:o,name:"membersEmails",render:({field:{onChange:s,value:d}})=>i?e.jsx(E,{isMulti:!0,preventAdding:!0,value:d,label:"Members",labelAction:e.jsx(y,{position:P.right,mainText:"You can edit member roles later",children:e.jsx(T,{ml:"5px",icon:N.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(E,{isMulti:!0,label:"Members",value:d,labelAction:e.jsx(y,{position:P.right,mainText:"You can edit member roles later",children:e.jsx(T,{ml:"5px",icon:N.info_block,size:"xs"})}),placeholder:"enter an email",options:[],onChange:l=>s(l)})})]})},ee=S.memo(D),re=o=>J().shape({projectName:X("consecutiveUnderlines",Z.notOneOf(o,"This name already exists").label("Name")),description:z.label("Description"),featureStoreTopic:z}),se=({isLoading:o,onSubmit:x,onDelete:m,isEdit:t,initialData:r,projectsNames:i=[],isProgressingSubmit:a,isSuccessSubmit:n,progressElement:c})=>{const s=S.useMemo(()=>re(i),[i]),{data:d}=B(),{handleSubmit:l,formState:{errors:h},register:j,control:k}=Q({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:$(s),shouldUnregister:!1}),u=G.size(h),_=u===0?"":`${u} error${u>1?"s":""}`,F=U(),[O,V]=Y({name:["projectName","description"],control:k});return e.jsxs("form",{onSubmit:l(x),children:[e.jsx(K,{title:t?"Edit a project":"Create a New Project",mb:"100px",children:(a||n)&&c?c:e.jsxs(b,{flexDirection:"column",children:[e.jsxs(b,{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:N.info_block})}),...w("projectName",h)}),e.jsx(f,{labelProps:{ml:"20px",flex:1},label:"Description",...j("description"),placeholder:"project about....",...w("description",h)})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(M,{legend:"External topic"}),e.jsx(f,{label:"Topic name",...j("featureStoreTopic"),placeholder:"featurestore_topic"})]}),!t&&e.jsx(ee,{control:k}),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(L,{mt:"5px",children:e.jsx(q,{type:H.neutral,content:e.jsxs(b,{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(R.docsVersion,"/user_guides/projects/project/add_members/"),target:"_blank",rel:"noreferrer",style:{color:"inherit"},children:"here↗"})})]})})})]})]})}),e.jsx(W,{title:C(O||"",24),firstValue:C(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:()=>F(-1),children:"Back"}),hasScrollOnScreen:!1,errorsValue:_})]})},ae=S.memo(se);export{ae as P};
