"use client";

import { useTranslation } from "react-i18next";

export const TYPE_CHIPS = [
  { value: "all", labelKey: "COMMON.ALL", param: undefined },
  { value: "volunteer", labelKey: "COMMON.VOLUNTEER", param: "volunteer_opportunity" },
  { value: "development", labelKey: "COMMON.PROFILE_DEVELOPMENT", param: "learn_serve_opportunity" },
] as const;

export type TypeChip = (typeof TYPE_CHIPS)[number]["value"];

/**
 * All / Volunteer / Development, each with the count the list would return.
 *
 * `countOf` is the parent's: only the "all" chip has a total to show, because
 * that is the only one whose query is already in flight for the list itself.
 */
export default function ProfileTypeChips({
  typeChip,
  setTypeChip,
  countOf,
}: {
  typeChip: TypeChip;
  setTypeChip: (chip: TypeChip) => void;
  countOf: (chip: TypeChip) => number | null;
  isExpert?: boolean;
  expertOpportunitiesCount?: number | null;
}) {
  const { t } = useTranslation();

  return (
    <div className="flex shrink-0 flex-wrap items-center gap-2">
      {TYPE_CHIPS.map((chip) => {
        const active = chip.value === typeChip;
        const count = countOf(chip.value);
        return (
          <button
            key={chip.value}
            type="button"
            onClick={() => setTypeChip(chip.value)}
            className={`flex items-center gap-2 rounded-full px-4 py-1.5 text-sm font-semibold ${
              active ? "bg-primary-5 text-white" : "bg-[#29246D0F] text-primary-5"
            }`}
          >
            {t(chip.labelKey)}
            {count != null && (
              <span
                className={`rounded-full px-2 text-xs ${
                  active ? "bg-white text-primary-5" : "bg-white/70"
                }`}
              >
                {count}
              </span>
            )}
          </button>
        );
      })}
    </div>
  );
}
