"use client";

import { useTranslation } from "react-i18next";
import { interestLabel, type InterestTag } from "@/lib/interests";
import {
} from "./learnServeDetailsTypes";
import TagChipLink from "@/components/ui/TagChipLink";
import AssetIcon from "@/components/ui/AssetIcon";

interface LearnServeDescriptionBlockProps {
  selectedLanguage: string;
  /** Already sanitized by `computeLearnServeViewState`. */
  description: string;
  interestTags: InterestTag[];
}

/**
 * The description and the interest tags under it.
 *
 * The description arrives sanitized rather than being sanitized here: the
 * markup comes from an organization's rich-text editor, and doing it once in the
 * view-state module keeps one call site instead of trusting every renderer.
 */
export default function LearnServeDescriptionBlock({
  selectedLanguage,
  description,
  interestTags,
}: LearnServeDescriptionBlockProps) {
  const { t } = useTranslation();

  return (
    <>
      <div className="mb-6">
        <div className="flex justify-between items-center mb-3">
          <h3 className="text-sm md:text-base font-bold text-primary-5 flex gap-2 items-center">
            <AssetIcon
              src="/assets/voluneteerevent/rightarrows.svg"
              size={22}
              className={selectedLanguage === "ar" ? "rotate-rtl" : ""}
            />
            {t("COMMON.DESCRIPTION")}
          </h3>
        </div>
        <div
          className="text-sm md:text-base font-normal text-secondary-102"
          dangerouslySetInnerHTML={{ __html: description }}
        />
      </div>

      {interestTags.length > 0 && (
        <div className="flex flex-wrap gap-6 mt-6 xss:gap-2 items-center mb-6">
          <AssetIcon src="/assets/voluneteerevent/label.svg" size={30} />
          {interestTags.map((interest, index) => {
            const label = interestLabel(interest, selectedLanguage);
            return (
              <TagChipLink
                key={interest.id ?? index}
                label={label}
                index={index}
                href={`/development-opportunities-list?tags=${encodeURIComponent(label)}`}
              />
            );
          })}
        </div>
      )}
    </>
  );
}
