"use client"; import Link from "next/link"; import { T } from "@/components/TranslatedText"; import { useState, useEffect, useMemo } from "react"; interface Project { id: string; title: string; category: string; location: string | null; description: string | null; coverImage: string | null; status: string; } export default function ProjetosPage() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [searchTerm, setSearchTerm] = useState(""); const [selectedCategory, setSelectedCategory] = useState(null); useEffect(() => { async function fetchProjects() { try { const res = await fetch("/api/projects", { cache: "no-store" }); if (res.ok) { const data = await res.json(); // Mostrar todos os projetos (status pode ser "Em andamento" ou "Concluído") setProjects(data); } } catch (error) { console.error("Erro ao carregar projetos:", error); } finally { setLoading(false); } } fetchProjects(); }, []); // Extrair categorias únicas dos projetos const categories = useMemo(() => { const cats = new Set(); projects.forEach((p) => { if (p.category) cats.add(p.category); }); return Array.from(cats); }, [projects]); // Filtrar projetos por categoria e pesquisa const filteredProjects = useMemo(() => { return projects.filter((project) => { const matchesCategory = !selectedCategory || project.category === selectedCategory; const matchesSearch = !searchTerm || project.title.toLowerCase().includes(searchTerm.toLowerCase()) || project.description?.toLowerCase().includes(searchTerm.toLowerCase()) || project.category?.toLowerCase().includes(searchTerm.toLowerCase()) || project.location?.toLowerCase().includes(searchTerm.toLowerCase()); return matchesCategory && matchesSearch; }); }, [projects, selectedCategory, searchTerm]); const defaultImage = "https://images.unsplash.com/photo-1504307651254-35680f356dfd?q=80&w=2070&auto=format&fit=crop"; return (
{/* Hero Section */}

Nossos Projetos

Conheça alguns dos projetos que já realizamos para nossos clientes

{/* Projects Grid */}
{/* Search Bar */}
setSearchTerm(e.target.value)} className="w-full px-5 py-3 pl-12 rounded-full border border-gray-200 dark:border-white/20 bg-white dark:bg-white/5 text-secondary dark:text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all" /> {searchTerm && ( )}
{/* Category Filters */}
{categories.map((category) => ( ))}
{/* Loading State */} {loading && (
)} {/* Empty State */} {!loading && filteredProjects.length === 0 && (

Nenhum projeto encontrado

{searchTerm || selectedCategory ? ( Tente ajustar os filtros de busca ) : ( Em breve adicionaremos novos projetos )}

{(searchTerm || selectedCategory) && ( )}
)} {/* Projects Grid */} {!loading && filteredProjects.length > 0 && (
{filteredProjects.map((project) => (
{project.category && (
{project.category}
)}

{project.title}

{project.location && (
{project.location}
)} {project.description && (

{project.description}

)} Ver Detalhes
))}
)} {/* Results Count */} {!loading && filteredProjects.length > 0 && (
Exibindo {filteredProjects.length} de {projects.length} projetos
)}
); }