"use client";

import CommunityImageStrip from "./CommunityImageStrip";
import { type PostData } from "./InnerPost";
import HashtagText from "@/components/shared/HashtagText";
import { pickLocalized } from "@/features/shared/types/cms";
import Image from "next/image";
import { useTranslation } from "react-i18next";

const asset = (path: string) => `/assets/${path}`;

/**
 * A post's title, body text and images on its own page.
 *
 * The body goes through `HashtagText`, so a tag inside the text filters the
 * list rather than opening the post.
 */
export default function CommunityPostBody({
  postData,
  selectedLanguage,
  handleTagClick,
  handleImageClick,
}: {
  postData: NonNullable<PostData["data"]>;
  selectedLanguage: string;
  handleTagClick: (tag: string) => void;
  handleImageClick: (imageUrl: string) => void;
}) {
  const { t } = useTranslation();

  return (
  <div className="mb-4">
    <h2 className="text-xl xs:text-base font-bold mb-2 flex gap-3">
      {/* Idea badge only — the funding ("Needs Support") badge was removed. */}
      {postData.proposing_idea ? (
        <div
          style={{
            width: 60,
            height: 36,
            borderRadius: 20,
            border: "1px solid #29246D",
            background: "rgba(23, 10, 81, 0.05)",
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            gap: 6,
          }}
        >
          <Image
            src={asset("community/idia.svg")}
            style={{ width: 12, height: 19.25 }}
            alt={t("COMMON.PROPOSING_IDEA")}
            width={12}
            height={20}
          />
        </div>
      ) : null}
    </h2>
    <p className="text-[#535151] text-lg">
      {/* Older posts carry only the language they were written in; the
          other side is null, so fall back rather than show an empty body. */}
      <HashtagText
        text={pickLocalized(postData.idea_text_en, postData.idea_text_ar, selectedLanguage)}
        onTagClick={handleTagClick}
      />
    </p>
    {/* The shared strip: null-`image` rows filtered out (`next/image` throws
        on a missing `src`) and each thumbnail a real button rather than an
        `<Image onClick>`. */}
    <CommunityImageStrip
      images={postData.post_images}
      onImageClick={handleImageClick}
      altPrefix={t("COMMON.POST")}
      className="flex pt-8 pb-4 overflow-x-auto space-x-4"
    />
  </div>
  );
}
