'use client' import { useRouter, usePathname, useSearchParams } from 'next/navigation' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Search, X } from 'lucide-react' import { useTransition } from 'react' interface Group { id: string name: string } interface MachinesFilterProps { allTags: string[] groups: Group[] currentSearch: string currentTag: string currentGroup: string onlineCount: number totalCount: number } export function MachinesFilter({ allTags, groups, currentSearch, currentTag, currentGroup, onlineCount, totalCount, }: MachinesFilterProps) { const router = useRouter() const pathname = usePathname() const searchParams = useSearchParams() const [, startTransition] = useTransition() const update = (key: string, value: string) => { const params = new URLSearchParams(searchParams.toString()) if (value) params.set(key, value) else params.delete(key) startTransition(() => router.push(`${pathname}?${params.toString()}`)) } const clearAll = () => { startTransition(() => router.push(pathname)) } const hasFilters = currentSearch || currentTag || currentGroup return (
update('q', e.target.value)} className="pl-8" />
{groups.length > 0 && ( )}
{onlineCount} online / {totalCount} total
{/* Tag filter pills */} {allTags.length > 0 && (
Filter: {allTags.map(tag => ( update('tag', currentTag === tag ? '' : tag)} > {tag} ))} {hasFilters && ( )}
)}
) }