"use client"; import { useEffect, useState } from "react"; import { X, Download, Power, RefreshCw, Copy, Check } from "lucide-react"; import { api, apiBase } from "@/lib/api"; type Tab = "overview" | "stats" | "history"; export default function QrDetailDrawer({ qrId, onClose, onChanged }: { qrId: string; onClose: () => void; onChanged: () => void; }) { const [d, setD] = useState(null); const [tab, setTab] = useState("overview"); const [copied, setCopied] = useState(false); function load() { api(`/qr/${qrId}/detail`).then(setD).catch(() => {}); } useEffect(() => { load(); }, [qrId]); async function disable() { await api(`/qr/${qrId}/disable`, { method: "PUT" }); load(); onChanged(); } async function regenerate() { await api(`/qr/${qrId}/regenerate`, { method: "POST" }); load(); onChanged(); } function copyUrl() { navigator.clipboard?.writeText(d?.short_url ?? ""); setCopied(true); setTimeout(() => setCopied(false), 1500); } if (!d) return (
e.stopPropagation()}>
); const preview = d.image_url ? `${apiBase}${d.image_url}` : `${apiBase}/qr/${qrId}/download?format=png`; const statusColor = d.status === "active" ? "bg-emerald-50 text-emerald-700" : "bg-rose-50 text-rose-600"; return (
e.stopPropagation()}>

QR Details

QR
{d.status}
QR ID
{d.qr_id_label}
Short URL
{/* tabs */}
{([["overview", "Overview"], ["stats", "Scan Statistics"], ["history", "History"]] as const).map(([t, l]) => ( ))}
{tab === "overview" && (
Verification Enabled {d.overview.verification_enabled ? "✓ Yes" : "Disabled"}
Expiry {d.overview.expiry}
)} {tab === "stats" && (
)} {tab === "history" && (
{d.history.map((h: any, i: number) => (
{new Date(h.at).toLocaleString()} {h.city ?? "—"} · {h.device ?? "—"}
))} {d.history.length === 0 &&

No scans yet.

}
)} {/* downloads */}
); } function Row({ label, value, cap }: any) { return (
{label} {value ?? "—"}
); } function Stat({ label, value }: any) { return (
{value}
{label}
); }