"use client";
import useSWR from "swr";

const fetcher = (url: string) => fetch(url).then((r) => r.json());

export default function AdminDashboardPage() {
  const { data } = useSWR<{ users: number; posts: number; comments: number; reportsOpen: number; pendingReviews: number }>("/api/admin/dashboard", fetcher);
  const m = data ?? { users: 0, posts: 0, comments: 0, reportsOpen: 0, pendingReviews: 0 };
  return (
    <div className="space-y-4">
      <h1 className="text-xl md:text-2xl font-bold">관리자 대시보드</h1>
      <div className="grid grid-cols-2 md:grid-cols-5 gap-3">
        <Card label="사용자" value={m.users} />
        <Card label="게시글" value={m.posts} />
        <Card label="댓글" value={m.comments} />
        <Card label="열린 신고" value={m.reportsOpen} />
        <Card label="승인 대기 글" value={m.pendingReviews} />
      </div>
    </div>
  );
}

function Card({ label, value }: { label: string; value: number }) {
  return (
    <div className="rounded-xl border border-neutral-200 bg-white p-4">
      <div className="text-xs text-neutral-500">{label}</div>
      <div className="text-2xl font-bold">{value}</div>
    </div>
  );
}


