"use client";

import { type Reply } from "./replyDetailTypes";
import { useTranslation } from "react-i18next";
import type { useReplyDetail } from "./useReplyDetail";
import ChildReplyRow from "./ChildReplyRow";

/**
 * The replies under a reply.
 *
 * Only direct children are listed — the thread does not nest further, and a
 * child with its own replies links to its own page instead.
 */
export default function ReplyDetailChildren({
  screen,
  directReplies,
}: {
  /* The page hook's whole return, forwarded to each row. */
  screen: ReturnType<typeof useReplyDetail>;
  /* Derived on the page, not in the hook — hence an explicit prop. */
  directReplies: Reply[];
}) {
  const { t } = useTranslation();

  return (
  <div className="pb-12">
    <h3 className="font-bold text-xl my-4">
      {directReplies.length === 1
        ? t("COMMON.REPLY")
        : t("COMMON.REPLIES")}{" "}
      ({directReplies.length})
    </h3>

    {directReplies.length === 0 ? (
      <div className="text-center py-8 text-secondary-102 text-lg font-medium">
        {t("COMMON.NO_REPLIES")}
      </div>
    ) : (
      <div>
        {directReplies.map((childReply: Reply, index: number) => (
          <ChildReplyRow
            key={childReply.id}
            childReply={childReply}
            isLast={index === directReplies.length - 1}
            screen={screen}
          />
        ))}
      </div>
    )}
  </div>
  );
}
