import { nbspDash } from '@/shared/lib/typography'
import { cn } from '@/shared/lib/utils'
import type { ReactNode } from 'react'
import { Reveal } from './motion'

const typograph = (node: ReactNode) =>
  typeof node === 'string' ? nbspDash(node) : node

export const SectionHeading = ({
  eyebrow,
  title,
  description,
  align = 'center',
  className
}: {
  eyebrow: string
  title: ReactNode
  description?: ReactNode
  align?: 'center' | 'left'
  className?: string
}) => (
  <Reveal
    className={cn(
      'max-w-2xl',
      align === 'center' && 'mx-auto text-center',
      className
    )}
  >
    <p className='inline-flex items-center rounded-full border border-primary/20 bg-primary/10 px-3 py-1 text-xs font-semibold uppercase tracking-wider text-primary'>
      {eyebrow}
    </p>
    <h2 className='mt-4 font-display text-3xl font-semibold tracking-tight text-balance sm:text-4xl lg:text-5xl'>
      {typograph(title)}
    </h2>
    {description && (
      <p className='mt-4 text-lg text-muted-foreground text-pretty'>
        {typograph(description)}
      </p>
    )}
  </Reveal>
)
