import type { ReactNode } from 'react';

import { cn } from '@/lib/utils';

/** Settings section: header (title + muted description) and a body. Destructive sections use a danger border. */
export function SectionCard({
  title,
  description,
  action,
  danger = false,
  children,
  className,
}: {
  title: string;
  description?: ReactNode;
  action?: ReactNode;
  danger?: boolean;
  children: ReactNode;
  className?: string;
}) {
  return (
    <section className={cn('rounded-xl border bg-surface shadow-xs', danger ? 'border-danger/40' : 'border-border', className)}>
      <header className={cn('flex flex-wrap items-start justify-between gap-3 border-b px-5 py-4 md:px-6', danger ? 'border-danger/20 bg-danger-soft/50' : 'border-border')}>
        <div className="min-w-0">
          <h3 className={cn('font-display text-h3 font-bold', danger && 'text-danger')}>{title}</h3>
          {description === undefined ? null : <p className="mt-0.5 text-small text-muted-foreground">{description}</p>}
        </div>
        {action}
      </header>
      <div className="px-5 py-5 md:px-6">{children}</div>
    </section>
  );
}
