'use client';

import Link from 'next/link';
import { useAnalytics } from './analytics/useAnalytics';
import { AnalyticsEvents } from './analytics/analytics-events';

interface RelatedProductLinkProps {
  href: string;
  productSlug: string;
  productTitle: string;
  children: React.ReactNode;
  className?: string;
}

export function RelatedProductLink({
  href,
  productSlug,
  productTitle,
  children,
  className,
}: RelatedProductLinkProps) {
  const { trackEvent } = useAnalytics();

  return (
    <Link
      href={href}
      className={className}
      onClick={() =>
        trackEvent(AnalyticsEvents.PRODUCT_VIEW, {
          product_id: productSlug,
          product_name: productTitle,
          location: 'related_products',
        })
      }
    >
      {children}
    </Link>
  );
}
