File size: 10,208 Bytes
bcce530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"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<string>("All")
    const [searchQuery, setSearchQuery] = useState("")
    const scrollContainerRef = useRef<HTMLDivElement>(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 (
        <div className="space-y-8">
            {/* Controls Section */}
            <div className="flex flex-col md:flex-row gap-6 items-center justify-between">
                {/* Search */}
                <div className="relative w-full md:w-96">
                    <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
                    <Input
                        placeholder="Search tools..."
                        className="pl-10 h-11 glass"
                        value={searchQuery}
                        onChange={(e) => setSearchQuery(e.target.value)}
                    />
                </div>

                {/* Filter Pills - Managed Scroll */}
                <div className="relative w-full md:w-auto flex-1 min-w-0 flex items-center gap-2">
                    <Button
                        variant="ghost"
                        size="icon"
                        className="hidden md:flex shrink-0 h-8 w-8 rounded-full"
                        onClick={() => scroll('left')}
                    >
                        <ChevronLeft className="h-4 w-4" />
                    </Button>

                    <div
                        ref={scrollContainerRef}
                        className="flex gap-2 overflow-x-auto pb-4 md:pb-0 scrollbar-hide mask-fade no-scrollbar"
                        id="categories-container"
                        style={{ scrollbarWidth: 'none', msOverflowStyle: 'none' }}
                    >
                        <Button
                            variant={selectedCategory === "All" ? "gradient" : "outline"}
                            size="sm"
                            onClick={() => setSelectedCategory("All")}
                            className={cn(
                                "rounded-full whitespace-nowrap transition-all duration-300",
                                selectedCategory === "All" ? "btn-glow" : "hover:bg-primary/10"
                            )}
                        >
                            All Tools
                        </Button>
                        {categories.map((category) => (
                            <Button
                                key={category}
                                variant={selectedCategory === category ? "gradient" : "outline"}
                                size="sm"
                                onClick={() => setSelectedCategory(category)}
                                className={cn(
                                    "rounded-full capitalize whitespace-nowrap transition-all duration-300",
                                    selectedCategory === category ? "btn-glow" : "hover:bg-primary/10"
                                )}
                            >
                                {category}
                            </Button>
                        ))}
                    </div>

                    <Button
                        variant="ghost"
                        size="icon"
                        className="hidden md:flex shrink-0 h-8 w-8 rounded-full"
                        onClick={() => scroll('right')}
                    >
                        <ChevronRight className="h-4 w-4" />
                    </Button>
                </div>
            </div>

            {/* Tools Grid */}
            <div className="space-y-12">
                {filteredTools.length === 0 ? (
                    <div className="text-center py-20 text-muted-foreground">
                        <div className="inline-flex h-12 w-12 items-center justify-center rounded-full bg-muted mb-4">
                            <Search className="h-6 w-6" />
                        </div>
                        <p className="text-lg">No tools found matching your criteria.</p>
                        <Button
                            variant="link"
                            onClick={() => {
                                setSelectedCategory("All")
                                setSearchQuery("")
                            }}
                        >
                            Clear filters
                        </Button>
                    </div>
                ) : (
                    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 (
                            <div key={category} className="animate-fade-in">
                                <h2 className="text-2xl font-serif font-medium mb-6 capitalize flex items-center gap-3">
                                    <span className="text-gradient">{category}</span>
                                    <Badge variant="secondary" className="glass bg-primary/5 text-primary ml-2">
                                        {categoryTools.length}
                                    </Badge>
                                </h2>

                                <div className="grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-5">
                                    {categoryTools.map((tool) => (
                                        <Link key={tool.slug} href={`/tools/${tool.slug}`}>
                                            <Card className="h-full glass hover:border-primary/50 transition-all cursor-pointer group hover:-translate-y-1 hover:shadow-lg hover:shadow-primary/5">
                                                <CardHeader className="pb-3">
                                                    <div className="flex items-start justify-between mb-3">
                                                        <span className="bg-linear-to-br from-white/10 to-white/5 p-2 rounded-xl border border-white/5">
                                                            <DynamicIcon name={tool.icon} className="h-8 w-8 text-white" />
                                                        </span>
                                                        {tool.isPremium && (
                                                            <Badge variant="default" className="bg-linear-to-r from-yellow-500 to-orange-500 shadow-lg shadow-orange-500/20">
                                                                PRO
                                                            </Badge>
                                                        )}
                                                    </div>
                                                    <CardTitle className="text-lg group-hover:text-primary transition-colors line-clamp-1">
                                                        {tool.name}
                                                    </CardTitle>
                                                    <CardDescription className="line-clamp-2 leading-relaxed">
                                                        {tool.description}
                                                    </CardDescription>
                                                </CardHeader>
                                            </Card>
                                        </Link>
                                    ))}
                                </div>
                            </div>
                        )
                    })
                )}
            </div>

            {/* Footer Stats */}
            <div className="mt-16 text-center border-t border-border/50 pt-8">
                <div className="inline-flex items-center gap-2 px-6 py-3 bg-primary/5 rounded-full glass text-sm">
                    <Sparkles className="h-4 w-4 text-primary" />
                    <span className="font-medium text-muted-foreground">
                        Showing {filteredTools.length} of {tools.length} available tools
                    </span>
                </div>
            </div>
        </div>
    )
}