import { usePage } from '@inertiajs/react';

import type { AppPageProps } from '@/types';

export function FlashMessage() {
    const { flash } = usePage<AppPageProps>().props;

    if (!flash.success && !flash.error) {
        return null;
    }

    return (
        <div className="space-y-3">
            {flash.success ? (
                <div className="rounded-lg border border-success/30 bg-success/10 px-4 py-3 text-sm text-success">
                    {flash.success}
                </div>
            ) : null}
            {flash.error ? (
                <div className="rounded-lg border border-danger/30 bg-danger/10 px-4 py-3 text-sm text-danger">
                    {flash.error}
                </div>
            ) : null}
        </div>
    );
}
