import type { ReactNode } from 'react';

import { Card } from '@/components/ui/card';
import { cn } from '@/lib/utils';

/** Card with a consistent header row used by every dashboard panel. */
export function DashCard({
  title,
  caption,
  action,
  children,
  className,
}: {
  title: string;
  caption?: ReactNode;
  action?: ReactNode;
  children: ReactNode;
  className?: string;
}) {
  return (
    <Card className={cn('flex h-full flex-col p-5 md:p-6', className)}>
      <div className="flex items-start justify-between gap-3">
        <div className="min-w-0">
          <h2 className="font-display text-h3 font-bold text-foreground">{title}</h2>
          {caption === undefined ? null : <div className="mt-0.5 text-small text-muted-foreground">{caption}</div>}
        </div>
        {action}
      </div>
      <div className="mt-5 flex min-h-0 flex-1 flex-col">{children}</div>
    </Card>
  );
}
