"use client"; import React, { useState, useMemo } from "react"; import { useSearchParams } from "next/navigation"; import PlantCard from "@/components/PlantCard"; import EmptyState from "@/components/EmptyState"; import { plants, type Plant } from "@/data/plants"; import { PLANT_CATEGORIES } from "@/lib/constants"; type Category = Plant["category"] | "all"; /** * Client component that handles the interactive browse/search/filter logic. * Wrapped in a Suspense boundary in the parent page. */ export default function BrowseContent() { const searchParams = useSearchParams(); const initialSearch = searchParams.get("search") || ""; const [searchQuery, setSearchQuery] = useState(initialSearch); const [activeCategory, setActiveCategory] = useState("all"); const filteredPlants = useMemo(() => { let result = plants; if (activeCategory !== "all") { result = result.filter((p) => p.category === activeCategory); } const q = searchQuery.toLowerCase().trim(); if (q) { result = result.filter( (p) => p.commonName.toLowerCase().includes(q) || p.scientificName.toLowerCase().includes(q) || p.family.toLowerCase().includes(q) || p.diseases.some((d) => d.name.toLowerCase().includes(q)) ); } return result; }, [activeCategory, searchQuery]); return (
{/* Page header */}

Browse Plants

Explore our database of {plants.length} plants and their common diseases.

{/* Search bar */}
setSearchQuery(e.target.value)} className="w-full rounded-xl border border-zinc-300 dark:border-zinc-600 bg-white dark:bg-zinc-900 pl-10 pr-4 py-3 text-sm text-zinc-900 dark:text-zinc-100 placeholder-zinc-400 dark:placeholder-zinc-500 focus:outline-none focus:ring-2 focus:ring-leaf-green-500 focus:border-leaf-green-500 transition-all shadow-sm" />
{searchQuery && ( )}
{/* Category filter chips */}
{PLANT_CATEGORIES.map((cat) => ( ))}
{/* Results count */}

{filteredPlants.length === 0 ? "No plants found" : `Showing ${filteredPlants.length} ${filteredPlants.length === 1 ? "plant" : "plants"}`} {activeCategory !== "all" && ` in ${PLANT_CATEGORIES.find((c) => c.value === activeCategory)?.label.toLowerCase()}`} {searchQuery.trim() && ` matching "${searchQuery.trim()}"`}

{/* Plant grid or empty state */} {filteredPlants.length > 0 ? (
{filteredPlants.map((plant) => ( ))}
) : ( )}
); }