import React from 'react'
import { Button, Card } from 'flowbite-react'
import { FiBell, FiCheck } from 'react-icons/fi'
import { LuFilter } from 'react-icons/lu'

import buttonTheme from '@/lib/themes/button'
import { useScreenSize } from '@/lib/hooks/useScreenSize'
import NotificationFilterModal from './NotificationFilterModal'
import { NotificationType } from '../types'

interface NotificationHeaderProps {
  unreadCount: number
  isMarkingAllAsRead: boolean
  selectedType: NotificationType | 'all'
  notificationTypes: Array<{
    value: NotificationType | 'all'
    label: string
    show: boolean
  }>
  onMarkAllAsRead: () => void
  onTypeChange: (type: NotificationType | 'all') => void
}

export default function NotificationHeader({
  unreadCount,
  isMarkingAllAsRead,
  selectedType,
  notificationTypes,
  onMarkAllAsRead,
  onTypeChange,
}: NotificationHeaderProps) {
  const screenSize = useScreenSize()
  const [isFilterModalOpen, setIsFilterModalOpen] = React.useState(false)

  return (
    <Card className="shadow-none border border-gray-200">
      <div className="flex items-center justify-between gap-4">
        <div className="flex items-center gap-4">
          <FiBell className="h-4 w-4 sm:h-6 sm:w-6 text-gray-700" />
          <h1 className="text-base sm:text-2xl font-semibold text-gray-900">
            Notifications
          </h1>
        </div>

        <div className="flex items-center gap-3">
          <Button
            color="alternative"
            size={screenSize < 475 ? 'xs' : 'sm'}
            disabled={isMarkingAllAsRead}
            className="border-gray-200 hover:border-gray-300 focus:ring-2 focus:ring-gray-100 whitespace-nowrap relative"
            onClick={() => setIsFilterModalOpen(true)}
          >
            <LuFilter className="w-4 h-4 text-blue-500" />
            {selectedType !== 'all' && (
              <div className="absolute -top-1 -right-1 w-2.5 h-2.5 bg-blue-500 rounded-full border-2 border-white" />
            )}
          </Button>

          {unreadCount > 0 && (
            <Button
              color="alternative"
              size={screenSize < 475 ? 'xs' : 'sm'}
              className="text-green-500 hover:text-green-700 focus:ring-0 whitespace-nowrap"
              theme={buttonTheme.button}
              disabled={isMarkingAllAsRead}
              onClick={onMarkAllAsRead}
            >
              <FiCheck className="mr-2 h-4 w-4" />
              {isMarkingAllAsRead ? 'Marking...' : 'Mark all as read'}
            </Button>
          )}
        </div>
      </div>

      <NotificationFilterModal
        isOpen={isFilterModalOpen}
        onClose={() => setIsFilterModalOpen(false)}
        selectedType={selectedType}
        onTypeChange={onTypeChange}
        notificationTypes={notificationTypes}
      />
    </Card>
  )
}
