import React from 'react'
import { AlertCircle, Info, AlertTriangle, CircleCheck } from 'lucide-react'
import {
  Dialog,
  DialogContent,
  DialogTitle,
  DialogDescription,
} from '@/components/shadcn/ui/dialog'

export type AlertType = 'success' | 'error' | 'info' | 'warning'

export interface AlertOptions {
  /**
   * The title of the alert
   */
  title: string
  /**
   * The description of the alert
   */
  description: string
  /**
   * The type of alert
   */
  type?: AlertType
  /**
   * Optional custom icon to override the default
   */
  icon?: React.ReactNode
}

export interface ModalAlertProps extends AlertOptions {
  /**
   * Whether the modal is open
   */
  open: boolean
  /**
   * Function to set the open state
   */
  onOpenChange: (open: boolean) => void
}

// Icon and color mapping based on alert type
const alertConfig = {
  success: {
    icon: <CircleCheck className="h-14 w-14" />,
    iconColor: 'text-green-500',
    titleColor: 'text-green-700',
  },
  error: {
    icon: <AlertCircle className="h-14 w-14" />,
    iconColor: 'text-red-500',
    titleColor: 'text-red-700',
  },
  info: {
    icon: <Info className="h-14 w-14" />,
    iconColor: 'text-blue-500',
    titleColor: 'text-blue-700',
  },
  warning: {
    icon: <AlertTriangle className="h-14 w-14" />,
    iconColor: 'text-yellow-500',
    titleColor: 'text-yellow-700',
  },
}

export const ModalAlert: React.FC<ModalAlertProps> = ({
  open,
  title,
  description,
  icon,
  type = 'info',
  onOpenChange,
}) => {
  const config = alertConfig[type]

  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className={`sm:max-w-md animate-out duration-300`}>
        <div className="p-6 flex flex-col items-center text-center">
          {/* Large centered icon */}
          <div
            className={`${config.iconColor} h-16 w-16 mx-auto mb-5 flex items-center justify-center rounded-full`}
          >
            {icon || config.icon}
          </div>

          {/* Title and description */}
          <DialogTitle
            className={`text-xl font-bold ${config.titleColor} mb-3`}
          >
            {title}
          </DialogTitle>
          <DialogDescription className="text-gray-600 text-base">
            {description}
          </DialogDescription>
        </div>
      </DialogContent>
    </Dialog>
  )
}
