"use client" import { useEffect, useRef, useState } from "react" import { BrainIcon, CheckIcon, ChevronDownIcon, MoreHorizontalIcon, ZapIcon, } from "lucide-react" import { cn } from "@lib/utils" import { dmSansClassName } from "@/lib/fonts" import { reasoningOptions, type ReasoningEffort } from "@/lib/models" interface ReasoningSelectorProps { value: ReasoningEffort onChange: (value: ReasoningEffort) => void variant?: "pill" | "icon" disabled?: boolean dropdownDirection?: "up" | "down" } export function ReasoningSelector({ value, onChange, variant = "pill", disabled = false, dropdownDirection = "up", }: ReasoningSelectorProps) { const [isOpen, setIsOpen] = useState(false) const containerRef = useRef(null) const selected = reasoningOptions.find((option) => option.id === value) const SelectedIcon = value === "thinking" ? BrainIcon : ZapIcon const selectedLabel = selected?.label ?? "Reasoning" const selectedItemClass = "border border-[#267BF1]/35 bg-[#0A1A3A] text-white shadow-[inset_0_0_0_1px_rgba(75,160,250,0.08)]" useEffect(() => { if (!isOpen) return const handleClickOutside = (event: MouseEvent) => { if ( containerRef.current && !containerRef.current.contains(event.target as Node) ) { setIsOpen(false) } } document.addEventListener("mousedown", handleClickOutside) return () => document.removeEventListener("mousedown", handleClickOutside) }, [isOpen]) const handleSelect = (next: ReasoningEffort) => { onChange(next) setIsOpen(false) } return (
{isOpen && (
{reasoningOptions.map((option) => { const Icon = option.id === "thinking" ? BrainIcon : ZapIcon const isSelected = option.id === value return ( ) })}
)}
) }