"use client";
import useCurrentLanguage from "@/hooks/useCurrentLanguage";
import { cn } from "@/lib/utils";
import Link from "next/link";
import { usePathname } from "next/navigation";

type Props = {
  href: string;
  children: React.ReactNode;
  className?: string;
  noActive?: boolean;
  onClick?: () => void;
};
const LangLink = ({ children, href, className, noActive, onClick }: Props) => {
  const { lang } = useCurrentLanguage();
  const pathname = usePathname();
  const isPathOpened =
    href === "/" ? pathname.endsWith(`/${lang}`) : pathname.endsWith(href);

  const classes = cn({
    "font-bold text-mainLime": isPathOpened && !noActive,
  });

  return (
    <Link
      onClick={onClick}
      href={`/${lang}/${href}`}
      className={` ${className ? classes + " " + className : classes}`}
    >
      {children}
    </Link>
  );
};

export default LangLink;
