"use client";

import Image from "next/image";
import Link from "next/link";
import { useTranslation } from "react-i18next";

/**
 * Two pieces the header's desktop and mobile navs both render.
 *
 * They were closures inside `Header`, reading `close`, `unreadCount` and
 * `pathname` from its scope. As shared components those values arrive as
 * props, so a missing one is a compile error rather than a badge that silently
 * shows nothing.
 */

/** The bell, with its unread count. */
export function NotificationBadge({
  close,
  unreadCount,
  mobile = false,
}: {
  close: () => void;
  unreadCount: number;
  /** The mobile menu renders it slightly smaller. */
  mobile?: boolean;
}) {
  const { t } = useTranslation();

  return (
    <Link href="/notification" onClick={close} aria-label={t("COMMON.NOTIFICATIONS") || "Notifications"}>
      <div className="relative">
        <Image
          src="/assets/homepage/notification.svg"
          alt=""
          width={mobile ? 35 : 40}
          height={mobile ? 35 : 40}
          className={mobile ? "xss:w-[35px] xss:h-[35px]" : ""}
          aria-hidden="true"
          unoptimized
        />
        {unreadCount > 0 && (
          <span
            className={`absolute top-[14px] left-[10px] p-2 transform translate-x-1/2 -translate-y-1/2 bg-orange-500 text-white text-[10px] leading-[1rem] font-bold ${unreadCount > 99 ? "w-5 h-3" : "w-3 h-3"
              } flex items-center justify-center rounded-full`}
          >
            {unreadCount > 99 ? "99+" : unreadCount}
          </span>
        )}
      </div>
    </Link>
  );
}

/** One row inside the account dropdown. */
export function DropdownItem({
  href,
  icon,
  label,
  close,
}: {
  href: string;
  icon: string;
  label: string;
  close: () => void;
}) {
  return (
    <li className="px-4 py-2 hover:bg-[#F5F5F5] mx-2 rounded-xl flex items-center gap-3 h-12 text-lg font-bold text-secondary-101">
      <Link href={href} className="flex items-center gap-3 w-full" onClick={close}>
        <Image src={icon} alt="" width={24} height={24} className="w-6 h-6 object-contain" unoptimized />
        {label}
      </Link>
    </li>
  );
}
