"use client"; import Link from "next/link"; import { notFound } from "next/navigation"; import { useState, useEffect } from "react"; import { useLocale } from "@/contexts/LocaleContext"; interface Project { id: string; title: string; category: string; client: string | null; status: string; completionDate: string | null; description: string | null; coverImage: string | null; galleryImages: string[]; featured: boolean; createdAt: string; } export default function ProjectDetails({ params }: { params: { id: string; locale: string } }) { const { t, locale } = useLocale(); const prefix = locale === 'pt' ? '' : `/${locale}`; const [project, setProject] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); const [selectedImage, setSelectedImage] = useState(null); const [lightboxOpen, setLightboxOpen] = useState(false); // Translations const texts = { aboutProject: locale === 'pt' ? 'Sobre o Projeto' : locale === 'es' ? 'Sobre el Proyecto' : 'About the Project', imageGallery: locale === 'pt' ? 'Galeria de Imagens' : locale === 'es' ? 'Galería de Imágenes' : 'Image Gallery', technicalSheet: locale === 'pt' ? 'Ficha Técnica' : locale === 'es' ? 'Ficha Técnica' : 'Technical Sheet', client: locale === 'pt' ? 'Cliente' : locale === 'es' ? 'Cliente' : 'Client', category: locale === 'pt' ? 'Categoria' : locale === 'es' ? 'Categoría' : 'Category', status: locale === 'pt' ? 'Status' : locale === 'es' ? 'Estado' : 'Status', year: locale === 'pt' ? 'Ano' : locale === 'es' ? 'Año' : 'Year', featured: locale === 'pt' ? 'Destaque' : locale === 'es' ? 'Destacado' : 'Featured', yes: locale === 'pt' ? 'Sim' : locale === 'es' ? 'Sí' : 'Yes', requestQuote: locale === 'pt' ? 'Solicitar Orçamento Similar' : locale === 'es' ? 'Solicitar Presupuesto Similar' : 'Request Similar Quote', backToProjects: locale === 'pt' ? 'Voltar para Projetos' : locale === 'es' ? 'Volver a Proyectos' : 'Back to Projects', completed: locale === 'pt' ? 'Concluído' : locale === 'es' ? 'Completado' : 'Completed', inProgress: locale === 'pt' ? 'Em andamento' : locale === 'es' ? 'En progreso' : 'In Progress', }; useEffect(() => { async function fetchProject() { try { const res = await fetch(`/api/projects/${params.id}`, { cache: "no-store" }); if (res.ok) { const data = await res.json(); setProject(data); setSelectedImage(data.coverImage || data.galleryImages?.[0] || null); } else if (res.status === 404) { setError(true); } } catch (err) { console.error("Erro ao carregar projeto:", err); setError(true); } finally { setLoading(false); } } fetchProject(); }, [params.id]); if (loading) { return (
); } if (error || !project) { notFound(); } const defaultImage = "https://images.unsplash.com/photo-1504307651254-35680f356dfd?q=80&w=2070&auto=format&fit=crop"; const heroImage = project.coverImage || defaultImage; const allImages = [ ...(project.coverImage ? [project.coverImage] : []), ...project.galleryImages, ].filter(Boolean); const completionYear = project.completionDate ? new Date(project.completionDate).getFullYear() : new Date(project.createdAt).getFullYear(); const statusText = project.status === 'Concluído' ? texts.completed : texts.inProgress; return (
{/* Hero Section */}
{project.category && ( {project.category} )}

{project.title}

{project.client && (
{project.client}
)}
{completionYear}
{statusText}
{/* Content Section */}
{/* Main Content */}
{/* Description */} {project.description && ( <>

{texts.aboutProject}

{project.description}

)} {/* Image Gallery */} {allImages.length > 0 && ( <>

{texts.imageGallery}

{/* Main Image */}
{ setLightboxOpen(true); }} > {project.title}
{/* Thumbnail Grid */} {allImages.length > 1 && (
{allImages.map((img, index) => ( ))}
)} )}
{/* Sidebar */}

{texts.technicalSheet}

    {project.client && (
  • {texts.client} {project.client}
  • )} {project.category && (
  • {texts.category} {project.category}
  • )}
  • {texts.status} {statusText}
  • {texts.year} {completionYear}
  • {project.featured && (
  • {texts.featured} {texts.yes}
  • )}
{texts.requestQuote} {texts.backToProjects}
{/* Lightbox */} {lightboxOpen && (
setLightboxOpen(false)} > {allImages.length > 1 && ( <> )} {project.title} e.stopPropagation()} />
)}
); }