1import{u as I,r as l,j as e,c as N}from"./index-Bv3Bofm-.js";import{D as C,a as S,b as _,c as D,e as L}from"./dialog-4CO45iY9.js";import{u as v}from"./useTranslation-DVry60RK.js";import{S as T}from"./shield-check-Dn3v70M3.js";import{P as E}from"./plus-DHZwBb2L.js";import{T as y}from"./triangle-alert-QteJ9e4A.js";import{L as w}from"./loader-circle-DI5IRqPf.js";import{M}from"./mail-Coyw6sOM.js";import{c as P}from"./createLucideIcon-CWJ9Sf_H.js";import{T as V}from"./trash-2-CGRsUgki.js";import"./index-7sSK0Fxm.js";import"./index-Dc_FVRD7.js";import"./index-B0S7T6Iq.js";import"./index-D__OmZ0k.js";import"./index-FW9E5kpD.js";import"./Combination-bWOQ-6ny.js";import"./index-DiiLNpaU.js";import"./index-DUG1lxBv.js";import"./utils-CBfrqCZ4.js";import"./x-CPPa5Rss.js";const $=[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]],H=P("mail-check",$);const q=[["path",{d:"M22 10.5V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h12.5",key:"e61zoh"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"M18 15.28c.2-.4.5-.8.9-1a2.1 2.1 0 0 1 2.6.4c.3.4.5.8.5 1.3 0 1.3-2 2-2 2",key:"7z9rxb"}],["path",{d:"M20 22v.01",key:"12bgn6"}]],F=P("mail-question-mark",q),f="w-full px-3 py-2 border border-slate-200 dark:border-slate-800 rounded-md bg-white text-[13px] text-slate-900 placeholder:text-slate-400 outline-none focus:border-slate-400",j="admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase";function O(t){if(!t)return"â";try{return new Date(t).toLocaleDateString()}catch{return t}}function U(t){if(!t)return"â";try{return new Date(t).toLocaleString()}catch{return t}}function A(t){const n=t?.response?.data?.detail;return typeof n=="string"?n:n&&typeof n=="object"?n.message||JSON.stringify(n):t?.message||"Unknown error"}function me(){const{t}=v(),{user:n}=I(),[s,i]=l.useState([]),[h,o]=l.useState(!0),[m,c]=l.useState(""),[g,d]=l.useState(!1),[u,b]=l.useState(null);async function r(){o(!0),c("");try{const a=await N.get("/admin/administrators");i(Array.isArray(a.data)?a.data:[])}catch(a){c(A(a))}finally{o(!1)}}l.useEffect(()=>{r()},[]);
1async function p(a){if(a.id!==n?.id&&!(s.length<=1)&&window.confirm(t("portalI18n.adminAdministratorsPage.deleteAdminConfirm",{username:a.username,email:a.email}))){b(`delete-${a.id}`);try{await N.delete(`/admin/administrators/${a.id}`),await r()}catch(x){alert(t("portalI18n.adminAdministratorsPage.deleteFailed",{error:A(x)}))}finally{b(null)}}}return e.jsxs("div",{className:"px-7 py-6 space-y-5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-[22px] font-extrabold tracking-tight text-slate-900 inline-flex items-center gap-2",children:[e.jsx(T,{className:"w-5 h-5 text-primary"}),t("portalI18n.adminAdministratorsPage.pageTitle")]}),e.jsx("p",{className:"text-[13px] text-slate-500 mt-1",children:t("portalI18n.adminAdministratorsPage.pageDescription")})]}),e.jsxs("button",{type:"button",onClick:()=>d(!0),className:"px-3 py-1.5 border border-slate-200 dark:border-slate-800 rounded-md bg-slate-900 text-white text-[12px] hover:bg-slate-800 inline-flex items-center gap-1.5",children:[e.jsx(E,{className:"w-3.5 h-3.5"}),t("portalI18n.adminAdministratorsPage.addAdministrator")]})]}),m&&e.jsxs("div",{className:"px-4 py-3 border border-rose-200 bg-rose-50 text-[12px] text-rose-700 rounded-md inline-flex items-center gap-2",children:[e.jsx(y,{className:"w-4 h-4"}),m]}),e.jsxs("div",{className:"border border-slate-200 dark:border-slate-800 rounded-lg overflow-hidden bg-white shadow-sm transition-shadow duration-200 hover:shadow-md",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-5 py-3 border-b border-slate-200 dark:border-slate-800 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-slate-900",children:t("portalI18n.adminAdministratorsPage.activeAdmins")}),e.jsx("span",{className:"admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase px-1.5 py-0.5 bg-white border border-slate-200 dark:border-slate-800 rounded-sm",children:s.length})]}),s.length<=1&&e.jsxs("span",{className:"text-[11.5px] text-[hsl(var(--admin-amber))] inline-flex items-center gap-1.5",title:t("portalI18n.adminAdministratorsPage.lastAdminBlockTooltip"),children:[e.jsx(y,{className:"w-3.5 h-3.5"}),t("portalI18n.adminAdministratorsPage.singleAdminWarning")]})]}),e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-slate-200 dark:border-slate-800 bg-slate-50 text-left",children:[e.jsx("th",{className:"admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase px-4 py-2.5",children:t("portalI18n.adminAdministratorsPage.colAccount")}),e.jsx("th",{className:"admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase px-4 py-2.5",children:t("portalI18n.adminAdministratorsPage.colEmailStatus")}),e.jsx("th",{className:"admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase px-4 py-2.5",children:t("portalI18n.adminAdministratorsPage.colCreated")}),e.jsx("th",{className:"admin-mono text-[10.5px] tracking-widest text-slate-500 uppercase px-4 py-2.5",children:t("portalI18n.adminAdministratorsPage.colLastLogin")}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsxs("tbody",{children:[h&&s.length===0&&e.jsx("tr",{children:e.jsxs("td",{colSpan:5,className:"px-4 py-10 text-center text-slate-500",children:[e.jsx(w,{className:"w-4 h-4 inline mr-2 animate-spin"}),t("portalI18n.adminAdministratorsPage.loadingAdministrators")]})}),!h&&s.length===0&&!m&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-10 text-center text-slate-500",children:t("portalI18n.adminAdministratorsPage.noAdministrators")})}),s.map(a=>{const x=a.id===n?.id,k=x||s.length<=1;return e.jsxs("tr",{className:"border-t border-slate-100 dark:border-slate-800 hover:bg-slate-50",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium text-slate-900",children:["@",a.username]}),x&&e.jsx("span",{className:"admin-mono text-[10.5px] font-semibold uppercase px-1.5 py-0.5 rounded-sm bg-[hsl(var(--admin-teal-soft))] text-primary",children:t("portalI18n.adminAdministratorsPage.badgeYou")})]}),e.jsxs("div",{className:"text-[11.5px] text-slate-500 mt-0.5 inline-flex items-center gap-1",children:[e.jsx(M,{className:"w-3 h-3"}),a.email]})]}),e.jsx("td",{className:"px-4 py-3",children:a.is_verified?e.jsxs("span",{className:"admin-mono text-[10.5px] font-semibold uppercase px-1.5 py-0.5 rounded-sm bg-emerald-50 text-emerald-700 inline-flex items-center gap-1",children:[e.jsx(H,{className:"w-3 h-3"}),t("portalI18n.adminAdministratorsPage.statusVerified")]}):e.jsxs("span",{className:"admin-mono text-[10.5px] font-semibold uppercase px-1.5 py-0.5 rounded-sm bg-[hsl(var(--admin-amber-bg))] text-[hsl(var(--admin-amber))] inline-flex items-center gap-1",children:[e.jsx(F,{className:"w-3 h-3"}),t("portalI18n.adminAdministratorsPage.statusPending")]})}),e.jsx("td",{className:"px-4 py-3 admin-mono text-[12px] text-slate-600",children:O(a.created_at)}),e.jsx("td",{className:"px-4 py-3 admin-mono text-[12px] text-slate-600",children:a.last_login_at?U(a.last_login_at):e.jsx("span",{className:"text-slate-400 italic",children:t("portalI18n.adminAdministratorsPage.lastLoginNever")})}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{type:"button",onClick:()=>p(a),disabled:k||u===`delete-${a.id}`,className:"p-1.5 rounded-md text-slate-500 hover:bg-rose-50 hover:text-rose-700 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-slate-500",title:x?t("portalI18n.adminAdministratorsPage.cantDeleteSelfTooltip"):s.length<=1?t("portalI18n.adminAdministratorsPage.atLeastOneAdminTooltip"):t("portalI18n.adminAdministratorsPage.deleteAdministratorTooltip"),children:u===`delete-${a.id}`?e.jsx(w,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(V,{className:"w-3.5 h-3.5"})})})]},a.id)})]})]})]}),g&&e.jsx(z,{onClose:()=>d(!1),onCreated:async()=>{d(!1),await r()}})]})}function z({onClose:t,onCreated:n}){const{t:s}=v(),[i,h]=l.useState({email:"",username:"",password:"",send_verification_email:!0}),[o,m]=l.useState(!1),[c,g]=l.useState("");function d(r,p){h(a=>({...a,[r]:p}))}const u=i.email.trim().includes("@")&&i.username.trim().length>=3&&i.password.length>=8;async function b(r){r.preventDefault(),m(!0),g("");try{await N.post("/admin/administrators",{email:i.email.trim(),username:i.username.trim(),password:i.password,send_verification_email:i.send_verification_email}),n()}catch(p){g(A(p))}finally{m(!1)}}return e.jsx(C,{open:!0,onOpenChange:r=>!r&&t(),children:e.jsx(S,{className:"sm:max-w-md","data-admin-shell":!0,children:e.jsxs("form",{onSubmit:b,children:[e.jsxs(_,{children:[e.jsx(D,{className:"text-[16px] font-semibold text-slate-900",children:s("portalI18n.adminAdministratorsPage.dialogTitle")}),e.jsx("p",{className:"text-[12px] text-slate-500 mt-1",children:s("portalI18n.adminAdministratorsPage.dialogDescription")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[c&&e.jsxs("div",{className:"px-3 py-2 border border-rose-200 bg-rose-50 text-[12px] text-rose-700 rounded-md inline-flex items-center gap-2",children:[e.jsx(y,{className:"w-4 h-4"}),c]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:j,children:s("portalI18n.adminAdministratorsPage.labelEmail")}),e.jsx("input",{className:f,type:"email",required:!0,value:i.email,onChange:r=>d("email",r.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:j,children:s("portalI18n.adminAdministratorsPage.labelUsername")}),e.jsx("input",{className:`${f} admin-mono`,required:!0,minLength:3,value:i.username,onChange:r=>d("username",r.target.value),placeholder:"opsadmin"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:j,children:s("portalI18n.adminAdministratorsPage.labelInitialPassword")}),e.jsx("input",{className:f,type:"password",required:!0,minLength:8,value:i.password,onChange:r=>d("password",r.target.value),placeholder:s("portalI18n.adminAdministratorsPage.passwordPlaceholder")}),e.jsx("p",{className:"text-[11.5px] text-slate-500",children:s("portalI18n.adminAdministratorsPage.passwordComplexityHint")})]}),e.jsxs("label",{className:"flex items-start gap-2 text-[13px] curs
1or-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.send_verification_email,onChange:r=>d("send_verification_email",r.target.checked),className:"mt-0.5"}),e.jsxs("span",{className:"text-slate-700",children:[s("portalI18n.adminAdministratorsPage.sendVerificationEmail"),e.jsx("span",{className:"block text-[11.5px] text-slate-500 mt-0.5",children:s("portalI18n.adminAdministratorsPage.sendVerificationEmailHint")})]})]})]}),e.jsxs(L,{className:"gap-2",children:[e.jsx("button",{type:"button",onClick:t,disabled:o,className:"px-3 py-1.5 border border-slate-200 dark:border-slate-800 rounded-md bg-white text-[12px] text-slate-700 hover:bg-slate-50 disabled:opacity-50",children:s("portalI18n.adminAdministratorsPage.cancel")}),e.jsxs("button",{type:"submit",disabled:o||!u,className:"px-3 py-1.5 border border-slate-200 dark:border-slate-800 rounded-md bg-slate-900 text-white text-[12px] hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center gap-1.5",children:[o&&e.jsx(w,{className:"w-3.5 h-3.5 animate-spin"}),s("portalI18n.adminAdministratorsPage.createAdministrator")]})]})]})})})}export{me 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.