// @design-system: feedback/EmptyState
/**
 * EmptyState - empty list / zero-data state.
 *
 * @example
 * <EmptyState
 *   title={t('title')}
 *   description={t('description')}
 *   action={<Button onClick={refetch}>{t('retry')}</Button>}
 * />
 */

import { type ReactNode } from 'react';
import { cn } from '@/lib/cn';

export interface EmptyStateProps {
  /** Optional large illustration (~140px). Takes precedence over icon when both set. */
  illustration?: ReactNode;
  /** Optional icon node. Use <Icon> from icons/ or a placeholder <span aria-hidden>. */
  icon?: ReactNode;
  title: string;
  description?: string;
  /** Optional call-to-action node (e.g. a <Button>). */
  action?: ReactNode;
  /** Heading level for the title. Defaults to h3 for embedded empty states. */
  titleLevel?: 1 | 2 | 3;
  className?: string;
}

export function EmptyState({
  illustration,
  icon,
  title,
  description,
  action,
  titleLevel = 3,
  className,
}: EmptyStateProps) {
  const Title = `h${titleLevel}` as const;

  return (
    <div
      role="status"
      className={cn(
        'flex flex-col items-center justify-center text-center',
        'gap-3',
        'px-6 py-10',
        className,
      )}
    >
      {illustration ? (
        <div
          className="bg-brand-primary-50 ring-brand-primary-100 flex size-35 items-center justify-center rounded-full ring-1"
          aria-hidden="true"
        >
          {illustration}
        </div>
      ) : icon ? (
        <span
          className="text-brand-primary-700 flex size-[4.5rem] items-center justify-center rounded-full bg-[radial-gradient(circle_at_30%_30%,var(--color-brand-primary-50),var(--color-brand-primary-100))] ring-1 ring-[var(--color-brand-primary-200)]"
          aria-hidden="true"
        >
          {icon}
        </span>
      ) : null}
      <Title className="text-text-primary text-lg leading-[var(--line-height-tight)] font-bold">
        {title}
      </Title>
      {description && (
        <p className="text-text-secondary max-w-xs text-sm leading-[var(--line-height-normal)]">
          {description}
        </p>
      )}
      {action && <div className="mt-2">{action}</div>}
    </div>
  );
}
