'use client';

interface FlightSortTabsProps {
  activeTab?: string;
  onTabChange?: (tab: string) => void;
  /** Cheapest fare among current results, e.g. "$294" — omit while there's nothing to show yet */
  cheapestLabel?: string;
  /** Shortest duration among current results, e.g. "8h 8m" — omit while there's nothing to show yet */
  fastestLabel?: string;
}

export default function FlightSortTabs({
  activeTab = 'best',
  onTabChange,
  cheapestLabel,
  fastestLabel,
}: FlightSortTabsProps) {
  const tabs = [
    { id: 'best', label: 'Best', subLabel: 'Recommended' },
    { id: 'cheapest', label: 'Cheapest', subLabel: cheapestLabel ?? '–' },
    { id: 'fastest', label: 'Fastest', subLabel: fastestLabel ?? '–' },
    { id: 'earliest', label: 'Earliest', subLabel: 'Departure' },
    { id: 'earliest-arrival', label: 'Earliest', subLabel: 'Arrival' },
  ];

  return (
    <div className="filter-button-tabs d-md-block d-none">
      <div className="row row-cols-md-5 row-cols-2 g-2 mt-3">
        {tabs.map((tab) => (
          <div key={tab.id} className="col d-flex">
            <button
              className={`filter-buttons w-100 buttons btnColor-first-outline bgColor-white p-2 w-100 d-flex flex-column justify-content-center align-items-center gap-0 ${activeTab === tab.id ? ' active' : ''}`}
              onClick={() => onTabChange?.(tab.id)}
            >
              <p className="text-sm mb-0 fw-600">{tab.label}</p>
              <p className="text-xs mb-0">{tab.subLabel}</p>
            </button>
          </div>
        ))}
      </div>
    </div>
  );
}
