"use client";

import { useState, useEffect } from "react";
import { useParams } from "next/navigation";
import { generateQueens, QueensPuzzle } from "@/lib/generators/queens";
import QueensBoard from "@/components/QueensBoard";
import Link from "next/link";

export default function QueensDatePage() {
  const { date } = useParams<{ date: string }>();
  const [puzzle, setPuzzle] = useState<QueensPuzzle | null>(null);
  useEffect(() => { setPuzzle(generateQueens(date)); }, [date]);

  return (
    <div className="flex flex-col items-center gap-8">
      <div className="text-center">
        <h1 className="text-2xl font-bold text-gray-900 tracking-tight">Queens</h1>
        <p className="text-sm text-gray-400 mt-1">{date}</p>
      </div>
      {puzzle ? (
        <QueensBoard key={date} puzzle={puzzle} date={date} />
      ) : (
        <div className="py-20 text-gray-300 text-sm">Chargement…</div>
      )}
      <div className="flex gap-4 text-sm">
        <Link href="/queens" className="text-gray-500 hover:text-gray-900 transition-colors">← Aujourd&apos;hui</Link>
        <Link href="/archive?game=queens" className="text-gray-400 hover:text-gray-700 transition-colors">Archives</Link>
      </div>
    </div>
  );
}
