"use client"

import { useRouter } from "next/navigation"
import { ChevronDown } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
    DropdownMenu,
    DropdownMenuContent,
    DropdownMenuItem,
    DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { useVertical, VERTICALS, VerticalSlug } from "@/contexts/vertical-context"

export function BandSelector() {
    const { current, setCurrent } = useVertical()
    const router = useRouter()

    const handleSelect = (slug: VerticalSlug) => {
        setCurrent(slug)
        router.push(`/${slug}`)
    }

    return (
        <DropdownMenu>
            <DropdownMenuTrigger asChild>
                <Button
                    variant="ghost"
                    className="flex items-center gap-2 font-bold text-lg"
                >
                    <span>{current.name}</span>
                    <ChevronDown className="h-4 w-4 opacity-50" />
                </Button>
            </DropdownMenuTrigger>
            <DropdownMenuContent align="start" className="w-56">
                {VERTICALS.map((vertical) => (
                    <DropdownMenuItem
                        key={vertical.slug}
                        onClick={() => handleSelect(vertical.slug)}
                        className={`cursor-pointer ${vertical.slug === current.slug ? "font-bold" : ""}`}
                    >
                        {vertical.name}
                    </DropdownMenuItem>
                ))}
            </DropdownMenuContent>
        </DropdownMenu>
    )
}
