import type { ReactNode } from 'react';

import { cn } from '@/lib/utils';

export function Container({
  children,
  className,
  width = 'marketing',
}: {
  children: ReactNode;
  className?: string;
  width?: 'marketing' | 'app' | 'prose';
}) {
  return (
    <div
      className={cn(
        'mx-auto w-full px-5 md:px-8',
        width === 'marketing' && 'max-w-marketing',
        width === 'app' && 'max-w-content',
        width === 'prose' && 'max-w-prose',
        className,
      )}
    >
      {children}
    </div>
  );
}

export function Section({
  children,
  className,
  id,
  muted = false,
}: {
  children: ReactNode;
  className?: string;
  id?: string;
  muted?: boolean;
}) {
  return (
    <section id={id} className={cn('py-14 md:py-24', muted ? 'bg-surface-muted' : 'bg-background', className)}>
      {children}
    </section>
  );
}

export function SectionHeading({
  eyebrow,
  title,
  text,
  align = 'center',
  as: Heading = 'h2',
}: {
  eyebrow?: string;
  title: ReactNode;
  text?: ReactNode;
  align?: 'center' | 'left';
  as?: 'h1' | 'h2';
}) {
  return (
    <div className={cn('max-w-2xl', align === 'center' ? 'mx-auto text-center' : 'text-left')}>
      {eyebrow === undefined ? null : (
        <p className="inline-flex rounded-pill bg-primary-soft px-3 py-1 text-caption font-semibold uppercase tracking-[0.14em] text-primary">
          {eyebrow}
        </p>
      )}
      <Heading
        className={cn(
          'mt-4 text-balance font-display font-extrabold tracking-[-0.02em] text-foreground',
          Heading === 'h1' ? 'text-[2.25rem] leading-[2.75rem] md:text-display-lg' : 'text-[1.75rem] leading-9 md:text-[2.5rem] md:leading-[3rem]',
        )}
      >
        {title}
      </Heading>
      {text === undefined ? null : (
        <p className={cn('mt-4 max-w-[560px] text-pretty text-[1.0625rem] leading-7 text-muted-foreground', align === 'center' && 'mx-auto')}>{text}</p>
      )}
    </div>
  );
}
