"use client"

import Link from "next/link"
import {
  MessageCircle,
  PlusCircle,
  Newspaper,
  Truck,
  Users,
  Trophy,
  ClipboardList,
  GraduationCap,
  Info,
  Cookie,
  ShieldCheck,
  FileText,
  type LucideIcon,
} from "lucide-react"
import { Drawer, DrawerContent, DrawerClose, DrawerTitle, DrawerDescription } from "@/components/ui/drawer"
import { useToast } from "@/hooks/use-toast"

interface MoreMenuModalProps {
  open: boolean
  onOpenChange: (open: boolean) => void
}

interface MenuItem {
  href?: string
  label: string
  icon: LucideIcon
  iconClass: string
  comingSoon?: boolean
}

const mainItems: MenuItem[] = [
  { href: "/chat", label: "Chat", icon: MessageCircle, iconClass: "bg-blue-100 text-blue-600" },
  { href: "/add-service", label: "Add Service", icon: PlusCircle, iconClass: "bg-purple-100 text-purple-600" },
  { href: "/blog", label: "Blog", icon: Newspaper, iconClass: "bg-indigo-100 text-indigo-600" },
  { href: "/delivery-men", label: "Delivery Men", icon: Truck, iconClass: "bg-emerald-100 text-emerald-600" },
  { href: "/my-referees", label: "My Referees", icon: Users, iconClass: "bg-orange-100 text-orange-600" },
  { href: "/quiz-leaderboard", label: "Quiz Leaders", icon: Trophy, iconClass: "bg-amber-100 text-amber-600" },
  { href: "/survey", label: "Survey", icon: ClipboardList, iconClass: "bg-cyan-100 text-cyan-600" },
  { label: "Digital Courses", icon: GraduationCap, iconClass: "bg-rose-100 text-rose-600", comingSoon: true },
]

const legalItems: MenuItem[] = [
  { href: "/about-us", label: "About Us", icon: Info, iconClass: "bg-slate-100 text-slate-600" },
  { href: "/cookie-policy", label: "Cookie Policy", icon: Cookie, iconClass: "bg-slate-100 text-slate-600" },
  { href: "/privacy-policy", label: "Privacy Policy", icon: ShieldCheck, iconClass: "bg-slate-100 text-slate-600" },
  { href: "/terms", label: "Terms", icon: FileText, iconClass: "bg-slate-100 text-slate-600" },
]

export function MoreMenuModal({ open, onOpenChange }: MoreMenuModalProps) {
  const { toast } = useToast()

  const renderItem = (item: MenuItem) => {
    const Icon = item.icon
    const content = (
      <>
        <div
          className={`flex h-11 w-11 items-center justify-center rounded-full ${item.iconClass} transition-transform group-hover:scale-110`}
        >
          <Icon className="h-5 w-5" />
        </div>
        <span className="text-center text-[11px] font-semibold leading-tight text-slate-700">
          {item.label}
        </span>
      </>
    )

    if (item.comingSoon) {
      return (
        <button
          key={item.label}
          type="button"
          onClick={() => {
            onOpenChange(false)
            toast({ title: "Coming Soon", description: "Digital Courses are on the way. Stay tuned!" })
          }}
          className="group flex min-h-[100px] flex-col items-center justify-center gap-2 rounded-2xl border border-slate-100 bg-white p-3 shadow-sm transition-all hover:border-slate-200 hover:shadow-md active:scale-[0.97]"
        >
          {content}
        </button>
      )
    }

    return (
      <DrawerClose asChild key={item.href}>
        <Link
          href={item.href!}
          className="group flex min-h-[100px] flex-col items-center justify-center gap-2 rounded-2xl border border-slate-100 bg-white p-3 shadow-sm transition-all hover:border-slate-200 hover:shadow-md active:scale-[0.97]"
        >
          {content}
        </Link>
      </DrawerClose>
    )
  }

  return (
    <Drawer open={open} onOpenChange={onOpenChange}>
      <DrawerContent className="rounded-t-[32px]">
        <DrawerTitle className="sr-only">More</DrawerTitle>
        <DrawerDescription className="sr-only">Explore more pages</DrawerDescription>
        <div className="max-h-[75vh] overflow-y-auto px-4 pb-8">
          <div className="mx-auto w-full max-w-sm pt-2">
            <div className="grid grid-cols-3 gap-3">
              {mainItems.map(renderItem)}
            </div>

            <div className="my-5 h-px bg-slate-100" />

            <div className="grid grid-cols-2 gap-3">
              {legalItems.map(renderItem)}
            </div>
          </div>
        </div>
      </DrawerContent>
    </Drawer>
  )
}
