"use client" import { useState, useRef } from "react" import Link from "next/link" import { Search, Sparkles, ChevronLeft, ChevronRight } from "lucide-react" import { ToolDefinition } from "@/lib/tools" import { DynamicIcon } from "@/components/ui/dynamic-icon" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Badge } from "@/components/ui/badge" import { Card, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { cn } from "@/lib/utils" interface ToolsBrowserProps { tools: ToolDefinition[] categories: string[] } export function ToolsBrowser({ tools, categories }: ToolsBrowserProps) { const [selectedCategory, setSelectedCategory] = useState("All") const [searchQuery, setSearchQuery] = useState("") const scrollContainerRef = useRef(null) const scroll = (direction: 'left' | 'right') => { if (scrollContainerRef.current) { const scrollAmount = 300 const currentScroll = scrollContainerRef.current.scrollLeft scrollContainerRef.current.scrollTo({ left: direction === 'left' ? currentScroll - scrollAmount : currentScroll + scrollAmount, behavior: 'smooth' }) } } // Filter tools based on search and category const filteredTools = tools.filter(tool => { const matchesCategory = selectedCategory === "All" || tool.category === selectedCategory const matchesSearch = tool.name.toLowerCase().includes(searchQuery.toLowerCase()) || tool.description.toLowerCase().includes(searchQuery.toLowerCase()) return matchesCategory && matchesSearch }) // Group for "All" view const displayCategories = selectedCategory === "All" ? categories : [selectedCategory] return (
{/* Controls Section */}
{/* Search */}
setSearchQuery(e.target.value)} />
{/* Filter Pills - Managed Scroll */}
{categories.map((category) => ( ))}
{/* Tools Grid */}
{filteredTools.length === 0 ? (

No tools found matching your criteria.

) : ( displayCategories.map((category) => { // In "All" view, valid tools are those belonging to the current category iteration // AND matching the search query. // In specific view, 'filteredTools' already contains only the right tools. const categoryTools = selectedCategory === "All" ? filteredTools.filter(t => t.category === category) : filteredTools if (categoryTools.length === 0) return null return (

{category} {categoryTools.length}

{categoryTools.map((tool) => (
{tool.isPremium && ( PRO )}
{tool.name} {tool.description}
))}
) }) )}
{/* Footer Stats */}
Showing {filteredTools.length} of {tools.length} available tools
) }