'use client'

import { useTranslations } from 'next-intl'
import { FaFacebookF, FaInstagram, FaLinkedinIn, FaGlobe } from 'react-icons/fa'
import { FaXTwitter } from 'react-icons/fa6'
import type { BlogAuthorProfile } from '@/lib/db/queries/getBlogPosts'

interface AuthorSocialLinksProps {
  author: BlogAuthorProfile
  // 'light' for white-on-gradient (hero), 'default' for cards
  variant?: 'default' | 'light'
}

export default function AuthorSocialLinks({ author, variant = 'default' }: AuthorSocialLinksProps) {
  const t = useTranslations('BlogPage')

  const links = [
    { url: author.website, Icon: FaGlobe, network: t('website') },
    { url: author.facebook, Icon: FaFacebookF, network: 'Facebook' },
    { url: author.twitter, Icon: FaXTwitter, network: 'X' },
    { url: author.instagram, Icon: FaInstagram, network: 'Instagram' },
    { url: author.linkedin, Icon: FaLinkedinIn, network: 'LinkedIn' },
  ].filter((l): l is { url: string; Icon: typeof FaGlobe; network: string } => !!l.url)

  if (links.length === 0) return null

  const itemClass = variant === 'light'
    ? 'bg-white/15 text-white hover:bg-white hover:text-primary border border-white/20'
    : 'bg-gray-100 text-dark hover:bg-primary hover:text-white'

  return (
    <ul className="flex flex-wrap items-center gap-2">
      {links.map(({ url, Icon, network }) => (
        <li key={network}>
          <a
            href={url}
            target="_blank"
            rel="noopener noreferrer nofollow"
            aria-label={t('profileOn', { name: author.name, network })}
            title={network}
            className={`w-9 h-9 rounded-full flex items-center justify-center transition ${itemClass}`}
          >
            <Icon size={14} />
          </a>
        </li>
      ))}
    </ul>
  )
}
