"use client";

import { useTranslation } from "react-i18next";

export type ProfileRelation = "organized" | "sponsored";

const OPTIONS: ReadonlyArray<{ value: ProfileRelation; labelKey: string }> = [
  { value: "organized", labelKey: "COMMON.CARD_BADGE_ORGANIZER" },
  { value: "sponsored", labelKey: "COMMON.CARD_BADGE_SPONSOR" },
];

/**
 * «منظم / راعي» — an organization's tabs list what it organized or what it
 * sponsored. They are two backend filters (`organized` / `sponsored`, and the
 * `_events` pair), not one list, so the switch picks which one is shown; each
 * card also carries the matching tag on its cover.
 */
export default function ProfileRelationSwitch({
  value,
  onChange,
}: {
  value: ProfileRelation;
  onChange: (value: ProfileRelation) => void;
}) {
  const { t } = useTranslation();

  return (
    <div
      role="tablist"
      className="mt-4 inline-flex rounded-full bg-[#29246D0F] p-1"
    >
      {OPTIONS.map((option) => {
        const active = option.value === value;
        return (
          <button
            key={option.value}
            type="button"
            role="tab"
            aria-selected={active}
            onClick={() => onChange(option.value)}
            className={`rounded-full px-5 py-1.5 text-sm font-semibold transition-colors ${
              active ? "bg-primary-5 text-white" : "text-primary-5"
            }`}
          >
            {t(option.labelKey)}
          </button>
        );
      })}
    </div>
  );
}
