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

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

export default function MonthlyStatsPage({ searchParams }: { searchParams?: { year?: string; month?: string } }) {
  const year = searchParams?.year ?? String(new Date().getFullYear());
  const month = searchParams?.month ?? String(new Date().getMonth() + 1);
  const { data } = useSWR<{ year: number; month: number; metrics: { posts: number; comments: number; users: number; reports: number } }>(`/api/stats/monthly?year=${year}&month=${month}`, fetcher);
  const m = data?.metrics;
  return (
    <div>
      <h1>월간 집계</h1>
      <div>대상 월: {year}.{month}</div>
      <ul>
        <li>게시글: {m?.posts ?? 0}</li>
        <li>댓글: {m?.comments ?? 0}</li>
        <li>신규 사용자: {m?.users ?? 0}</li>
        <li>신고: {m?.reports ?? 0}</li>
      </ul>
    </div>
  );
}


