import{r as C,az as z,eR as v,j as e,cG as N,aS as I,bH as S,at as T,bm as w,au as _,C as k,f as U,eS as A,ek as K,eT as Y,aD as H,aE as Q,bp as R,bc as L,V as J,y as W,B as f,b5 as b,aR as g,bG as y,b4 as h,d as q,ah as X,ai as Z,c5 as D,br as ee,al as se,eU as re,aG as oe,an as P,cx as $,cd as te}from"./index-C1DmWO_C.js";import{c as B}from"./utils-DospTenN.js";const ae=({control:t})=>{var n,c;const{data:{email:j}={}}=z(),{data:m=[],isLoading:r,error:s}=v(),p=((c=(n=s==null?void 0:s.response)==null?void 0:n.data)==null?void 0:c.errorCode)!==160057,a=m.map(({email:o})=>o).filter(o=>o!==j);return e.jsxs(e.Fragment,{children:[e.jsx(N,{legend:"Project members"}),e.jsx(I,{control:t,name:"membersEmails",render:({field:{onChange:o,value:d}})=>p?e.jsx(S,{isMulti:!0,preventAdding:!0,value:d,label:"Members",labelAction:e.jsx(T,{position:w.right,mainText:"You can edit member roles later",children:e.jsx(_,{ml:"5px",icon:k.info_block,size:"xs"})}),placeholder:"pick members",onChange:l=>o(l),disabled:r||!a.length,options:a,noDataMessage:"No other member registered in this cluster"}):e.jsx(S,{isMulti:!0,label:"Members",value:d,labelAction:e.jsx(T,{position:w.right,mainText:"You can edit member roles later",children:e.jsx(_,{ml:"5px",icon:k.info_block,size:"xs"})}),placeholder:"enter an email",options:[],onChange:l=>o(l)})})]})},ne=C.memo(ae),ce=U(A,K),le=t=>se().shape({projectName:re("consecutiveUnderlines",oe.notOneOf(t,"This name already exists").label("Name")),namespace:P().max(63).label("Namespace"),description:$.label("Description"),featureStoreTopic:$,memberEmails:te().of(P().email().optional())}),me=({isLoading:t,onSubmit:j,onDelete:m,isEdit:r,initialData:s,projectsNames:p=[],isProgressingSubmit:a,isSuccessSubmit:n,progressElement:c})=>{const o=C.useMemo(()=>le(p),[p]),{data:d}=Y(),{handleSubmit:l,formState:{errors:i},register:x,control:O}=H({mode:"onTouched",defaultValues:{projectName:s==null?void 0:s.projectName,namespace:s==null?void 0:s.namespace,description:s==null?void 0:s.description,membersEmails:[],featureStoreTopic:s==null?void 0:s.featureStoreTopic},resolver:Q(o),shouldUnregister:!1}),u=ce(i),F=u===0?"":`${u} error${u>1?"s":""}`,M=R(),[E,G]=L({name:["projectName","description"],control:O}),{data:V}=J("kube_skip_namespace_creation");return e.jsxs("form",{onSubmit:l(j),children:[e.jsx(W,{title:r?"Edit a project":"Create a New Project",mb:"100px",children:(a||n)&&c?c:e.jsxs(f,{flexDirection:"column",children:[e.jsxs(f,{children:[e.jsx(b,{label:"Name",readOnly:r,...x("projectName"),placeholder:"project_acme",labelAction:e.jsx(T,{mainText:"Only alphanumeric characters, dash or underscore",position:"right",children:e.jsx(_,{ml:"5px",size:"xs",icon:k.info_block})}),...g("projectName",i)}),e.jsx(b,{labelProps:{ml:"20px",flex:1},label:"Description",...x("description"),placeholder:"project about....",...g("description",i)})]}),d&&e.jsxs(e.Fragment,{children:[e.jsx(N,{legend:"External topic"}),e.jsx(b,{label:"Topic name",...x("featureStoreTopic"),placeholder:"featurestore_topic"})]}),V&&e.jsxs(e.Fragment,{children:[e.jsx(N,{legend:"Kubernetes"}),e.jsx(b,{labelProps:{flex:1},label:"Namespace",readOnly:r,...x("namespace"),placeholder:"Kubernetes pre-created namespace",...g("namespace",i)})]}),!r&&e.jsx(ne,{control:O}),r&&m&&e.jsx(y,{text:"Danger zone",width:"fit-content",mt:0,children:e.jsx(h,{intent:"alert",disabled:t,onClick:m,children:"Delete the project"})}),e.jsxs(y,{mt:"10px",children:["Invite new members",e.jsx(q,{mt:"5px",children:e.jsx(X,{type:Z.neutral,content:e.jsxs(f,{alignItems:"center",children:[e.jsx(y,{children:"Learn more about how to add a new user"}),e.jsx(h,{type:"button",pl:"3px",my:"-8px",intent:"inline",children:e.jsx("a",{href:D("/user_guides/projects/project/add_members/"),target:"_blank",rel:"noreferrer",style:{color:"inherit"},children:"here↗"})})]})})})]})]})}),e.jsx(ee,{title:B(E||"",24),firstValue:B(G||"",50),mainButton:e.jsx(h,{type:"submit",isLoading:a,disabled:t||n,intent:"primary",children:r?"Edit Project":"Create New Project"}),secondaryButton:e.jsx(h,{type:"button",disabled:t||a,intent:"secondary",onClick:()=>M(-1),children:"Back"}),hasScrollOnScreen:!1,errorsValue:F})]})},ie=C.memo(me);export{ie as P};
