1import{j as e,cW as t,ae as s,am as a,r as l,a9 as i}from"./index-GDMS6ldZ.js";import{A as r}from"./AdminListPageHeader-3o4Km4dD.js";import{A as n}from"./AdminDataTable-CcoZ3Y6N.js";import{f as o,g as d}from"./adminUserUtils-1NfAmp-U.js";import{S as c}from"./cells-FTb5Xa3u.js";import{F as m}from"./ShieldCheckIcon-DD02hlDs.js";import{F as u}from"./CheckCircleIcon-DYgu-tdI.js";import{F as x}from"./XMarkIcon-DrgZsvNU.js";import{F as g}from"./index.es-BNbyiAtg.js";import{d as p,e as h}from"./index-ymjA_K7O.js";import{y as f,D as b,j}from"./dialog-DI7BzUC6.js";import{F as v}from"./XMarkIcon-saypijZy.js";import{U as y}from"./UserAccessModal-CeVv3P_w.js";import{u as w,a as N}from"./adminPlatformApi-CEamUoVG.js";import{F as S}from"./MagnifyingGlassIcon-D9LWneJi.js";import{F as C}from"./UserPlusIcon-CSDy65gQ.js";import"./InformationCircleIcon-BqW0tfkd.js";import"./ArrowPathIcon-D-MTjHNq.js";import"./AdminAsyncState-VhllU-mN.js";import"./ExclamationCircleIcon-DBE7OqCV.js";import"./ChevronLeftIcon-BUBYIo34.js";import"./ChevronRightIcon-8w11xhHf.js";import"./portal-CpA9E1LO.js";import"./use-tab-direction-r0j1w13K.js";import"./hidden-DAIQtKKH.js";const A={active:{label:"Active",tone:"green"},disabled:{label:"Disabled",tone:"red"}};function k({value:t}){return t?e.jsx("span",{className:"inline-flex items-center justify-center rounded-full bg-emerald-50 p-1",children:e.jsx(u,{className:"h-4 w-4 text-emerald-600","aria-hidden":"true"})}):e.jsx("span",{className:"inline-flex items-center justify-center rounded-full bg-red-50 p-1",children:e.jsx(x,{className:"h-4 w-4 text-red-500","aria-hidden":"true"})})}function I({user:a}){const l=o(a),i=t(a.id),r="truncate text-left transition-colors hover:text-blue-700 focus:outline-none focus-visible:underline",n={user:a};return e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-full bg-slate-100 text-xs font-bold text-slate-600 ring-1 ring-slate-200","aria-hidden":"true",children:d(a)}),e.jsxs("div",{className:"min-w-0",children:[l?e.jsx(s,{to:i,state:n,className:`block font-semibold text-slate-900 ${r}`,title:l,children:l}):e.jsx(s,{to:i,state:n,className:`block font-semibold text-slate-500 italic ${r}`,title:a.email,children:"Unnamed user"}),a.email?e.jsx(s,{to:i,state:n,className:`mt-0.5 block text-xs text-slate-500 ${r}`,title:a.email,children:a.email}):e.jsx("p",{className:"mt-0.5 truncate text-xs text-slate-400",children:"No email"})]})]})}const L=({canManageAccess:t=!1,onManageAccess:s=()=>{}}={})=>[{id:"user",header:"User",meta:{width:"280px",sortKey:"name"},cell:({row:t})=>e.jsx(I,{user:t.original})},{id:"roles",header:"Roles",meta:{width:"180px"},cell:({row:t})=>{const s=Array.isArray(t.original.roles)?t.original.roles:[];return 0===s.length?e.jsx("span",{className:"text-xs text-slate-400",children:"â"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:s.map(t=>e.jsx(c,{label:String(t).replace("ROLE_",""),tone:"green"},t))})}},{id:"isSuperAdmin",header:"Super Admin",meta:{width:"110px",align:"center"},cell:({row:t})=>e.jsx(k,{value:t.original.isSuperAdmin})},{id:"nationalViewOverride",header:"National View",meta:{width:"120px",align:"center"},cell:({row:t})=>e.jsx(k,{value:Boolean(t.original.nationalViewOverride)})},{id:"hasSubscription",header:"Subscription",meta:{width:"120px",align:"center"},cell:({row:t})=>{if(!(!0===t.original.hasSubscription))return e.jsx(c,{label:"None",tone:"gray"});const s=t.original.subscriptionStatus,a=s&&"active"!==s?s.charAt(0).toUpperCase()+s.slice(1):"Subscribed";return e.jsx(c,{label:a,tone:"green"})}},{id:"iqPlusMember",header:"IQ+ Member",meta:{width:"110px",align:"center"},cell:({row:t})=>!0===t.original.iqPlusMember?e.jsx(c,{label:"IQ+",tone:"green"}):e.jsx(c,{label:"None",tone:"gray"})},{id:"iqCredits",header:"Credits",meta:{width:"100px",align:"right",sortKey:"iqCredits"},cell:({row:t})=>{const s=Number(t.original.iqCredits??0),a=s<100?"font-semibold text-red-600":s<1e3?"font-semibold text-amber-600":"font-medium text-slate-800";return e.jsx("span",{className:`tabular-nums text-sm ${a}
1`,children:s.toLocaleString()})}},{id:"dateCreated",header:"Registered",meta:{width:"120px",align:"center",sortKey:"dateCreated"},cell:({row:t})=>t.original.dateCreated?e.jsx("p",{className:"truncate text-xs font-medium text-slate-700",title:t.original.dateCreated,children:String(t.original.dateCreated).slice(0,10)}):e.jsx("span",{className:"text-xs text-slate-400",children:"â"})},{id:"lastLogin",header:"Last Login",meta:{width:"140px",align:"center",sortKey:"lastLogin"},cell:({row:t})=>t.original.lastLogin?e.jsx("p",{className:"truncate text-xs font-medium text-slate-700",title:t.original.lastLogin,children:t.original.lastLogin}):e.jsx(k,{value:!1})},{id:"status",header:"Status",meta:{width:"90px",align:"center"},cell:({row:t})=>{const{label:s,tone:a}=function(e){const t=!0===e.disabled||"disabled"===e.status?"disabled":e.status||"active";return A[t]??{label:String(t).charAt(0).toUpperCase()+String(t).slice(1),tone:"gray"}}(t.original);return e.jsx(c,{label:s,tone:a})}},{id:"actions",header:"",meta:{width:"96px",align:"right"},cell:({row:a})=>e.jsx("div",{className:"flex items-center justify-end",children:t&&e.jsxs("button",{type:"button",onClick:e=>{e.stopPropagation(),s(a.original)},className:"inline-flex items-center gap-1 rounded-lg border border-blue-200 bg-blue-50 px-2.5 py-1.5 text-xs font-semibold text-blue-700 transition-colors hover:border-blue-300 hover:bg-blue-100",title:"Manage Access",children:[e.jsx(m,{className:"h-3.5 w-3.5"}),"Access"]})})}];function M({open:t,setOpen:s}){const i=a(),[r,n]=l.useState({firstName:"",lastName:"",email:"",password:""}),[o,d]=l.useState(!1),[c,m]=l.useState(!1),[u,x]=l.useState(null);return e.jsxs(f,{open:t,onClose:s,className:"relative z-10",children:[e.jsx(b,{transition:!0,className:"fixed inset-0 bg-gray-500/75 transition-opacity data-[closed]:opacity-0 data-[enter]:duration-300 data-[leave]:duration-200 data-[enter]:ease-out data-[leave]:ease-in"}),e.jsx("div",{className:"fixed inset-0 z-10 w-screen overflow-y-auto",children:e.jsx("div",{className:"flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0",children:e.jsxs(j,{transition:!0,className:"relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all data-[closed]:translate-y-4 data-[closed]:opacity-0 data-[enter]:duration-300 data-[leave]:duration-200 data-[enter]:ease-out data-[leave]:ease-in sm:my-8 sm:w-full sm:max-w-lg sm:p-6 data-[closed]:sm:translate-y-0 data-[closed]:sm:scale-95",children:[e.jsx("div",{className:"absolute right-0 top-0 hidden pr-4 pt-4 sm:block",children:e.jsxs("button",{type:"button",onClick:()=>s(!1),className:"rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2",children:[e.jsx("span",{className:"sr-only",children:"Close"}),e.jsx(v,{"aria-hidden":"true",className:"size-6"})]})}),e.jsx("div",{children:e.jsx("div",{className:"grid grid-cols-1 gap-x-2 gap-y-2 py-1",children:e.jsx("form",{className:"bg-white ",children:e.jsx("div",{className:"px-2 py-2 pt-4 sm:p-2",children:e.jsxs("div",{className:"grid max-w-2xl grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-2",children:[e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("label",{htmlFor:"first-name",className:"block text-sm/6 font-medium text-gray-900",children:"First name"}),e.jsx("div",{className:"mt-2",children:e.jsx("input",{id:"first-name",name:"first-name",value:r.firstName?r.firstName:"",onChange:e=>n({...r,firstName:e.target.value}),type:"text",autoComplete:"given-name",className:"block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6"})})]}),e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("label",{htmlFor:"last-name",className:"block text-sm/6 font-medium text-gray-900",children:"Last name"}),e.jsx("div",{className:"mt-2",children:e.jsx("input",{id:"last-name",name:"last-name",value:r.lastName?r.lastName:"",onChange:e=>n({...r,lastName:e.target.value}),type:"text",autoComplete:"family-name",className:"block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6"})})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{htmlFor:"email",className:"block text-sm/6 font-medium text-gray-900",children:"Email address"}),e.jsx("div",{className:"mt-2",children:e.jsx("input",{id:"email",name:"email",value:r.email?r.email:"",onChange:e=>n({...r,email:e.target.value}),type:"email",autoComplete:"email",className:"block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6"})})]}),e.jsx("div",{className:"sm:col-span-2",children:u&&e.jsx("div",{className:"mb-2 p-2 bg-red-100 border border-red-400 text-red-700 rounded text-center",children:u})}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{htmlFor:"password",className:"block text-sm/6 font-medium text-gray-900",children:"Password"}),e.jsxs("div",{className:"mt-2 relative",children:[e.jsx("input",{id:"password",name:"password",value:r.password?r.password:"",onCh
1ange:e=>n({...r,password:e.target.value}),type:o?"text":"password",autoComplete:"new-password",className:"block w-full rounded-md bg-white px-3 py-1.5 text-base text-gray-900 outline outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6 pr-10"}),e.jsx("button",{type:"button",className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",onClick:()=>d(e=>!e),tabIndex:-1,children:e.jsx(g,{icon:o?p:h})})]})]})]})})})})}),e.jsxs("div",{className:"mt-5 sm:mt-6 sm:grid sm:grid-flow-row-dense sm:grid-cols-2 sm:gap-3",children:[e.jsx("button",{type:"button",onClick:async()=>{if(Object.values(r).some(e=>""===e))x("Please fill in all fields");else{try{m(!0);const e=await i.post("api/admin/iq/add-user",r);(null==e?void 0:e.success)?(n({firstName:"",lastName:"",email:"",password:""}),x(null),s(!1)):x((null==e?void 0:e.message)||"An error occurred")}catch(e){x((null==e?void 0:e.message)||"An error occurred")}finally{m(!1)}s(!1)}},className:"inline-flex w-full justify-center rounded-md bg-gray-800 cursor-pointer px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-gray-700 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:col-start-2",disabled:c,children:c?"Adding...":"Add User"}),e.jsx("button",{type:"button","data-autofocus":!0,onClick:()=>s(!1),className:"mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:col-start-1 sm:mt-0",disabled:c,children:"Cancel"})]})]})})})]})}L();function U(){const[t,s]=l.useState(1),[a,o]=l.useState(""),[d,c]=l.useState(""),[m,u]=l.useState("name"),[x,g]=l.useState("asc"),[p,h]=l.useState(!1),[f,b]=l.useState(null),[j,A]=l.useState(null),{user:k,accessToken:I,expireTime:U,isAdmin:P,isSuperAdmin:F,applyUserSession:O}=i(),{data:R,isLoading:V,isFetching:D,error:T}=w(t,15,d,m,x),{mutateAsync:q,isPending:z}=N(),K=null==R?void 0:R.data,$=null==K?void 0:K.users,E="string"==typeof(null==K?void 0:K.search)?K.search.trim():d.trim(),Q=E.length>0;l.useEffect(()=>{const e=window.setTimeout(()=>{const e=a.trim();c(t=>t===e?t:(s(1),e))},300);return()=>window.clearTimeout(e)},[a]);const W=l.useMemo(()=>L({canManageAccess:P,onManageAccess:e=>{A(null),b(e)}}),[P]),B=Q?`No users match '${E}'.`:"No users found.",G=e=>{const t=e.trim();c(t),s(1)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-6 text-left",children:[e.jsx(r,{title:"Users List",description:"View & Manage Users in IQ's system",isLoading:V&&!K,statValue:(null==K?void 0:K.totalItems)??0,statLabel:Q?"Results":"Total Users"}),(null==K?void 0:K.stats)&&e.jsx("div",{className:"mt-4 grid grid-cols-2 gap-3 lg:grid-cols-5",children:[{label:"Total users",value:K.stats.total},{label:"Subscribed",value:K.stats.subscribed},{label:"IQ+ members",value:K.stats.iqPlusMembers},{label:"Active (7d)",value:K.stats.activeLast7Days},{label:"New (30d)",value:K.stats.newLast30Days}].map(t=>e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-3.5 shadow-sm",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-500",children:t.label}),e.jsx("p",{className:"mt-0.5 text-xl font-bold tabular-nums text-slate-900",children:Number(t.value??0).toLocaleString()})]},t.label))}),e.jsxs("form",{className:"mt-2",onSubmit:e=>{e.preventDefault(),G(a)},children:[e.jsxs("div",{className:"flex w-full flex-row items-center justify-between",children:[e.jsxs("div",{className:"mr-2 flex w-full flex-row",children:[e.jsxs("div",{className:"relative w-full",children:[e.jsx("input",{type:"search",placeholder:"Search users by name, email, or ID...",className:"w-full rounded-md border border-gray-200 bg-white p-2 pr-9 text-sm font-semibold text-neutral-800 shadow-xs",value:a,onChange:e=>o(e.target.value),"aria-label":"Search users by name, email, or ID"}),a.length>0&&e.jsx("button",{type:"button",onClick:()=>{o(""),G("")}
1,className:"absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-gray-400 hover:bg-gray-100 hover:text-gray-600","aria-label":"Clear search",children:e.jsx(v,{className:"h-4 w-4"})})]}),e.jsxs("button",{type:"submit",className:"ml-2 flex cursor-pointer flex-row items-center gap-x-2 rounded-md border border-gray-800 bg-gray-800 px-4 py-2 text-sm font-semibold text-white",children:[e.jsx(S,{className:"h-5 w-5"}),"Search"]})]}),e.jsx("div",{className:"flex flex-row items-center justify-end gap-x-2",children:e.jsxs("button",{type:"button",onClick:()=>h(!0),className:"ml-auto mr-0 flex min-w-[130px] cursor-pointer flex-row items-center gap-x-2 rounded-md border border-blue-700 bg-blue-700 px-4 py-2 text-sm font-semibold text-white",children:[e.jsx(C,{className:"h-5 w-5"}),"Add User"]})})]}),Q&&e.jsxs("p",{className:"mt-2 text-xs font-medium text-slate-500",children:["Showing results for â",E,"â"]})]}),e.jsx(n,{columns:W,data:$,isLoading:V,isFetching:D,error:T,minTableWidth:"84rem",loadingSkeletonRows:15,emptyMessage:B,sort:{key:m,dir:x,onChange:(e,t)=>
1{u(e),g(t),s(1)}},pagination:{currentPage:(null==K?void 0:K.currentPage)??t,totalPages:null==K?void 0:K.pagesCount,totalItems:null==K?void 0:K.totalItems,pageSize:(null==K?void 0:K.pageSize)??15,onPageChange:e=>{s(e)}}})]}),e.jsx(M,{open:p,setOpen:h}),e.jsx(y,{open:Boolean(f),user:f,currentUserId:null==k?void 0:k.id,canManageRoles:F,isSaving:z,error:j,onClose:()=>{z||(b(null),A(null))},onSave:async({userId:e,roles:t,isSuperAdmin:s,nationalViewOverride:a,canManageRoles:l})=>{A(null);try{const i=await q({userId:e,roles:t,isSuperAdmin:s,nationalViewOverride:a,canManageRoles:l}),r=null==i?void 0:i.data;r&&String(r.id)===String(null==k?void 0:k.id)&&O({...k,...r},I,U),b(null)}catch(i){A((null==i?void 0:i.message)||"Unable to update user access.")}}})]})}export{U 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.