import{r as $,aq as v,eH as z,j as e,ca as F,aF as B,bM as E,am as y,b1 as M,an as T,T as N,f as I,dL as A,eI as L,au as Q,av as Y,b4 as G,aO as H,Q as U,d as u,aR as f,aE as O,aV as g,b6 as p,c as J,aa as K,ab as R,b$ as q,b5 as W,ae as X,eJ as Z,ax as D,c1 as _,bH as ee,ag as re}from"./index-CK33qGU_.js";import{c as C}from"./utils-LzNCUvhl.js";import{l as se}from"./length-fOfC3W0h.js";const te=({control:t})=>{var n,c;const{data:{email:x}={}}=v(),{data:m=[],isLoading:o,error:r}=z(),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(F,{legend:"Project members"}),e.jsx(B,{control:t,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:M.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:o||!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:M.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)})})]})},oe=$.memo(te),ae=I(A,se),ne=t=>X().shape({projectName:Z("consecutiveUnderlines",D.notOneOf(t,"This name already exists").label("Name")),description:_.label("Description"),featureStoreTopic:_,memberEmails:ee().of(re().email().optional())}),ce=({isLoading:t,onSubmit:x,onDelete:m,isEdit:o,initialData:r,projectsNames:i=[],isProgressingSubmit:a,isSuccessSubmit:n,progressElement:c})=>{const s=$.useMemo(()=>ne(i),[i]),{data:d}=L(),{handleSubmit:l,formState:{errors:b},register:h,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:Y(s),shouldUnregister:!1}),j=ae(b),P=j===0?"":`${j} error${j>1?"s":""}`,S=G(),[V,w]=H({name:["projectName","description"],control:k});return e.jsxs("form",{onSubmit:l(x),children:[e.jsx(U,{title:o?"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:o,...h("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})}),...O("projectName",b)}),e.jsx(f,{labelProps:{ml:"20px",flex:1},label:"Description",...h("description"),placeholder:"project about....",...O("description",b)})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(F,{legend:"External topic"}),e.jsx(f,{label:"Topic name",...h("featureStoreTopic"),placeholder:"featurestore_topic"})]}),!o&&e.jsx(oe,{control:k}),o&&m&&e.jsx(g,{text:"Danger zone",width:"fit-content",mt:0,children:e.jsx(p,{intent:"alert",disabled:t,onClick:m,children:"Delete the project"})}),e.jsxs(g,{mt:"10px",children:["Invite new members",e.jsx(J,{mt:"5px",children:e.jsx(K,{type:R.neutral,content:e.jsxs(u,{alignItems:"center",children:[e.jsx(g,{children:"Learn more about how to add a new user"}),e.jsx(p,{type:"button",pl:"3px",my:"-8px",intent:"inline",children:e.jsx("a",{href:q("/user_guides/projects/project/add_members/"),target:"_blank",rel:"noreferrer",style:{color:"inherit"},children:"here↗"})})]})})})]})]})}),e.jsx(W,{title:C(V||"",24),firstValue:C(w||"",50),mainButton:e.jsx(p,{type:"submit",isLoading:a,disabled:t||n,intent:"primary",children:o?"Edit Project":"Create New Project"}),secondaryButton:e.jsx(p,{type:"button",disabled:t||a,intent:"secondary",onClick:()=>S(-1),children:"Back"}),hasScrollOnScreen:!1,errorsValue:P})]})},de=$.memo(ce);export{de as P};
