"use client";

import { useTranslation } from "react-i18next";

/**
 * Registered / Attended / Organizer / Sponsor.
 *
 * Which tabs exist depends on whose profile it is: a volunteer sees Registered
 * and Attended, a team or entity sees Organizer, and only an entity sees
 * Sponsor — a volunteer team has no sponsorships for the API to serve.
 */
export default function ProfileTabsBar({
  activeTab,
  setActiveTab,
  isVolunteer,
  isVolunteerTeam,
}: {
  activeTab: string;
  setActiveTab: (tab: string) => void;
  isVolunteer?: boolean;
  isVolunteerTeam?: boolean;
}) {
  const { t } = useTranslation();

  // Every tab is the same button with the same two states — only the label and
  // the value differ, so the class template is written once.
  const tabClass = (tab: string) =>
    `pb-1 ${
      activeTab === tab
        ? "text-primary-5 border-b-2 border-primary-5 text-[18px] 2xl:text-[25px] lg:text-[18px] md:text-[18px] xs:text-[13px] font-bold"
        : "text-[#000000] text-[18px] 2xl:text-[25px] lg:text-[18px] md:text-[18px] xs:text-[13px] font-normal"
    }`;

  return (
    <div className="flex gap-8 mobilescreen:gap-7 mobilescreen:mb-5 mobilescreen:justify-center">
      {isVolunteer && (
        <button
          className={tabClass("registered")}
          onClick={() => setActiveTab("registered")}
        >
          {t("COMMON.REGISTERED")}
        </button>
      )}
      <button
        className={tabClass("organized")}
        onClick={() => setActiveTab("organized")}
      >
        {t(isVolunteer ? "COMMON.ATTENDED--" : "COMMON.ORGANIZER_TAG")}
      </button>
      {!isVolunteerTeam && !isVolunteer && (
        <button
          className={tabClass("sponsored")}
          onClick={() => setActiveTab("sponsored")}
        >
          {t("COMMON.SPONSOR")}
        </button>
      )}
    </div>
  );
}
