'use client';

import React from 'react';
import { obfuscateEmail, deobfuscateEmail } from '@/lib/email-obfuscate';

interface ObfuscatedEmailProps {
  email: string;
  children?: React.ReactNode;
  className?: string;
}

export function ObfuscatedEmail({ email, children, className }: ObfuscatedEmailProps) {
  const obfuscated = obfuscateEmail(email);
  
  return (
    <a
      href="#"
      data-email={obfuscated}
      className={className || "obfuscated-email"}
      onClick={(e) => {
        e.preventDefault();
        const link = e.currentTarget;
        const decoded = deobfuscateEmail(obfuscated);
        link.href = `mailto:${decoded}`;
        window.location.href = link.href;
      }}
    >
      {children || email}
    </a>
  );
}
