import type { ReactNode } from 'react';
import { Card, CardContent, CardHeader } from '@/components/ui/card';

type Props = {
    title: string;
    description?: ReactNode;
    /** Shown at the end of the title row. */
    aside?: ReactNode;
    className?: string;
    children: ReactNode;
};

/** A titled card that groups related fields of an admin form. */
export function FormSection({
    title,
    description,
    aside,
    className,
    children,
}: Props) {
    return (
        <Card className={className}>
            <CardHeader>
                <div className="flex flex-wrap items-center justify-between gap-2">
                    <h2 className="leading-none font-semibold">{title}</h2>
                    {aside}
                </div>
                {description && (
                    <p className="text-sm text-muted-foreground">
                        {description}
                    </p>
                )}
            </CardHeader>
            <CardContent className="grid grid-cols-1 gap-6">
                {children}
            </CardContent>
        </Card>
    );
}
