'use client';

import Link from 'next/link';
import { usePathname } from 'next/navigation';

export default function ActiveLink({ href, children, className = '', activeClassName = 'active', exact = false, ...props }) {
  const pathname = usePathname();
  const isActive = exact ? pathname === href : pathname === href || pathname?.startsWith(`${href}/`);
  const resolvedClassName = [className, isActive ? activeClassName : ''].filter(Boolean).join(' ');

  return (
    <Link href={href} className={resolvedClassName || undefined} {...props}>
      {children}
    </Link>
  );
}
