import{r as _,av as z,f8 as A,j as e,cA as N,b9 as Y,aZ as M,ar as T,bt as B,as as k,Z as C,p as G,aY as I,f9 as K,az as Z,aA as Q,bw as U,bk as L,Y as H,m as R,B as f,aM as b,b8 as g,bK as y,aG as h,e as W,af as q,ag as J,c1 as X,bx as D,aj as ee,fa as se,aC as re,al as F,cs as O,c6 as oe}from"./index-dP1W1_bd.js";import{c as P}from"./utils-3BV3J1PE.js";import{l as ae}from"./length-BzpOfCdE.js";const te=({control:a})=>{var n,c;const{data:{email:j}={}}=z(),{data:m=[],isLoading:r,error:s}=A(),p=((c=(n=s==null?void 0:s.response)==null?void 0:n.data)==null?void 0:c.errorCode)!==160057,t=m.map(({email:o})=>o).filter(o=>o!==j);return e.jsxs(e.Fragment,{children:[e.jsx(N,{legend:"Project members"}),e.jsx(Y,{control:a,name:"membersEmails",render:({field:{onChange:o,value:d}})=>p?e.jsx(M,{isMulti:!0,preventAdding:!0,value:d,label:"Members",labelAction:e.jsx(T,{position:B.right,mainText:"You can edit member roles later",children:e.jsx(k,{ml:"5px",icon:C.info_block,size:"xs"})}),placeholder:"pick members",onChange:l=>o(l),disabled:r||!t.length,options:t,noDataMessage:"No other member registered in this cluster"}):e.jsx(M,{isMulti:!0,label:"Members",value:d,labelAction:e.jsx(T,{position:B.right,mainText:"You can edit member roles later",children:e.jsx(k,{ml:"5px",icon:C.info_block,size:"xs"})}),placeholder:"enter an email",options:[],onChange:l=>o(l)})})]})},ne=_.memo(te),ce=G(I,ae),le=a=>ee().shape({projectName:se("consecutiveUnderlines",re.notOneOf(a,"This name already exists").label("Name")),namespace:F().max(63).label("Namespace"),description:O.label("Description"),featureStoreTopic:O,memberEmails:oe().of(F().email().optional())}),me=({isLoading:a,onSubmit:j,onDelete:m,isEdit:r,initialData:s,projectsNames:p=[],isProgressingSubmit:t,isSuccessSubmit:n,progressElement:c})=>{const o=_.useMemo(()=>le(p),[p]),{data:d}=K(),{handleSubmit:l,formState:{errors:i},register:x,control:w}=Z({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),S=u===0?"":`${u} error${u>1?"s":""}`,$=U(),[v,E]=L({name:["projectName","description"],control:w}),{data:V}=H("kube_skip_namespace_creation");return e.jsxs("form",{onSubmit:l(j),children:[e.jsx(R,{title:r?"Edit a project":"Create a New Project",mb:"100px",children:(t||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(k,{ml:"5px",size:"xs",icon:C.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:w}),r&&m&&e.jsx(y,{text:"Danger zone",width:"fit-content",mt:0,children:e.jsx(h,{intent:"alert",disabled:a,onClick:m,children:"Delete the project"})}),e.jsxs(y,{mt:"10px",children:["Invite new members",e.jsx(W,{mt:"5px",children:e.jsx(q,{type:J.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:X("/user_guides/projects/project/add_members/"),target:"_blank",rel:"noreferrer",style:{color:"inherit"},children:"here↗"})})]})})})]})]})}),e.jsx(D,{title:P(v||"",24),firstValue:P(E||"",50),mainButton:e.jsx(h,{type:"submit",isLoading:t,disabled:a||n,intent:"primary",children:r?"Edit Project":"Create New Project"}),secondaryButton:e.jsx(h,{type:"button",disabled:a||t,intent:"secondary",onClick:()=>$(-1),children:"Back"}),hasScrollOnScreen:!1,errorsValue:S})]})},xe=_.memo(me);export{xe as P};
