"use client";

import Image from "next/image";
import { useTranslation } from "react-i18next";
import type { MouseEvent } from "react";

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

/**
 * The like and reply counters under a reply.
 *
 * The counts are passed in rather than read off the reply: the viewed reply
 * shows the number of *visible* children (deleted ones are filtered out on the
 * page), while a reply underneath shows its own raw `child_replies` length.
 */
export default function ReplyEngagementBar({
  className,
  likesCount,
  replyCount,
  likeDisabled,
  onLike,
  onReply,
}: {
  className: string;
  likesCount: number;
  replyCount: number;
  likeDisabled: boolean;
  onLike: (e: MouseEvent<HTMLButtonElement>) => void;
  onReply: (e: MouseEvent<HTMLButtonElement>) => void;
}) {
  const { t } = useTranslation();
  const pill =
    "flex items-center gap-1.5 py-1 text-xs font-bold text-[#65676B] hover:text-primary-5 hover:underline disabled:opacity-50";

  return (
    <div className={className}>
      <button disabled={likeDisabled} onClick={onLike} className={pill}>
        <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")} {likesCount > 0 ? `(${likesCount})` : ""}</span>
      </button>
      <button onClick={onReply} className={pill}>
        <Image
          src={asset("community/message.svg")}
          alt={t("COMMON.REPLY")}
          width={14}
          height={14}
        />
        <span>{t("COMMON.REPLY")} {replyCount > 0 ? `(${replyCount})` : ""}</span>
      </button>
    </div>
  );
}
