1import{r as e,j as s}from"./vendor-react-CcOkrrXR.js";import{a as t,V as a,ac as r,j as l,L as o,X as n,i}from"./index-DBwMo6Yj.js";import{S as d,g as c,s as m}from"./subadminPermissions-D9VsHX7m.js";import{B as x}from"./Button-CoTkasZ0.js";import{I as u}from"./Input-BSJjP1PU.js";import{D as p,d as g,a as b,b as h,c as y,e as j}from"./directoryChrome-dfA8AEPX.js";import{C as f}from"./circle-check-big-U6CKV3Cc.js";import{C as v}from"./circle-alert-4GbIc0N7.js";import{U as w}from"./user-plus-DY0b5f9H.js";import{C as N}from"./crown-Dh0_14Hg.js";import{K as k}from"./key-round-DboxJSws.js";import{T as C}from"./trash-2-tKWDk2Gs.js";import{E as S}from"./eye-off-jjeAMqsV.js";import{E as z}from"./eye-qJHTCboA.js";import"./vendor-query-O7qEwtyB.js";import"./vendor-axios-CZ8oOnp1.js";import"./vendor-router-ByYPGhRc.js";import"./vendor-i18n-yn_Olgdh.js";import"./chevron-left-CtPHafRD.js";const P=({user:a,onClose:r,onSuccess:l})=>{const[i,d]=e.useState({email:a?.email||"",newPassword:""}),[c,m]=e.useState(!1),[x,u]=e.useState(!1),[p,g]=e.useState("");return s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)"},onClick:r,children:s.jsxs("div",{className:"rounded-xl w-full max-w-md
1shadow-2xl overflow-hidden",style:{background:"var(--tg-modal-bg)",border:"1px solid var(--tg-border)"},onClick:e=>e.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-5",style:{background:"#f97316"},children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{background:"rgba(255,255,255,0.2)"},children:s.jsx(k,{size:18,className:"text-white"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-bold text-white text-base",children:"Reset Sub-Admin Password"}),s.jsx("p",{className:"text-xs",style:{color:"rgba(255,255,255,0.8)"},children:"Set a new password by email"})]})]}),s.jsx("button",{type:"button",onClick:r,className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:"rgba(255,255,255,0.2)"},children:s.jsx(n,{size:15,className:"text-white"})})]}),s.jsxs("form",{onSubmit:async e=>{if(e.preventDefault(),i.newPassword.length<6)g("Password must be at least 6 characters");else{u(!0),g("");try{const{data:e}=await t.patch("/admin/subadmins/reset-password",{email:i.email,newPassword:i.newPassword});l(e.message||"Password updated successfully"),r()}catch(s){g(s.response?.data?.message||"Failed to reset password")}u(!1)}},className:"p-6 space-y-4",children:[p&&s.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 rounded-lg text-sm",style:{background:"rgba(239,68,68,0.1)",border:"1px solid rgba(239,68,68,0.25)",color:"#f87171"},children:[s.jsx(v,{size:15})," ",p]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"text-xs font-bold uppercase tracking-wider",style:{color:"var(--tg-text-muted)"},children:"Account Email"}),s.jsx("input",{type:"email",value:i.email,onChange:e=>d(s=>({...s,email:e.target.value})),required:!0,placeholder:"[email protected]",className:"w-full px-4 py-3 text-sm rounded-lg outline-none",style:{background:"var(--tg-input-bg)",border:"1px solid var(--tg-input-border)",color:"var(--tg-text-head)"}}),s.jsx("p",{className:"text-[10px]",style:{color:"var(--tg-text-muted)"},children:"Pre-filled from the selected row. Edit if needed."})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"text-xs font-bold uppercase tracking-wider",style:{color:"var(--tg-text-muted)"},children:"New Password *"}),s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:c?"text":"password",value:i.newPassword,onChange:e=>d(s=>({...s,newPassword:e.target.value})),required:!0,placeholder:"Minimum 6 characters",className:"w-full px-4 py-3 pr-12 text-sm rounded-lg outline-none",style:{background:"var(--tg-input-bg)",border:"1px solid var(--tg-input-border)",color:"var(--tg-text-head)"}}),s.jsx("button",{type:"button",onClick:()=>m(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2",style:{color:"var(--tg-text-muted)"},children:c?s.jsx(S,{size:16}):s.jsx(z,{size:16})})]})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx("button",{type:"button",onClick:r,className:"flex-1 py-3 rounded-lg text-sm font-bold",style:{border:"1px solid var(--tg-border)",color:"var(--tg-text-muted)"},children:"Cancel"}),s.jsxs("button",{type:"submit",disabled:x,className:"flex-1 py-3 rounded-lg text-sm font-bold text-white flex items-center justify-center gap-2 disabled:opacity-50",style:{background:"#f97316"},children:[x?s.jsx(o,{size:14,className:"animate-spin"}):s.jsx(k,{size:14}),"Update Password"]})]})]})]})})},E=({onClose:a,onCreated:r})=>{const[l,d]=e.useState({name:"",email:"",password:"",mappedEmail:""}),[c,m]=e.useState(!1),[x,u]=e.useState(!1),[p,g]=e.useState("");return s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",style:{background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)"},onClick:a,children:s.jsxs("div",{className:"rounded-xl w-full max-w-md
1shadow-2xl overflow-hidden",style:{background:"var(--tg-modal-bg)",border:"1px solid var(--tg-border)"},onClick:e=>e.stopPropagation(),children:[s.jsxs("div",{className:"flex items-center justify-between px-6 py-5",style:{background:"#f97316"},children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center",style:{background:"rgba(255,255,255,0.2)"},children:s.jsx(w,{size:18,className:"text-white"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-bold text-white text-base",children:"Create Sub-Admin"}),s.jsx("p",{className:"text-xs",style:{color:"rgba(255,255,255,0.8)"},children:"Question bank & tutorial access"})]})]}),s.jsx("button",{type:"button",onClick:a,className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:"rgba(255,255,255,0.2)"},children:s.jsx(n,{size:15,className:"text-white"})})]}),s.jsxs("form",{onSubmit:async e=>{e.preventDefault(),u(!0),g("");try{await t.post("/admin/subadmins",l),r(),a()}catch(s){g(s.response?.data?.message||"Failed to create account")}u(!1)},className:"p-6 space-y-4",children:[p&&s.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 rounded-lg text-sm",style:{background:"rgba(239,68,68,0.1)",border:"1px solid rgba(239,68,68,0.25)",color:"#f87171"},children:[s.jsx(v,{size:15})," ",p]}),[{key:"name",label:"Full Name *",type:"text",placeholder:"e.g. Priya Sharma"},{key:"email",label:"Login Email *",type:"email",placeholder:"[email protected]"}].map(({key:e,label:t,type:a,placeholder:r})=>s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"text-xs font-bold uppercase tracking-wider",style:{color:"var(--tg-text-muted)"},children:t}),s.jsx("input",{type:a,value:l[e],onChange:s=>d(t=>({...t,[e]:s.target.value})),required:!0,placeholder:r,className:"w-full px-4 py-3 text-sm rounded-lg outline-none",style:{background:"var(--tg-input-bg)",border:"1px solid var(--tg-input-border)",color:"var(--tg-text-head)"}})]},e)),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"text-xs font-bold uppercase tracking-wider",style:{color:"var(--tg-text-muted)"},children:"Password *"}),s.jsxs("div",{className:"relative",children:[s.jsx("input",{type:c?"text":"password",value:l.password,onChange:e=>d(s=>({...s,password:e.target.value})),required:!0,placeholder:"Minimum 6 characters",className:"w-full px-4 py-3 pr-12 text-sm rounded-lg outline-none",style:{background:"var(--tg-input-bg)",border:"1px solid var(--tg-input-border)",color:"var(--tg-text-head)"}}),s.jsx("button",{type:"button",onClick:()=>m(e=>!e),className:"absolute right-3 top-1/2 -translate-y-1/2",style:{color:"var(--tg-text-muted)"},children:c?s.jsx(S,{size:16}):s.jsx(z,{size:16})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("label",{className:"text-xs font-bold uppercase tracking-wider flex items-center gap-1",style:{color:"var(--tg-text-muted)"},children:[s.jsx(i,{size:11})," Mapped Email ",s.jsx("span",{className:"normal-case font-normal text-[10px]",children:"(optional)"})]}),s.jsx("input",{type:"email",value:l.mappedEmail,onChange:e=>d(s=>({...s,mappedEmail:e.target.value})),placeholder:"Where credentials are emailed",className:"w-full px-4 py-3 text-sm rounded-lg outline-none",style:{background:"var(--tg-input-bg)",border:"1px solid var(--tg-input-border)",color:"var(--tg-text-head)"}})]}),s.jsxs("div",{className:"flex gap-3 pt-2",children:[s.jsx("button",{type:"button",onClick:a,className:"flex-1 py-3 rounded-lg text-sm font-bold",style:{border:"1px solid var(--tg-border)",color:"var(--tg-text-muted)"},children:"Cancel"}),s.jsxs("button",{type:"submit",disabled:x,className:"flex-1 py-3 rounded-lg text-sm font-bold text-white flex items-center justify-center gap-2 disabled:opacity-50",style:{background:"#f97316"},children:[x?s.jsx(o,{size:14,className:"animate-spin"}):s.jsx(w,{size:14}),"Create"]})]})]})]})})},T=({userId:a,permKey:r,label:l,icon:n,currentValue:i,onToggled:d,onError:c})=>{const[m,x]=e.useState(!1);return s.jsx("button",{type:"button",onClick:async()=>
1{if(m)return;x(!0);const e=!i;try{await t.patch(`/admin/subadmins/${a}/permissions`,{[r]:e}),d(a,r,e)}catch(s){c(s.response?.data?.message||"Failed to update permission")}x(!1)},disabled:m,title:`${i?"Revoke":"Grant"} "${l}" permission`,className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all disabled:opacity-50",style:{background:i?"rgba(16,185,129,0.12)":"rgba(100,116,139,0.1)",border:i?"1px solid rgba(16,185,129,0.35)":"1px solid var(--tg-border)",color:i?"#10b981":"var(--tg-text-muted)",minWidth:150},children:m?s.jsx(o,{size:12,className:"animate-spin flex-shrink-0"}):s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"relative inline-block flex-shrink-0",style:{width:28,height:16},children:[s.jsx("span",{style:{display:"block",width:"100%",height:"100%",borderRadius:9999,background:i?"#10b981":"rgba(100,116,139,0.3)",transition:"background 0.2s"}}),s.jsx("span",{style:{position:"absolute",top:2,left:i?14:2,width:12,height:12,borderRadius:"50%",background:"#fff",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.25)"}})]}),n&&s.jsx(n,{size:12,className:"flex-shrink-0"}),s.jsx("span",{className:"truncate",children:l})]})})};function A(){const[n,i]=e.useState([]),[S,z]=e.useState(!0),[A,F]=e.useState(!1),[R,D]=e.useState(null),[L,$]=e.useState(""),[M,q]=e.useState(null),_=(e,s="success")=>{q({msg:e,type:s}),setTimeout(()=>q(null),3500)},I=e.useCallback(async()=>{z(!0);try{const{data:e}=await t.get("/admin/subadmins");i(e||[])}catch{_("Failed to load sub-admins","error")}z(!1)},[]);e.useEffect(()=>{I()},[I]);const K=(e,s,t)=>{i(a=>a.map(a=>a._id===e?{...a,subadminPermissions:m(a.subadminPermissions,s,t)}:a)),_(`Permission ${t?"granted":"revoked"} successfully`)},U=n.filter(e=>!L||e.name?.toLowerCase().includes(L.toLowerCase())||e.email?.includes(L.toLowerCase()));return s.jsxs("div",{className:"space-y-6 max-w-[1600px]",children:[M&&s.jsxs("div",{className:"fixed top-4 right-4 z-50 flex items-center gap-2 px-4 py-3 rounded-lg text-sm font-semibold shadow-lg",style:{background:"error"===M.type?"var(--tg-error-bg)":"var(--tg-success-bg)",color:"error"===M.type?"var(--tg-error-text)":"var(--tg-success-text)",border:"1px solid var(--tg-border)"},children:["success"===M.type?s.jsx(f,{size:15}):s.jsx(v,{size:15}),M.msg]}),s.jsx(p,{title:"Sub-Admin Directory",countLabel:`${n.length} Total Sub-Admins`,subtitle:"Manage sub-admins and control which features they can access.",actions:s.jsxs(s.Fragment,{children:[s.jsx(x,{variant:"secondary",icon:s.jsx(a,{size:16}),onClick:I,style:{borderRadius:8,padding:"7px 10px"},"aria-label":"Refresh sub-admin directory"}),s.jsx(x,{variant:"primary",icon:s.jsx(w,{size:16}),onClick:()=>F(!0),style:{borderRadius:8},children:"Create Sub-Admin"})]})}),s.jsxs("div",{className:"overflow-hidden border shadow-sm",style:g,children:[s.jsxs("div",{className:"p-4 sm:p-5 space-y-4 border-b",style:{borderColor:"var(--tg-border)"},children:[s.jsx("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:s.jsx("div",{className:"relative flex-1 max-w-lg",children:s.jsx(u,{type:"text",icon:s.jsx(r,{size:16}),placeholder:"Search by name or email...",value:L,onChange:e=>$(e.target.value),style:{borderRadius:8,background:"color-mix(in srgb, var(--tg-surface) 70%, transparent)"}})})}),s.jsxs("div",{className:"flex items-start gap-3 px-3 py-2 rounded-lg border text-xs",style:{background:"color-mix(in srgb, var(--tg-accent-soft) 70%, transparent)",borderColor:"color-mix(in srgb, var(--tg-accent-border) 70%, transparent)",color:"var(--tg-text-muted)"},children:[s.jsx(l,{size:14,className:"flex-shrink-0 mt-0.5",style:{color:"var(--tg-accent-2, #f97316)"}}),s.jsxs("span",{children:["Use the ",s.jsx("strong",{style:{color:"var(--tg-text-head)"},children:"Feature Access"})," toggles below to grant or revoke extra dashboard features for each sub-admin. Changes take effect ",s.jsx("strong",{style:{color:"var(--tg-text-head)"},children:"immediately"})," \u2014 sub-admins will see the new tab next time they open or refresh their dashboard."]})]})]}),S?s.jsx("div",{className:"flex justify-center py-16",children:s.jsx(o,{className:"animate-spin",size:28,style:{color:"var(--tg-accent)"}})}):0===U.length?s.jsx("div",{className:"text-center py-16",style:{color:"var(--tg-text-muted)"},children:s.jsx("p",{children:"No sub-admin accounts yet."})}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full text-left border-collapse min-w-[960px]",children:[s.jsx("thead",{children:s.jsxs("tr",{className:"text-[11px] font-bold uppercase tracking-wider border-b",style:b,children:[s.jsx("th",{className:"py-3.5 pl-5 pr-3",children:"Account"}),s.jsx("th",{className:"py-3.5 px-3",children:"Created"}),s.jsx("th",{className:"py-3.5 px-3",children:"Feature Access"}),s.jsx("th",{className:"py-3.5 pl-3 pr-5 text-right",children:"Actions"})]})}),s.jsx("tbody",{children:U.map(e=>s.jsxs("tr",{className:y,style:h,children:[s.jsx("td",{className:"py-4 pl-5 pr-3",children:s.jsx(j,{name:e.name,email:e.email,seed:e._id||e.email||e.name})}),s.jsx("td",{className:"py-4 px-3 text-xs font-medium whitespace-nowrap",style:{color:"var(--tg-text-muted)"},children:new Date(e.createdAt).toLocaleDateString()}),s.jsx("td",{className:"py-4 px-3",children:s.jsx("div",{className:"flex flex-wrap items-center gap-2 max-w-[520px]",children:d.map(t=>s.jsx(T,{userId:e._id,permKey:t.key,label:t.label,icon:"Premium Courses"===t.group?N:l,currentValue:c(e.subadminPermissions,t.key),onToggled:K,onError:e=>_(e,"error")},t.key))})}),s.jsx("td",{className:"py-4 pl-3 pr-5 text-right",children:s.jsxs("div",{className:"inline-flex items-center justify-end gap-1",children:[s.jsx("button",{type:"button",onClick:()=>D(e),title:"Reset Password",className:"p-1.5 rounded-lg transition",style:{color:"var(--tg-text-muted)"},"aria-label":`Reset password for ${e.name||e.email||"sub-admin"}`,onMouseEnter:e=>{e.currentTarget.style.color="#f97316",e.currentTarget.style.background="rgba(249,115,22,0.1)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--tg-text-muted)",e.currentTarget.style.background="none"},children:s.jsx(k,{size:16})}),s.jsx("button",{type:"button",onClick:()=>(async e=>{if(confirm("Remove this sub-admin account?"))try{await t.delete(`/admin/subadmins/${e}
1`),_("Sub-admin removed"),I()}catch(s){_(s.response?.data?.message||"Delete failed","error")}})(e._id),title:"Delete Account",className:"p-1.5 rounded-lg transition",style:{color:"var(--tg-text-muted)"},"aria-label":`Delete ${e.name||e.email||"sub-admin"}`,onMouseEnter:e=>{e.currentTarget.style.color="var(--tg-error-text)",e.currentTarget.style.background="var(--tg-error-bg)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--tg-text-muted)",e.currentTarget.style.background="transparent"},children:s.jsx(C,{size:16})})]})})]},e._id))})]})})]}),A&&s.jsx(E,{onClose:()=>F(!1),onCreated:()=>{_("Sub-admin created"),I()}}),R&&s.jsx(P,{user:R,onClose:()=>D(null),onSuccess:e=>_(e)})]})}export{A 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.