import{r as o,j as e}from"./sikshya-admin-sikshya-react-E_TY_un4.js";import{c as j,g as x,S as m,a as N}from"./sikshya-admin.js";import{E as v}from"./sikshya-admin-EmbeddableShell-B-jr8i1j.js";import{A as g}from"./sikshya-admin-ApiErrorPanel-2sA2VptM.js";import{L as _}from"./sikshya-admin-ListPanel-vTJNuGbZ.js";import{L as w}from"./sikshya-admin-ListEmptyState-BRNOY4j4.js";import{R as S}from"./sikshya-admin-RowActionsMenu-CZXvJHkw.js";import{a as L}from"./sikshya-admin-buttons-Bym2otdv.js";import{f as R}from"./sikshya-admin-formatPostDate-DY4hP6OT.js";import{u as C}from"./sikshya-admin-useAsyncData-D6Z2fDHQ.js";import{ad as t}from"./sikshya-admin-sikshya-vendor-BVAk_Gwu.js";function q(h){const{config:a,title:p,embedded:f}=h,{confirm:u}=j(),y=a.adminUrl.replace(/\/?$/,"/"),[i]=o.useState(1),k=o.useCallback(async()=>{const s=new URLSearchParams({page:String(i),per_page:"50"});return x().get(`${m.admin.issuedCertificates}?${s.toString()}`)},[i]),{loading:c,data:r,error:d,refetch:l}=C(k,[i]),n=(r==null?void 0:r.certificates)??[],b=async s=>{await u({title:t("Revoke certificate?","sikshya"),message:t("This certificate will no longer verify publicly.","sikshya"),variant:"danger",confirmLabel:t("Revoke","sikshya")})&&(await x().post(m.admin.issuedCertificatesRevoke,{id:s}),l())};return e.jsxs(v,{embedded:f,config:a,title:p,subtitle:t("Learner certificates issued when courses are completed (table-backed records).","sikshya"),pageActions:e.jsx(L,{type:"button",disabled:c,onClick:()=>l(),children:"Refresh"}),children:[d?e.jsx("div",{className:"mb-4",children:e.jsx(g,{error:d,title:t("Could not load certificates","sikshya"),onRetry:()=>l()})}):null,e.jsx(_,{children:c?e.jsx("div",{className:"p-8 text-center text-sm text-slate-500 dark:text-slate-400",children:t("Loading…","sikshya")}):n.length===0?e.jsx(w,{title:t("No issued certificates yet","sikshya"),description:t("When learners complete a course and certificates are enabled, records appear here with verification codes.","sikshya")}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-slate-200 text-sm dark:divide-slate-800",children:[e.jsx("thead",{className:"bg-slate-50/80 text-left text-xs font-semibold uppercase tracking-wide text-slate-500 dark:bg-slate-800/80 dark:text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3.5",children:t("Issued","sikshya")}),e.jsx("th",{className:"px-5 py-3.5",children:t("Learner","sikshya")}),e.jsx("th",{className:"px-5 py-3.5",children:t("Course","sikshya")}),e.jsx("th",{className:"px-5 py-3.5",children:t("Number","sikshya")}),e.jsx("th",{className:"px-5 py-3.5",children:t("Verification","sikshya")}),e.jsx("th",{className:"px-5 py-3.5",children:t("Status","sikshya")}),e.jsx("th",{className:"px-5 py-3.5 text-right",children:t("Actions","sikshya")})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100 dark:divide-slate-800",children:n.map(s=>e.jsxs("tr",{className:"bg-white dark:bg-slate-900",children:[e.jsx("td",{className:"whitespace-nowrap px-5 py-3.5 text-slate-600 dark:text-slate-400",children:R(s.issued_date)}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsxs("a",{href:`${y}user-edit.php?user_id=${s.user_id}`,className:"font-semibold text-brand-600 hover:text-brand-800 dark:text-brand-400",children:["User #",s.user_id]})}),e.jsx("td",{className:"px-5 py-3.5",children:e.jsx("a",{href:N(a,"add-course",{course_id:String(s.course_id)}),className:"font-medium text-brand-600 hover:text-brand-800 dark:text-brand-400",children:`Course #${s.course_id}`})}),e.jsx("td",{className:"px-5 py-3.5 font-mono text-xs text-slate-700 dark:text-slate-300",children:s.certificate_number}),e.jsx("td",{className:"max-w-[220px] px-5 py-3.5",children:s.verify_url?e.jsx("a",{href:s.verify_url,target:"_blank",rel:"noreferrer noopener",className:"break-all font-mono text-xs text-brand-600 hover:underline dark:text-brand-400",title:t("Open public verification URL","sikshya"),children:s.verify_url}):s.verification_code?e.jsx("code",{className:"break-all font-mono text-xs text-slate-600 dark:text-slate-400",children:s.verification_code}):"—"}),e.jsx("td",{className:"px-5 py-3.5 capitalize text-slate-700 dark:text-slate-300",children:s.status}),e.jsx("td",{className:"w-12 px-5 py-3.5 text-right",children:s.status==="active"?e.jsx(S,{items:[{key:"revoke",label:t("Revoke","sikshya"),onClick:()=>b(s.id),danger:!0}],ariaLabel:t("Certificate actions","sikshya")}):e.jsx("span",{className:"text-xs text-slate-400",children:"—"})})]},s.id))})]})})})]})}export{q as IssuedCertificatesPage};
