1import{c as L,r as c,j as e,l as i,i as B,s as P,au as o,aw as F,V as $,ax as I,av as x,I as K,B as C,W as V,M as q,e as M,as as z}from"./index-BRZCj0Re.js";import{B as h}from"./badge-B1bsGkMV.js";import{T as U,a as W,b as R,c as _}from"./tabs-DCPd9NRa.js";import{A as X}from"./arrow-left-CZ27GFxq.js";import{D as G}from"./dollar-sign-CmGrrqa9.js";import{C as J}from"./clock-DzJjljJM.js";import{C as O}from"./circle-x-LcgdhcY4.js";import{f as b}from"./format-QYTbuQ-l.js";import"./index-B6EJG7xU.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Q=L("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]),N=c.forwardRef(({className:s,...t},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:i("w-full caption-bottom text-sm",s),...t})}));N.displayName="Table";const g=c.forwardRef(({className:s,...t},r)=>e.jsx("thead",{ref:r,className:i("[&_tr]:border-b",s),...t}));g.displayName="TableHeader";const y=c.forwardRef(({className:s,...t},r)=>e.jsx("tbody",{ref:r,className:i("[&_tr:last-child]:border-0",s),...t}));y.displayName="TableBody";const Y=c.forwardRef(({className:s,...t},r)=>e.jsx("tfoot",{ref:r,className:i("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...t}));Y.displayName="TableFooter";const m=c.forwardRef(({className:s,...t},r)=>e.jsx("tr",{ref:r,className:i("border-b transition-colors data-[state=selected]:bg-muted hover:bg-muted/50",s),...t}));m.displayName="TableRow";const n=c.forwardRef(({className:s,...t},r)=>e.jsx("th",{ref:r,className:i("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s),...t}));n.displayName="TableHead";const l=c.forwardRef(({className:s,...t},r)=>e.jsx("td",{ref:r,className:i("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...t}));l.displayName="TableCell";const Z=c.forwardRef(({className:s,...t},r)=>e.jsx("caption",{ref:r,className:i("mt-4 text-sm text-muted-foreground",s),...t}));Z.displayName="TableCaption";function ee({status:s}){switch(s){case"sent":return e.jsxs(h,{className:"bg-emerald-500/15 text-emerald-600 border-emerald-500/30",children:[e.jsx(z,{className:"w-3 h-3 mr-1"}),"Sent"]});case"dlq":case"failed":return e.jsxs(h,{variant:"destructive",className:"bg-red-500/15 text-red-600 border-red-500/30",children:[e.jsx(O,{className:"w-3 h-3 mr-1"}),"Failed"]});case"pending":return e.jsxs(h,{className:"bg-amber-500/15 text-amber-600 border-amber-500/30",children:[e.jsx(J,{className:"w-3 h-3 mr-1"}),"Pending"]});case"suppressed":return e.jsxs(h,{className:"bg-muted text-muted-foreground",children:[e.jsx(M,{className:"w-3 h-3 mr-1"}),"Suppressed"]});default:return e.jsx(h,{variant:"outline",children:s})}}function S(s){const[t,r]=s.split("@");return r?`${t.slice(0,2)}${"â¢".repeat(Math.max(t.length-2,2))}@${r}`:s}function oe(){const[s,t]=c.useState(""),[r,D]=c.useState(!1),[w,v]=c.useState(!1),[E,H]=c.useState(null),{toast:T}=B(),A=c.useCallback(async a=>{v(!0);try{const{data:d,error:u}=await P.functions.invoke("admin-reports",{body:{pin:a}});if(u)throw u;if(d.error)throw new Error(d.error);H(d),D(!0)}catch(d){T({variant:"destructive",title:"Access denied",description:d.message})}finally{v(!1)}},[T]),k=()=>{s.trim()&&A(s)};if(!r)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsxs(o,{className:"w-full max-w-sm",children:[e.jsxs(F,{className:"text-center",children:[e.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center mb-2",children:e.jsx($,{className:"w-5 h-5 text-primary"})}),e.jsx(I,{className:"text-lg",children:"Report Admin"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enter admin PIN to view report data"})]}),e.jsxs(x,{className:"space-y-3",children:[e.jsx(K,{type:"password",placeholder:"Admin PIN",value:s,onChange:a=>t(a.target.value),onKeyDown:a=>a.key==="Enter"&&k()}),e.jsx(C,{className:"w-full",onClick:k,disabled:w,children:w?"Verifyingâ¦":"Unlock"})]})]})});const{tokens:j,emails:f,stats:p}=E;return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border/50 bg-background/80 backdrop-blur-sm sticky top-0 z-10",children:e.jsxs("div",{className:"container max-w-7xl mx-auto px-4 py-3 flex items-center gap-3",children:[e.jsx(V,{to:"/analytics",children:e.jsx(C,{variant:"ghost",size:"icon",children:e.jsx(X,{className:"w-4 h-4"})})}),e.jsx("h1",{className:"text-lg font-bold text-foreground",children:"Report Purchases & Delivery"})]})}),e.jsxs("main",{className:"container max-w-7xl mx-auto px-4 py-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(o,{children:e.jsxs(x,{className:"pt-4 pb-3 px-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(G,{className:"w-3.5 h-3.5"}),"Revenue"]}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:["$",(p.totalRevenue/100).toFixed(0)]})]})}),e.jsx(o,{children:e.jsxs(x,{className:"pt-4 pb-3 px-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),"Purchases"]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:p.totalPurchases})]})}),e.jsx(o,{children:e.jsxs(x,{className:"pt-4 pb-3 px-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Emails Sent"]}),e.jsx("p",{className:"text-2xl font-bold text-emerald-600",children:p.emailsSent})]})}),e.jsx(o,{children:e.jsxs(x,{className:"pt-4 pb-3 px-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(M,{className:"w-3.5 h-3.5"}),"Emails Failed"]}),e.jsx("p",{className:"text-2xl font-bold text-red-500",children:p.emailsFailed})]})})]}),e.jsxs(U,{defaultValue:"purchases",className:"space-y-4",children:[e.jsxs(W,{children:[e.jsxs(R,{value:"purchases",children:["Purchases (",j.length,")"]}),e.jsxs(R,{value:"emails",children:["Email Log (",f.length,")"]})]}),e.jsx(_,{value:"purchases",children:e.jsx(o,{children:e.jsx(x,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(N,{children:[e.jsx(g,{children:e.jsxs(m,{children:[e.jsx(n,{children:"Date"}),e.jsx(n,{children:"Email"}),e.jsx(n,{children:"Report"}),e.jsx(n,{children:"Amount"}),e.jsx(n,{children:"Token"}),e.jsx(n,{children:"Last Access"})]})}),e.jsx(y,{children:j.length===0?e.jsx(m,{children:e.jsx(l,{colSpan:6,className:"text-center text-muted-foreground py-8",children:"No purchases yet"})}):j.map(a=>{var d,u;return e.jsxs(m,{children:[e.jsx(l,{className:"text-xs whitespace-nowrap",children:b(new Date(a.created_at),"MMM d, yyyy HH:mm")}
6),e.jsx(l,{className:"font-mono text-xs",children:S(a.recipient_email)}),e.jsx(l,{className:"text-xs",children:a.report_title}),e.jsx(l,{className:"font-mono text-xs",children:a.payment_amount_cents?`$${(a.payment_amount_cents/100).toFixed(2)} ${(d=a.currency)==null?void 0:d.toUpperCase()}`:"â"}),e.jsxs(l,{className:"font-mono text-xs text-muted-foreground",children:[(u=a.token)==null?void 0:u.slice(0,12),"â¦"]}),e.jsx(l,{className:"text-xs text-muted-foreground",children:a.last_accessed_at?b(new Date(a.last_accessed_at),"MMM d HH:mm"):"Never"})]},a.id)})})]})})})})}),e.jsx(_,{value:"emails",children:e.jsx(o,{children:e.jsx(x,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(N,{children:[e.jsx(g,{children:e.jsxs(m,{children:[e.jsx(n,{children:"Date"}),e.jsx(n,{children:"Template"}),e.jsx(n,{children:"Recipient"}),e.jsx(n,{children:"Status"}),e.jsx(n,{children:"Error"})]})}),e.jsx(y,{children:f.length===0?e.jsx(m,{children:e.jsx(l,{colSpan:5,className:"text-center text-muted-foreground py-8",children:"No report emails sent yet"})}):f.map(a=>e.jsxs(m,{children:[e.jsx(l,{className:"text-xs whitespace-nowrap",children:b(new Date(a.created_at),"MMM d, yyyy HH:mm")}),e.jsx(l,{children:e.jsx(h,{variant:"outline",className:"text-xs",children:a.template_name})}),e.jsx(l,{className:"font-mono text-xs",children:S(a.recipient_email)}),e.jsx(l,{children:e.jsx(ee,{status:a.status})}),e.jsx(l,{className:"text-xs text-red-500 max-w-[200px] truncate",children:a.error_message||"â"})]},a.id))})]})})})})})]})]})]})}export{oe 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.