1import{w as g,r as m,j as t,aG as L,T as S,aF as b,g as j,D as B,b3 as I,aJ as k,f as l,b4 as D,b5 as F,K as $,b6 as A,h as P,B as z,aZ as R,a_ as G,aY as O}from"./index.js";import{E as T}from"./editPencil-BqKs45MF.js";import{A as q}from"./AdminPageLayout-e7xz8aZL.js";const H=["active","inactive"];function M(e,r=[]){const o=[],i={...e},[s,n]=g(e.name,[...r,"name"],{minLength:5,maxLength:50});n?o.push(...n):i.name=s;const[x,a]=g(e.internalName,[...r,"internalName"],{minLength:5,maxLength:200});return a?o.push(...a):i.internalName=x,o.length>0?[null,o]:[i,null]}function J(e,r=[]){const o=[],i={...e};if(e.name){const[s,n]=g(e.name,[...r,"name"],{minLength:5,maxLength:50});n?o.push(...n):i.name=s}if(e.internalName){const[s,n]=g(e.internalName,[...r,"internalName"],{minLength:5,maxLength:200});n?o.push(...n):i.internalName=s}if(e.status){const[s,n]=g(e.status,[...r,"status"],{enum:H});n?o.push(...n):i.status=s}return o.length>0?[null,o]:[i,null]}const y=l.div` 2 margin-bottom: 1em; 3`;function K(e){var E,w,N;const[r,o]=m.useState(((E=e.EditCohortData)==null?void 0:E.name)??""),[i,s]=m.useState(((w=e.EditCohortData)==null?void 0:w.internalName)??""),[n,x]=m.useState((N=e.EditCohortData)==null?void 0:N.status),[a,d]=m.useState(!1),[h,C]=m.useState([]),f=()=>{if(e.EditCohortData){const[c,u]=J({name:r,internalName:i,status:n});return u&&C(u),u}else{const[c,u]=M({name:r,internalName:i});return u&&C(u),u}},v=async()=>{d(!0);const c=f();if(c&&c.length>0){d(!1);return}e.EditCohortData?await D(e.EditCohortData.id,{name:r,internalName:i,status:n}).then(()=>{n&&e.EditCohortData&&e.onClose({id:e.EditCohortData.id,name:r,internalName:i,status:n})}):await F({name:r,internalName:i}).then(u=>{e.onClose(u)}).catch(u=>{d(!1)})};return t.jsxs(L,{title:e.EditCohortData?`Edit: ${e.EditCohortData.name}`:"Create a new cohort",children:[t.jsx(y,{children:t.jsx(S,{error:j(h,["name"]),label:"Cohort name",onChange:c=>{o(c.target.value)},placeholder:"Cohort name",required:!0,type:"text",value:r,style:{borderRadius:"0.5em",backgroundColor:b,border:"none"}})}),t.jsx(y,{children:t.jsx(S,{error:j(h,["internalName"]),label:"Cohort Internal Name",onChange:c=>{s(c.target.value)},required:!0,type:"text",placeholder:"Cohort Internal Name",value:i,style:{borderRadius:"0.5em",backgroundColor:b,border:"none"}})}),e.EditCohortData?t.jsx(y,{children:t.jsx(B,{error:j(h,["status"]),label:"Cohort Status",onChange:c=>{x(c.target.value)},options:[{value:"active",label:"Active"},{value:"inactive",label:"Inactive"}],required:!0,value:n,placeholder:"Select Cohort Status"})}):null,a?t.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%"},children:t.jsx(k,{size:15})}):t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"1em"},children:[t.jsx(I,{onClick:async()=>{await v()},children:e.EditCohortData?"Edit Cohort":"Create Cohort"}),t.jsx(I,{backgroundColor:"#FF6269",onClick:()=>{e.onClose()},children:"Cancel"})]})]})}const V=l.div` 4 display: flex; 5 gap: 20px; 6 margin-bottom: 20px; 7`,W=l.div` 8 display: flex; 9 align-items: center; 10 font-weight: bold; 11 color: ${e=>e.color||"black"}; 12 justify-content: center; 13 14 &:hover { 15 cursor: pointer; 16 text-decoration: underline; 17 } 18`,Y=l.div` 19 width: 30px; 20 height: 30px; 21 min-width: 30px; 22 -webkit-user-select: none; 23 -moz-user-select: none; 24 -ms-user-select: none; 25 user-select: none; 26 border-radius: 100px; 27 background-image: ${e=>`url(${e.src})`}; 28 background-position: center; 29 background-size: 20px 20px; 30 background-repeat: no-repeat; 31 32 @media (max-width: 830px) { 33 margin-right: 0; 34 } 35`,Z=l.div` 36 display: flex; 37 flex-direction: column; 38 gap: 20px; 39 margin-bottom: 20px; 40`,_=l.div` 41 display: flex; 42`;l.div` 43 width: 15px; 44 height: auto; 45 background-color: ${e=>e.color}; 46`;const Q=l.div` 47 display: grid; 48 grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr) minmax(90px, 0.6fr) minmax(110px, 0.7fr) auto; 49 align-items: center; 50 padding: 10px; 51 column-gap: 20px; 52 width: 100%; 53 box-sizing: border-box; 54 background-color: ${b}; 55 56 @media (max-width: 830px) { 57 grid-template-columns: minmax(0, 1fr); 58 row-gap: 10px; 59 } 60`,p=l(O)` 61 min-width: 0;
62 overflow-wrap: anywhere; 63`,U=l.div` 64 display: flex; 65 align-items: center; 66 justify-content: flex-end; 67 gap: 15px; 68 min-width: max-content; 69 70 @media (max-width: 830px) { 71 justify-content: flex-start; 72 } 73`,X=l.img` 74 width: 20px; 75 height: 20px; 76 object-fit: cover; 77`;function ae(){const{set_overlay:e}=$(),[r,o]=m.useState([]),[i,s]=m.useState(!0);m.useEffect(()=>{let a=!1;return A().then(d=>{a||(o(d),s(!1))}),()=>{a=!0}},[]);function n(a){e({element:t.jsx(K,{EditCohortData:a,onClose:d=>{var h;if(d)if(a){const C=r.findIndex(v=>v.id===d.id),f=[...r];f[C]={...d,userCount:((h=r[C])==null?void 0:h.userCount)??0},o(f)}else o([...r,{...d,userCount:0}]);e==null||e(void 0)}}),onClose:()=>{e==null||e(void 0)}})}const x=r.map(a=>t.jsx(_,{children:t.jsxs(Q,{children:[t.jsx(p,{fontFamily:"Cera Pro",fontWeight:"bolder",children:a.name}),t.jsx(p,{children:a.internalName}),t.jsx(p,{children:a.status}),t.jsxs(p,{children:[a.userCount," ",a.userCount===1?"user":"users"]}),t.jsxs(U,{children:[t.jsx(P,{onClick:()=>{n(a)},children:t.jsx(X,{src:T})}),t.jsx(z,{to:`/admin/cohorts/${a.id}`,children:"Manage"})]})]})},a.id+a.name));return t.jsx(q,{children:t.jsxs("div",{children:[t.jsxs(V,{children:[t.jsx(R,{children:"Cohorts"}),t.jsxs(W,{color:"#187b8b",onClick:()=>{n()},style:{marginBottom:"0.05em"},children:[t.jsx(Y,{src:G})," Create new cohort"]})]}),t.jsx(Z,{children:i?t.jsx("div",{style:{display:"flex",justifyContent:"center",width:"100%",height:"600px",alignContent:"center"},children:t.jsx(k,{size:50})}):x})]})})}export{ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.