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

/**
 * The padded column every admin page lays its content out in. SaveBar
 * relies on these paddings to reach the edges of the page.
 */
export function PageContainer({
    className,
    children,
}: {
    className?: string;
    children: ReactNode;
}) {
    return (
        <div className={cn('flex flex-1 flex-col gap-6 p-4 md:p-6', className)}>
            {children}
        </div>
    );
}

type Props = {
    title: string;
    description?: ReactNode;
    /** Buttons and links shown at the end of the header. */
    actions?: ReactNode;
};

/** Title row of an admin page: the page's only <h1>, a summary and actions. */
export function PageHeader({ title, description, actions }: Props) {
    return (
        <header className="flex flex-wrap items-start justify-between gap-4">
            <div className="space-y-1">
                <h1 className="text-xl font-semibold tracking-tight">
                    {title}
                </h1>
                {description && (
                    <p className="max-w-2xl text-sm text-muted-foreground">
                        {description}
                    </p>
                )}
            </div>
            {actions && (
                <div className="flex flex-wrap items-center gap-2">
                    {actions}
                </div>
            )}
        </header>
    );
}
