"use client";

import Image from "next/image";
import { useTranslation } from "react-i18next";
import { type Reply } from "./replyDetailTypes";

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

/**
 * A reply's like and reply-to-reply controls, plus its child count.
 */
export default function ReplyActionsRow({
  reply,
  childRepliesCount,
  expanded = false,
  likeLoading,
  onLike,
  onReply,
  onNavigateToReply,
}: {
  reply: Reply;
  childRepliesCount: number;
  expanded?: boolean;
  likeLoading: boolean;
  onLike: (replyId: string) => void;
  onReply: (replyId: string) => void;
  onNavigateToReply: (replyId: number) => void;
}) {
  const { t } = useTranslation();

  return (
  <div className="col-start-2 flex flex-wrap items-center gap-x-4 gap-y-2 px-2 pt-1">
    <button
      onClick={(e) => {
        e.stopPropagation();
        onLike(String(reply.id));
      }}
      disabled={likeLoading}
      className="flex items-center gap-1.5 py-1 text-xs font-bold text-[#65676B] hover:text-primary-5 hover:underline disabled:opacity-50"
    >
      <Image
        src={asset("community/purplethumb.svg")}
        alt={t("COMMON.LIKE")}
        width={14}
        height={14}
        className="h-3.5 w-3.5"
      />
      <span>
        {t("COMMON.LIKE")} {reply.likes_count > 0 ? `(${reply.likes_count})` : ""}
      </span>
    </button>
    <button
      onClick={(e) => {
        e.stopPropagation();
        onReply(String(reply.id));
      }}
      className="flex items-center gap-1.5 py-1 text-xs font-bold text-[#65676B] hover:text-primary-5 hover:underline disabled:opacity-50"
    >
      <Image
        src={asset("community/message.svg")}
        alt={t("COMMON.REPLY")}
        width={14}
        height={14}
      />
      <span className="text-xs">
        {t("COMMON.REPLY")}
      </span>
    </button>
    {childRepliesCount > 0 && (
      <button
        type="button"
        onClick={(event) => {
          event.stopPropagation();
          onNavigateToReply(reply.id);
        }}
        className="text-xs font-bold text-[#65676B] hover:text-primary-5 hover:underline"
      >
        {t(expanded ? "COMMON.HIDE_CHILD_REPLIES" : "COMMON.VIEW_CHILD_REPLIES", { count: childRepliesCount })}
      </button>
    )}
  </div>
  );
}
