"use client"; import { useDeferredValue, useMemo, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import type { Course } from "@/lib/types"; import { courseCategories } from "@/lib/site-config"; import { formatCoursePrice, formatLabel } from "@/lib/labels"; import { cn } from "@/lib/utils"; export function CategoryCourseExplorer({ courses, findLabel, }: { courses: Course[]; findLabel: string; }) { const [query, setQuery] = useState(""); const [category, setCategory] = useState("all"); const deferredQuery = useDeferredValue(query); const isStale = query !== deferredQuery; const filtered = useMemo(() => { return courses.filter((course) => { const matchesCategory = category === "all" || category === "best" || course.category === category; const matchesQuery = !deferredQuery || course.title.includes(deferredQuery) || course.summary.includes(deferredQuery); return matchesCategory && matchesQuery; }); }, [courses, category, deferredQuery]); return (
e.preventDefault()} role="search" > setQuery(e.target.value)} placeholder={findLabel} className="h-11 flex-1 border-border bg-background text-foreground placeholder:text-muted-foreground" />
{courseCategories.map((item) => ( ))}
{filtered.map((course) => { const priceLabel = formatCoursePrice(course.price); return (
{course.title}
{course.title} {course.summary}
{course.durationHours} ساعت · {formatLabel(course.format)} {priceLabel ? ( {priceLabel} ) : null}
جزئیات و ثبت‌نام
); })}
); }