"use client";

import { useRouter } from "next/navigation";

export function YearSelector({ currentYear }: { currentYear: number }) {
  const router = useRouter();
  const thisYear = new Date().getFullYear();

  function go(y: number) {
    router.push(`/admin?year=${y}`);
  }

  return (
    <div className="inline-flex items-center gap-0.5 rounded-lg border border-border-light bg-muted/50 px-1 py-0.5">
      <button
        onClick={() => go(currentYear - 1)}
        className="w-5 h-5 rounded flex items-center justify-center text-muted-foreground hover:text-primary transition-colors"
        aria-label="Anno precedente"
      >
        ←
      </button>
      <span className="text-xs font-bold text-foreground font-mono w-10 text-center">
        {currentYear}
      </span>
      <button
        onClick={() => go(currentYear + 1)}
        disabled={currentYear >= thisYear}
        className="w-5 h-5 rounded flex items-center justify-center text-muted-foreground hover:text-primary transition-colors disabled:opacity-30 disabled:cursor-not-allowed"
        aria-label="Anno successivo"
      >
        →
      </button>
    </div>
  );
}