import React from 'react';
import { Button, type ButtonProps } from '@mui/material';
import Dialog from './Dialog';

type DialogSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';

type ConfirmColor = ButtonProps['color'];

interface ConfirmationDialogProps {
  cancelText?: string;
  children?: React.ReactNode;
  confirmColor?: ConfirmColor;
  confirmText?: string;
  message?: React.ReactNode;
  onClose: () => void;
  onConfirm: () => void;
  open: boolean;
  size?: DialogSize;
  title?: string;
}

const ConfirmationDialog: React.FC<ConfirmationDialogProps> = ({
  open,
  onClose,
  onConfirm,
  title = "",
  message = "",
  children,
  confirmText = "Confirm",
  confirmColor = "secondary",
  cancelText = "Cancel",
  size = "sm"
}) => {
  const handleConfirm = () => {
    onConfirm();
    onClose();
  };

  return (
    <Dialog
      open={open}
      fullWidth
      size={size}
      onClose={onClose}
      title={title}
      actionButtons={
        <>
          <Button
            onClick={onClose}
            variant="outlined"
            color="inherit"
          >
            {cancelText}
          </Button>
          <Button
            onClick={handleConfirm}
            variant="contained"
            color={confirmColor}
            autoFocus
          >
            {confirmText}
          </Button>
        </>
      }
    >
      {message}
      {children}
    </Dialog>
  );
};

export default ConfirmationDialog;
