import type { ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import {
    Dialog,
    DialogContent,
    DialogDescription,
    DialogFooter,
    DialogHeader,
    DialogTitle,
} from '@/components/ui/dialog';

export type ConfirmActionModalProps = {
    open: boolean;
    onOpenChange: (open: boolean) => void;
    title: string;
    /** Texto auxiliar debajo del título (estilo descripción). */
    description?: ReactNode;
    /** Contenido adicional entre descripción y botones (resúmenes, montos, etc.). */
    children?: ReactNode;
    confirmLabel?: string;
    cancelLabel?: string;
    onConfirm: () => void;
    processing?: boolean;
    confirmVariant?: 'default' | 'destructive' | 'secondary';
};

/**
 * Diálogo reutilizable de confirmación antes de acciones sensibles (retiros, inversiones, admin…).
 */
export function ConfirmActionModal({
    open,
    onOpenChange,
    title,
    description,
    children,
    confirmLabel = 'Confirmar',
    cancelLabel = 'Cancelar',
    onConfirm,
    processing = false,
    confirmVariant = 'default',
}: ConfirmActionModalProps) {
    return (
        <Dialog open={open} onOpenChange={onOpenChange}>
            <DialogContent className="sm:max-w-md">
                <DialogHeader>
                    <DialogTitle>{title}</DialogTitle>
                    {description ? (
                        <DialogDescription className="text-left">{description}</DialogDescription>
                    ) : null}
                </DialogHeader>
                {children ? <div className="max-h-[40vh] overflow-y-auto text-sm">{children}</div> : null}
                <DialogFooter className="gap-2 sm:gap-0">
                    <Button disabled={processing} onClick={() => onOpenChange(false)} type="button" variant="ghost">
                        {cancelLabel}
                    </Button>
                    <Button
                        disabled={processing}
                        onClick={onConfirm}
                        type="button"
                        variant={confirmVariant}
                    >
                        {processing ? 'Procesando…' : confirmLabel}
                    </Button>
                </DialogFooter>
            </DialogContent>
        </Dialog>
    );
}
