'use client';
import React from 'react';
import Tab from '@/components/Tab';
import { getCurrentSchoolYear, getNextSchoolYear } from '@/utils/Date';
import { CURRENT_YEAR_FILTER, NEXT_YEAR_FILTER, HISTORICAL_FILTER } from '@/utils/constants';

/**
 * Composant de filtre par année scolaire réutilisable.
 * Affiche des tabs pour l'année en cours, l'année prochaine et l'historique.
 * 
 * @param {string} activeFilter - Le filtre actif ('current_year', 'next_year', 'historical')
 * @param {function} onFilterChange - Callback appelé quand le filtre change
 * @param {object} counts - Objet contenant les compteurs par filtre { currentYear, nextYear, historical }
 * @param {boolean} showNextYear - Afficher ou non l'onglet année prochaine (défaut: true)
 * @param {boolean} showHistorical - Afficher ou non l'onglet historique (défaut: true)
 */
const SchoolYearFilter = ({
  activeFilter,
  onFilterChange,
  counts = {},
  showNextYear = true,
  showHistorical = true,
}) => {
  const currentSchoolYear = getCurrentSchoolYear();
  const nextSchoolYear = getNextSchoolYear();

  return (
    <div className="flex flex-wrap gap-2 mb-4">
      <Tab
        text={`${currentSchoolYear}${counts.currentYear !== undefined ? ` (${counts.currentYear})` : ''}`}
        active={activeFilter === CURRENT_YEAR_FILTER}
        onClick={() => onFilterChange(CURRENT_YEAR_FILTER)}
      />
      {showNextYear && (
        <Tab
          text={`${nextSchoolYear}${counts.nextYear !== undefined ? ` (${counts.nextYear})` : ''}`}
          active={activeFilter === NEXT_YEAR_FILTER}
          onClick={() => onFilterChange(NEXT_YEAR_FILTER)}
        />
      )}
      {showHistorical && (
        <Tab
          text={`Archives${counts.historical !== undefined ? ` (${counts.historical})` : ''}`}
          active={activeFilter === HISTORICAL_FILTER}
          onClick={() => onFilterChange(HISTORICAL_FILTER)}
        />
      )}
    </div>
  );
};

export default SchoolYearFilter;
