"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";

import { userService } from "@/services";

import { useT } from "@/context/I18nContext"; 

export default function DashboardNav({ userData }) {

     const { t } = useT(); 

     const accountLinks = [
          { href: "/contul-meu", label: t("contul_meu_heading") },
     ];

	const pathname = usePathname();

     const handleLogout = (e) => {
          e.preventDefault(); 
          userService.logout(); 
     };

	return (
		<ul className='my-account-nav'>
			{accountLinks.map((link, index) => (
				<li key={index}>
					<Link
						href={link.href}
						className={`my-account-nav-item ${pathname == link.href ? "active" : ""}`}>
						{link.label}
					</Link>
				</li>
			))}
               
               {userData.marketplace === 1 && (
                    <li key={2}>
                         <Link
                              href="/contul-meu/marketplace"
                              className={`my-account-nav-item ${pathname == '/contul-meu/marketplace' ? "active" : ""}`}>
                              Marketplace
                         </Link>
                    </li>
               )}

			<li>
				<Link href="#" onClick={(e) => handleLogout(e)} className='my-account-nav-item'>
					Logout
				</Link>
			</li>
		</ul>
	);
}
