"use client";

import { HOME_CAROUSEL_SECTION_CLASS, HOME_CAROUSEL_HEADER_CLASS } from "./homeCarouselLayout";
import { useTranslation } from "react-i18next";
import VolunteerCard from "./VolunteerCard";
import Title from "@/components/shared/Title";
import Link from "next/link";
import { useAuthStore } from "@/store/authStore";
import type { HomeOpportunity } from "@/features/home/types";

interface VolunteerProps {
  /** Pre-fetched opportunities from the server (optional — client fetches if absent) */
  initialOpportunities?: HomeOpportunity[];
}

export default function Volunteer({ initialOpportunities = [] }: VolunteerProps) {
  const { t } = useTranslation();
  const user = useAuthStore((s) => s.user);

  return (
    <div className="relative">
      <div className={`profilevolunteer ${HOME_CAROUSEL_SECTION_CLASS}`}>
        <div className={HOME_CAROUSEL_HEADER_CLASS}>
          <h2>
            <Title
              text={t("COMMON.VOLUNTEER")}
              variant="blue"
              hasMargin={false}
            />
          </h2>
            <Link
              href="/volunteer-opportunities-list"
              className="text-primary-802 font-bold lg:text-lg md:text-lg text-base 2xl:text-xl"
              aria-label={t("COMMON.SHOW_ALL_VOLUNTEER_OPPORTUNITIES")}
            >
              {t("COMMON.SHOW.ALL")}
            </Link>
        </div>
        <VolunteerCard
          isOpportunity
          currentUser={user}
          buttonText={undefined}
          is_homepage={true}
          initialData={initialOpportunities}
        />
      </div>
    </div>
  );
}
