import React from 'react'
import { toast, ToastOptions } from 'react-toastify'
import { FiBell, FiCheck, FiX, FiCreditCard } from 'react-icons/fi'
import { NotificationType } from '../types/notification'

function getNotificationIcon(type: NotificationType) {
  switch (type) {
    case 'refund-request':
      return <FiCreditCard className="w-5 h-5 text-blue-500" />
    case 'approved-refund':
      return <FiCheck className="w-5 h-5 text-green-500" />
    case 'rejected-refund':
      return <FiX className="w-5 h-5 text-red-500" />
    default:
      return <FiBell className="w-5 h-5 text-gray-500" />
  }
}

interface NotificationToastProps {
  title: string
  message: string
  type: NotificationType
}

function NotificationToast({ title, message, type }: NotificationToastProps) {
  return (
    <div className="flex items-start gap-3">
      <div className="flex-shrink-0 mt-0.5">{getNotificationIcon(type)}</div>
      <div className="flex-1 min-w-0">
        <p className="text-sm font-medium text-gray-900">{title}</p>
        <p className="text-sm text-gray-600 mt-1 line-clamp-2">{message}</p>
      </div>
    </div>
  )
}

export function showNotificationToast(
  title: string,
  message: string,
  type: NotificationType,
  options?: ToastOptions,
) {
  const toastOptions: ToastOptions = {
    position: 'top-right',
    autoClose: 5000,
    hideProgressBar: false,
    closeOnClick: true,
    pauseOnHover: true,
    draggable: true,
    ...options,
  }

  toast(
    <NotificationToast title={title} message={message} type={type} />,
    toastOptions,
  )
}
