"use client";

import { useState, useEffect } from "react";
import { useParams } from "next/navigation";
import { generateTango, TangoPuzzle } from "@/lib/generators/tango";
import TangoBoard from "@/components/TangoBoard";
import Link from "next/link";

export default function TangoDatePage() {
  const { date } = useParams<{ date: string }>();
  const [puzzle, setPuzzle] = useState<TangoPuzzle | null>(null);
  useEffect(() => { setPuzzle(generateTango(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">Tango</h1>
        <p className="text-sm text-gray-400 mt-1">{date}</p>
      </div>
      {puzzle ? (
        <TangoBoard 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="/tango" className="text-gray-500 hover:text-gray-900 transition-colors">← Aujourd&apos;hui</Link>
        <Link href="/archive?game=tango" className="text-gray-400 hover:text-gray-700 transition-colors">Archives</Link>
      </div>
    </div>
  );
}
