"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 LearnServeProps {
  /** Pre-fetched opportunities from the server (optional — client fetches if absent) */
  initialOpportunities?: HomeOpportunity[];
}

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

  return (
    <div className={HOME_CAROUSEL_SECTION_CLASS}>
      <div className={HOME_CAROUSEL_HEADER_CLASS}>
        <h2>
          <Title
            text={t("COMMON.LEARN_SHARE")}
            variant="cyan"
            hasMargin={false}
          />
        </h2>
        <Link
          href="/development-opportunities-list"
          className="text-primary-803 font-bold lg:text-lg md:text-lg text-base 2xl:text-xl"
          aria-label={t("COMMON.SHOW_ALL_LEARN_SERVE_OPPORTUNITIES")}
        >
          {t("COMMON.SHOW.ALL")}
        </Link>
      </div>

      <VolunteerCard
        buttonText={undefined}
        isLearnServe
        currentUser={user}
        is_homepage={true}
        initialData={initialOpportunities}
      />
    </div>
  );
}
