import{s as o,aw as M,T as $,q,j as t,h as c,ax as G,c as K,ay as H,az as W,aA as Y,aj as Q,aB as V,aC as X,aD as A,aE as k,aF as R,f as Z,aG as ee}from"./index-DxWYYOj0.js";import{u as te,P as oe,D as ae}from"./useProjectForm-D2PONtKL.js";const re=o("form")(({theme:e})=>({background:e.palette.background.default})),E=o("div")(({theme:e})=>({"& + *":{borderBlockStart:`1px solid ${e.palette.divider}`},padding:e.spacing(7)})),ne=o(E)(({theme:e})=>({display:"grid",gridTemplateAreas:'"icon header" "icon project-name" "icon project-description"',gridTemplateColumns:"auto 1fr",gap:e.spacing(2)})),se=o(M)(({theme:e})=>({color:e.palette.primary.main})),ce=o($)(({theme:e})=>({gridArea:"header",alignSelf:"center",fontWeight:"lighter"})),ie=o("div")(({theme:e})=>({gridArea:"project-name"})),de=o("div")(({theme:e})=>({gridArea:"project-description"})),w=o(q)(({theme:e})=>({width:"100%",fieldset:{border:"none"}})),le=o(w)(({theme:e})=>({"*":{fontSize:e.typography.h1.fontSize}})),pe=o(w)(({theme:e})=>({"*":{fontSize:e.typography.h2.fontSize}})),ue=o(E)(({theme:e})=>({display:"flex",gap:e.spacing(2)})),je=o(E)(({theme:e})=>({display:"flex",gap:e.spacing(5),justifyContent:"flex-end"})),me="PROJECT_NAME_INPUT",ge="PROJECT_DESCRIPTION_INPUT",he=({children:e,handleSubmit:m,projectName:g,projectDesc:h,projectStickiness:P,featureLimit:C,featureCount:i,projectMode:f,setProjectMode:T,setProjectId:s,setProjectName:d,setProjectDesc:l,setProjectStickiness:x,setFeatureLimit:y,errors:n,mode:p,clearErrors:u})=>{const S=a=>{const r=a.target.value;d(r);const j=r?`${encodeURIComponent(r.trim())}-${G().slice(-12)}`:"";s(j)};return t.jsxs(re,{onSubmit:a=>{m(a)},children:[t.jsxs(ne,{children:[t.jsx(se,{"aria-hidden":"true"}),t.jsx(ce,{variant:"h2",children:"New project"}),t.jsx(ie,{children:t.jsx(le,{label:"Project name",required:!0,value:g,onChange:S,error:!!n.name,errorText:n.name,onFocus:()=>{delete n.name},"data-testid":me,autoFocus:!0})}),t.jsx(de,{children:t.jsx(pe,{className:"description",label:"Description (optional)",multiline:!0,maxRows:20,value:h,onChange:a=>l(a.target.value),"data-testid":ge})})]}),t.jsxs(ue,{children:[t.jsx(c,{variant:"outlined",children:"4 selected"}),t.jsx(c,{variant:"outlined",children:"clientId"}),t.jsx(c,{variant:"outlined",children:"Open"}),t.jsx(c,{variant:"outlined",children:"1 environment configured"})]}),t.jsx(je,{children:e})]})},U="CREATE_PROJECT_BTN",O=o(c)(({theme:e})=>({marginLeft:e.spacing(3)})),fe=()=>{const{setToastData:e,setToastApiError:m}=K(),{refetchUser:g}=H(),{uiConfig:h}=W(),P=Y(),{trackEvent:C}=Q(),{projectId:i,projectName:f,projectDesc:T,projectMode:s,setProjectMode:d,setProjectId:l,setProjectName:x,setProjectDesc:y,getCreateProjectPayload:n,clearErrors:p,validateProjectId:u,validateName:S,setProjectStickiness:a,projectStickiness:r,errors:j}=te(),F=V("newCreateProjectUI"),{createProject:b,loading:I}=X(),N=async D=>{D.preventDefault(),p();const B=S(),L=await u();if(B&&L){const J=n();try{await b(J),g(),P(`/projects/${i}`,{replace:!0}),e({title:"Project created",text:"Now you can add toggles to this project",confetti:!0,type:"success"}),r!==ae&&C("project_stickiness_set"),C("project-mode",{props:{mode:s,action:"added"}})}catch(z){m(Z(z))}}},v=()=>`curl --location --request POST '${h.unleashUrl}/api/admin/projects' \\
--header 'Authorization: INSERT_API_KEY' \\
--header 'Content-Type: application/json' \\
--data-raw '${JSON.stringify(n(),void 0,2)}'`,_=()=>{P(ee)};return F?t.jsx(A,{disablePadding:!0,loading:I,description:"Projects allows you to group feature toggles together in the management UI.",documentationLink:"https://docs.getunleash.io/reference/projects",documentationLinkLabel:"Projects documentation",formatApiCode:v,children:t.jsxs(he,{errors:j,handleSubmit:N,projectId:i,setProjectId:l,projectName:f,projectStickiness:r,projectMode:s,setProjectMode:d,setProjectStickiness:a,setProjectName:x,projectDesc:T,setProjectDesc:y,mode:"Create",clearErrors:p,validateProjectId:u,children:[t.jsx(O,{onClick:_,children:"Cancel"}),t.jsx(k,{name:"project",permission:R,"data-testid":U})]})}):t.jsx(A,{loading:I,title:"Create project",description:"Projects allows you to group feature toggles together in the management UI.",documentationLink:"https://docs.getunleash.io/reference/projects",documentationLinkLabel:"Projects documentation",formatApiCode:v,children:t.jsxs(oe,{errors:j,handleSubmit:N,projectId:i,setProjectId:l,projectName:f,projectStickiness:r,projectMode:s,setProjectMode:d,setProjectStickiness:a,setProjectName:x,projectDesc:T,setProjectDesc:y,mode:"Create",clearErrors:p,validateProjectId:u,children:[t.jsx(k,{name:"project",permission:R,"data-testid":U}),t.jsx(O,{onClick:_,children:"Cancel"})]})})};export{fe as default};
