1import{g as v,u as w,a as _,b as k,r as m,s as u,j as e,L as g,B as x,q as l,V as A,K as B,f as S}from"./index-BcGILXnr.js";import{o as q,D as f}from"./DashboardLayout-CEDXqKEj.js";import{C as j,c as N}from"./card-CXJ0-SW3.js";import{B as D}from"./badge-CgnKKj3C.js";import{S as L}from"./shield-x-CITo5dju.js";import{C as M}from"./check-CG4QLlbY.js";import{R}from"./refresh-cw-DdnBYlak.js";import{C as E}from"./circle-check-big-DtNtMt8b.js";import{C as T}from"./circle-x-DRrRk1-A.js";import"./database-e3mcfmXM.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 y=v("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]),$={purchase_success:{icon:A,color:"text-emerald-500",bgColor:"bg-emerald-500/10",label:"Purchase"},token_used:{icon:B,color:"text-blue-500",bgColor:"bg-blue-500/10",label:"Token Used"},research_failed:{icon:T,color:"text-destructive",bgColor:"bg-destructive/10",label:"Failed"}};function I(n){const o=Date.now()-new Date(n).getTime(),a=Math.floor(o/6e4);if(a<1)return"just now";if(a<60)return`${a}m ago`;const i=Math.floor(a/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function V(){w("Notifications",{noindex:!0}),_(),k();const{isAdmin:n,loading:o}=q(),[a,i]=m.useState([]),[c,h]=m.useState(!0);m.useEffect(()=>{n&&p()},[n]);const p=async()=>{h(!0);const{data:s}=await u.from("admin_notifications").select("*").order("created_at",{ascending:!1}).limit(100);i(s||[]),h(!1)},b=async s=>{await u.from("admin_notifications").update({is_read:!0}).eq("id",s),i(t=>t.map(r=>r.id===s?{...r,is_read:!0}:r))},C=async()=>{const s=a.filter(t=>!t.is_read).map(t=>t.id);s.length!==0&&(await u.from("admin_notifications").update({is_read:!0}).in("id",s),i(t=>t.map(r=>({...r,is_read:!0}))),S.success("All marked as read"))};if(o)return e.jsx(f,{children:e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(g,{className:"w-6 h-6 animate-spin text-muted-foreground"})})});if(!n)return e.jsx(f,{children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-destructive/10 flex items-center justify-center",children:e.jsx(L,{className:"w-8 h-8 text-destructive"})}),e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground text-center max-w-md",children:"This page is restricted to administrators."})]})});const d=a.filter(s=>!s.is_read).length;return e.jsx(f,{children:e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(y,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Notifications"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:d>0?`${d} unread`:"All caught up"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[d>0&&e.jsxs(x,{variant:"outline",size:"sm",onClick:C,children:[e.jsx(M,{className:"w-4 h-4 mr-1"})," Mark all read"]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:p,disabled:c,children:[e.jsx(R,{className:l("w-4 h-4 mr-1",c&&"animate-spin")}),"Refresh"]})]})]}),c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(g,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):a.length===0?e.jsx(j,{children:e.jsx(N,{className:"py-12 text-center text-muted-foreground",children:"No notifications yet"})}):e.jsx("div",{className:"space-y-2",children:a.map(s=>{const t=$[s.type]||{icon:y,color:"text-muted-foreground",bgColor:"bg-muted",label:s.type},r=t.icon;return e.jsx(j,{className:l("transition-colors",!s.is_read&&"border-primary/20 bg-primary/[0.02]"),children:e.jsx(N,{className:"py-3 px-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:l("w-8 h-8 rounded-lg flex items-center justify-center shrink-0 mt-0.5",t.bgColor),children:e.jsx(r,{className:l("w-4 h-4",t.color)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx(D,{variant:"outline",className:"text-[10px]",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:I(s.created_at)}),!s.is_read&&e.jsx("div",{className:"w-2 h-2 rounded-full bg-primary"})]}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.title}),s.details&&e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground space-x-3",children:[s.details.email&&e.jsxs("span",{children:["Email: ",String(s.details.email)]}),s.details.person_name&&e.jsxs("span",{children:["Person: ",String(s.details.person_name)]}),s.details.quality_score!=null&&e.jsxs("span",{children:["Quality: ",String(s.details.quality_score)]}),s.details.amount!=null&&e.jsxs("span",{children:["Amount: $",(Number(s.details.amount)/100).toFixed(2)]})]})]}),!s.is_read&&e.jsx(x,{variant:"ghost",size:"icon",className:"shrink-0 h-7 w-7",onClick:()=>b(s.id),children:e.jsx(E,{className:"w-4 h-4 text-muted-foreground"})})]})})},s.id)})})]})})}export{V 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.