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

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

export default function AttendancePage() {
  const { data, mutate } = useSWR<{ today: boolean; count: number }>("/api/attendance", fetcher);
  return (
    <div>
      <h1>출석부</h1>
      <p>오늘 출석: {data?.today ? "✅" : "❌"} / 누적: {data?.count ?? 0}</p>
      <button disabled={data?.today} onClick={async () => { await fetch("/api/attendance", { method: "POST" }); mutate(); }}>출석하기</button>
    </div>
  );
}


