"use client";

import { useTranslation } from "react-i18next";

import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/Tabs";
import { useLanguageStore } from "@/store/languageStore";
import CertificateTabs from "./ProfileCertificateTabs";
import MyEventsTabs from "./ProfileMyEventsTabs";
import OpportunityTabs from "./ProfileOpportunityTabs";
import { TAB_TRIGGER_CLASS } from "./profileTabChips";
/*
 * Re-exported: other screens import the activity chips and the filter dialog
 * from this module, and moving them should not move their import path.
 */
export { ACTIVITY_TAG_TABS, ActivityTagChips } from "./profileTabChips";
export { FilterModal } from "./ProfileFilterModal";

export const CERTIFICATE_FILTER_CHOICE_TYPE = "certificate_filter_type";

/** The "no filter" chip. Not a type — it just means the param is omitted. */
export const ALL_CERTIFICATE_TYPES = "all";

export interface ChoiceOption {
  id?: number | string;
  value_en?: string;
  value_ar?: string;
}

export const TAB_CONTENT_CLASS =
  "mt-0 border-t border-primary-5 2xl:pt-16 laptopmain:pt-8 lg:pt-5 pt-5 md:pt-5 lg:pb-[50px] md:pb-[20px] pb-[20px]";

export interface ProfileDescriptionTabsProps {
  /* Optional: `OrganizerProfile` reads it off a profile that is undefined
     until the fetch resolves. */
  isVolunteerTeam?: boolean;
  isPublicProfile?: boolean;
  user_id?: string;
  /**
   * A volunteer's own profile lists what they registered for and attended; a
   * team or entity lists what it organised (and sponsored).
   */
  isVolunteer?: boolean;
}

export default function ProfileDescriptionTabs({
  isVolunteerTeam = false,
  isPublicProfile = false,
  user_id,
  isVolunteer = false,
}: ProfileDescriptionTabsProps) {
  const selectedLanguage = useLanguageStore((s) => s.language);
  const { t } = useTranslation();

  return (
    <Tabs
      defaultValue="opportunity"
      dir={selectedLanguage === "en" ? "ltr" : "rtl"}
    >
      <div className="flex 2xl:px-5 px-3 mobilescreen:px-[13px]">
        <TabsList className="h-auto w-auto justify-start gap-[38px] bg-transparent p-0 xs:gap-3">
          <TabsTrigger value="opportunity" className={TAB_TRIGGER_CLASS}>
            <span className="2xl:text-[30px] lg:text-[20px] md:text-[18px] font-bold text-primary-5">
              {t("COMMON.OPPORTUNITIES-")}
            </span>
          </TabsTrigger>
          {isVolunteer && (
            <TabsTrigger value="certificates" className={TAB_TRIGGER_CLASS}>
              <span className="2xl:text-[30px] lg:text-[20px] md:text-[18px] font-bold text-primary-5">
                {t("COMMON.CERTIFICATES")}
              </span>
            </TabsTrigger>
          )}
          {/* Events are an announcement surface only (BE-41) — a volunteer has
              no event history to show, so their own profile is Opportunities +
              Certificates. Volunteer teams cannot publish events (client
              answers p.6), so only entities keep the tab. */}
          {!isVolunteer && !isVolunteerTeam && (
            <TabsTrigger value="event" className={TAB_TRIGGER_CLASS}>
              <span className="2xl:text-[30px] lg:text-[20px] md:text-[18px] font-bold text-primary-5">
                {t("COMMON.EVENTS-")}
              </span>
            </TabsTrigger>
          )}
        </TabsList>
      </div>

      <TabsContent value="opportunity" className={TAB_CONTENT_CLASS}>
        <OpportunityTabs
          isVolunteerTeam={isVolunteerTeam}
          isPublicProfile={isPublicProfile}
          user_id={user_id}
          isVolunteer={isVolunteer}
        />
      </TabsContent>

      {isVolunteer && (
        <TabsContent value="certificates" className={TAB_CONTENT_CLASS}>
          <CertificateTabs user_id={user_id} />
        </TabsContent>
      )}

      {!isVolunteer && !isVolunteerTeam && (
        <TabsContent value="event" className={TAB_CONTENT_CLASS}>
          <MyEventsTabs
            isVolunteerTeam={isVolunteerTeam}
            isPublicProfile={isPublicProfile}
            user_id={user_id}
          />
        </TabsContent>
      )}
    </Tabs>
  );
}
