import Link from 'next/link'
import { ArrowRight } from 'lucide-react'

interface SectionHeadingProps {
  eyebrow?: string
  title: string
  subtitle?: string
  action?: { href: string; label: string }
  // modern: bold, left-aligned with an accent bar · premium: heavy display
  // type over a hairline, dark pill action
  variant?: 'modern' | 'premium'
  // For sections whose title is a heading of the page outline
  as?: 'h2' | 'h3'
}

export default function SectionHeading({
  eyebrow,
  title,
  subtitle,
  action,
  variant = 'modern',
  as: Heading = 'h2',
}: SectionHeadingProps) {
  if (variant === 'premium') {
    return (
      <div className="mb-8 sm:mb-10 flex flex-wrap items-end justify-between gap-5 border-b border-gray-200 pb-5">
        <div className="flex max-w-3xl flex-col gap-2">
          {eyebrow && (
            <span className="text-[11px] font-bold uppercase tracking-[0.3em] text-primary">{eyebrow}</span>
          )}
          <Heading className="text-3xl sm:text-4xl lg:text-5xl font-black tracking-tight leading-[1.05] text-dark text-balance">
            {title}
          </Heading>
          {subtitle && <p className="text-gray-custom text-pretty">{subtitle}</p>}
        </div>
        {action && (
          <Link
            href={action.href}
            className="group inline-flex h-11 items-center gap-3 rounded-full bg-dark ps-5 pe-1.5 text-sm font-semibold text-white transition-colors hover:bg-primary"
          >
            {action.label}
            <span className="flex h-8 w-8 items-center justify-center rounded-full bg-white/15 transition-transform group-hover:translate-x-0.5 rtl:group-hover:-translate-x-0.5">
              <ArrowRight size={15} className="rtl:rotate-180" />
            </span>
          </Link>
        )}
      </div>
    )
  }

  return (
    <div className="flex flex-wrap items-end justify-between gap-4 mb-6 sm:mb-8">
      <div className="flex flex-col gap-2">
        {eyebrow && (
          <span className="inline-flex items-center gap-2 text-xs font-bold uppercase tracking-[0.2em] text-primary">
            <span className="h-1.5 w-6 rounded-full bg-primary" aria-hidden />
            {eyebrow}
          </span>
        )}
        <Heading className="text-2xl sm:text-3xl lg:text-4xl font-extrabold tracking-tight text-dark text-balance">
          {title}
        </Heading>
        {subtitle && <p className="text-gray-custom max-w-2xl text-pretty">{subtitle}</p>}
      </div>
      {action && (
        <Link
          href={action.href}
          className="group inline-flex items-center gap-2 rounded-full border border-gray-200 bg-white px-4 py-2 text-sm font-semibold text-dark hover:border-primary hover:text-primary transition-colors"
        >
          {action.label}
          <ArrowRight size={16} className="rtl:rotate-180 transition-transform group-hover:translate-x-0.5 rtl:group-hover:-translate-x-0.5" />
        </Link>
      )}
    </div>
  )
}
