"use client";

import Image from "next/image";
import Link from "next/link";
import { useTranslation } from "react-i18next";
import {
  ChevronDownIcon,
  ChevronUpIcon,
} from "./headerIcons";

/**
 * The header's desktop nav row.
 *
 * Separate from the mobile menu rather than a re-flow of it: the two show
 * different structures, with the account links behind a dropdown here and
 * flat on mobile.
 */
export default function HeaderDesktopNav({
  pathname,
  close,
  dropdownOpen,
  setDropdownOpen,
}: {
  pathname: string;
  isLoggedIn: boolean;
  isVolunteer: boolean;
  close: () => void;
  /* `handleLogout` was declared here and never destructured: this component
     renders no sign-out control — `Header` mounts `HeaderProfileDropdown`
     itself, which is where sign-out lives. Dropped while BE-129 added a
     second sign-out, rather than threading that one through here too. */
  dropdownOpen: string | null;
  setDropdownOpen: React.Dispatch<React.SetStateAction<string | null>>;
  /* `profilePicUrl` was declared here and never destructured, for the same
     reason `handleLogout` was: this component renders no avatar — `Header`
     mounts `HeaderProfileDropdown` itself, which is where the avatar lives.
     Dropped while the avatar gained a gendered fallback, rather than
     threading a second unused prop beside the first. */
  unreadCount: number;
}) {
  const { t } = useTranslation();

  return (
  <ul className="hidden mediumscreen:flex 2xl:gap-[30px] lg:gap-5 md:gap-4 mediumscreen1:gap-2 items-center laptopitm:gap-[13px]">
    <li className={`flex text-primary-5 2xl:text-lg lg:text-base sm:text-base items-center laptopitm:text-sm ${pathname === "/" ? "font-bold" : ""   }`} >
      <Link href="/" onClick={close}>
        {t("COMMON.HOME")}
      </Link>
    </li>

    {/* Opportunities dropdown */}
    <li className="cursor-pointer flex text-primary-5 relative items-center">
     
      <button
        className="flex items-center ml-1 cursor-pointer focus:outline-none"
        aria-label={t("COMMON.TOGGLE_OPPORTUNITIES_MENU") || "Toggle opportunities menu"}
        aria-expanded={dropdownOpen === "opportunities"}
        onClick={() =>
          setDropdownOpen(
            dropdownOpen === "opportunities" ? null : "opportunities"
          )
        }
      >
         <span 
        // href="/opportunities"
        // onClick={close}
        className={`flex text-primary-5 2xl:text-lg lg:text-base sm:text-base items-center laptopitm:text-sm ${pathname === "/opportunities" ||
          pathname === "/volunteer-opportunities-list" ||
          pathname === "/development-opportunities-list"
          ? "font-bold"
          : ""
          }`}
      >
        {t("COMMON.OPPORTUNITIES")}
      </span>
        {dropdownOpen === "opportunities" ? (
          <ChevronUpIcon className="text-primary-5 font-bold text-[30px]" aria-hidden="true" />
        ) : (
          <ChevronDownIcon className="text-primary-5 font-bold text-[30px]" aria-hidden="true" />
        )}
      </button>
      {dropdownOpen === "opportunities" && (
        <div className="absolute left-0 mt-2 w-[182px] rtl:w-[225px] bg-white shadow-[0px_4px_8px_3px_#00000026] rounded-[15px] py-2 top-[36px] z-50">
          <ul>
            <li className="px-4 py-2 hover:bg-[#F5F5F5] mx-2 rounded-xl flex items-center gap-2 h-12 text-lg font-bold text-secondary-101">
              <Link href="/volunteer-opportunities-list" className="w-full" onClick={close}>
                {t("COMMON.VOLUNTEER")}
              </Link>
            </li>
            <li className="px-4 py-2 hover:bg-[#F5F5F5] mx-2 rounded-xl flex items-center gap-2 h-12 text-lg font-bold text-secondary-101">
              <Link href="/development-opportunities-list" className="w-full" onClick={close}>
                {t("COMMON.LEARN_SHARE")}
              </Link>
            </li>
          </ul>
        </div>
      )}
    </li>

    <li
      className={`flex text-primary-5 2xl:text-lg lg:text-base laptopitm:text-sm sm:text-base items-center ${pathname === "/events-and-activities" ||
        pathname === "/event-exhibition-list" ||
        pathname === "/event-sports-list" ||
        pathname === "/event-camps-list"
        ? "font-bold"
        : ""
        }`}
    >
      <Link href="/events-and-activities" onClick={close}>
        {t("COMMON.EVENTS_ACTIVITIES")}
      </Link>
    </li>

    <li
      className={`flex text-primary-5 2xl:text-lg lg:text-base laptopitm:text-sm sm:text-base items-center ${pathname === "/achievements" ? "font-bold" : ""
        }`}
    >
      <Link href="/achievements" onClick={close}>
        {t("COMMON.ACHIEVEMENTS")}
      </Link>
    </li>

    <li
      className={`flex text-primary-5 2xl:text-lg laptopitm:text-sm lg:text-base sm:text-base items-center ${pathname === "/community" ? "font-bold" : ""
        }`}
    >
      <Link href="/community" onClick={close}>
        {t("COMMON.FORSA.COMMUNITY-")}
      </Link>
    </li>

    {/* More dropdown */}
    <li
      className={`cursor-pointer flex text-primary-5 2xl:text-lg laptopitm:text-sm lg:text-base sm:text-base relative ${["/more-profile", "/partner", "/about-us", "/contact-us", "/faq"].includes(pathname)
        ? "font-bold"
        : ""
        }`}
    >
      <button
        className="text-primary-5 2xl:text-lg laptopitm:text-sm lg:text-base sm:text-base flex gap-1 items-center focus:outline-none"
        aria-label={t("COMMON.TOGGLE_MORE_MENU") || "Toggle more menu"}
        aria-expanded={dropdownOpen === "more"}
        onClick={() => setDropdownOpen(dropdownOpen === "more" ? null : "more")}
      >
        {t("COMMON.MORE")}
        {dropdownOpen === "more" ? (
          <ChevronUpIcon className="text-primary-5 font-bold text-[30px]" aria-hidden="true" />
        ) : (
          <ChevronDownIcon className="text-primary-5 font-bold text-[30px]" aria-hidden="true" />
        )}
      </button>
      {dropdownOpen === "more" && (
        <ul className="absolute left-0 mt-2 bg-white shadow-[0px_4px_8px_3px_#00000026] rounded-[15px] py-2 top-[36px] w-[190px] rtl:w-[235px] z-50">
          <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="/more-profile" className="flex items-center gap-3 w-full" onClick={close}>
              <Image src="/assets/auth/profileimg.svg" alt="" width={24} height={24} className="w-6 h-6 object-contain" unoptimized />
              {t("COMMON.PROFILES")}
            </Link>
          </li>
          <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="/partner" className="flex items-center gap-3 w-full" onClick={close}>
              <Image src="/assets/auth/partners.svg" alt="" width={24} height={24} className="w-6 h-6 object-contain" unoptimized />
              {t("COMMON.PARTNERS")}
            </Link>
          </li>
          <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="/about-us" className="flex items-center gap-3 w-full" onClick={close}>
              <Image src="/assets/auth/aboutus.svg" alt="" width={24} height={24} className="w-6 h-6 object-contain" unoptimized />
              {t("COMMON.ABOUT_US")}
            </Link>
          </li>
          <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="/contact-us" className="flex items-center gap-3 w-full" onClick={close}>
              <Image src="/assets/auth/contactus.svg" alt="" width={24} height={24} className="w-6 h-6 object-contain" unoptimized />
              {t("COMMON.CONTACT_US")}
            </Link>
          </li>
        </ul>
      )}
    </li>
  </ul>
  );
}
