import React, { useState } from 'react' import { Link, useParams } from 'react-router-dom' import { ArrowLeftIcon, ChevronLeftIcon } from 'lucide-react' import { Reveal } from '../components/Reveal' import { ButtonLink } from '../components/Button' import { ProjectCard } from '../components/ProjectCard' import { ContactSection } from '../components/ContactSection' import { Lightbox } from '../components/Lightbox' import { useEffect } from 'react'; import { useSite, useStatusLabel } from '../api'; import { useLang } from '../i18n/lang'; import { useAdmin } from '../admin/AdminContext'; import { LazyProjectsMapSingle } from '../map/LazyMaps'; import { createPlaceholderProject, findMapProjectByName } from '../data/mapProjects'; import { applySeo } from '../seo'; export function ProjectDetail() { const { slug } = useParams<{ slug: string }>() const { projects, brand } = useSite() const { t, href, lang } = useLang() const { canManageSite } = useAdmin() const project = projects.find((p) => p.slug === slug) const statusLabel = useStatusLabel(project?.status ?? '') const [lightbox, setLightbox] = useState(null) // مختصات پروژه از فهرست سنجاق‌های شیت؛ نبودش → محل جایگزین تا نقشه خالی نماند const mapLocation = project ? (findMapProjectByName(project.title) ?? createPlaceholderProject(project.title, project.summary)) : null const mapImages = project && Array.isArray(project.gallery) ? project.gallery.filter(Boolean) : [] // عنوان تب، توضیح متا، OG و JSON-LD از خود پروژه — هم‌ارز نسخهٔ سمت سرور (seo_pages.py) useEffect(() => { if (!project) return; const absolute = (path: string) => new URL(path, window.location.origin).href; applySeo({ title: `${project.title} | ${brand.name}`, description: project.summary, path: href(`/projects/${project.slug}`), image: project.image, lang, // alternate انگلیسی فقط با وجود ترجمهٔ واقعی hasEn: !!(project.title_en?.trim() || project.summary_en?.trim()), jsonLd: [ { '@context': 'https://schema.org', '@type': 'WebPage', name: project.title, description: project.summary, image: project.image ? absolute(project.image) : undefined, inLanguage: lang, }, { '@context': 'https://schema.org', '@type': 'BreadcrumbList', itemListElement: [ { '@type': 'ListItem', position: 1, name: t('home'), item: absolute(href('/')) }, { '@type': 'ListItem', position: 2, name: t('projects'), item: absolute(href('/projects')) }, { '@type': 'ListItem', position: 3, name: project.title, item: absolute(href(`/projects/${project.slug}`)) }, ], }, ], }); }, [project?.id, lang, href]); if (!project) { return (

{t('projectNotFound')}

{t('projectNotFoundText')}

{t('backToProjects')}
) } const related = projects.filter((p) => p.slug !== project.slug).slice(0, 3) /** * پیمایش پروژه‌ها — همان ترتیبی که فهرست پروژه‌ها دارد (position از API). * در ابتدا/انتهای فهرست، حلقه می‌زند تا کاوش هیچ‌وقت قطع نشود. */ const currentIndex = projects.findIndex((p) => p.slug === project.slug) const total = projects.length const prevProject = total > 1 ? projects[(currentIndex + 1) % total] : undefined // قدیمی‌تر const nextProject = total > 1 ? projects[(currentIndex - 1 + total) % total] : undefined // تازه‌تر // مشخصات هر پروژه — همان فهرستی که تیم داده دارد: // وضعیت / سال / تعداد طبقات / واحدها / نوع پروژه / زیربنا / کاربری // ردیف‌های خالی نمایش داده نمی‌شوند. const facts = [ { label: t('specStatus'), value: statusLabel }, { label: t('specYear'), value: project.year }, { label: t('specLandArea'), value: project.land_area }, { label: t('specArea'), value: project.area }, { label: t('specUsage'), value: project.usage }, { label: t('specPilotFloors'), value: project.pilot_floors }, { label: t('specFloors'), value: project.floors }, { label: t('specUnitsResidential'), value: project.units_residential }, { label: t('specUnitsCommercial'), value: project.units_commercial }, { label: t('specUnitsOffice'), value: project.units_office }, ].filter((f) => String(f.value ?? '').trim() !== '') return ( <>
{/* نقشهٔ مختصات پروژه — بلافاصله زیر هیرو */} {mapLocation && (
)}

{t('aboutProject')}

{project.body.map((para) => (

{para}

))}
{facts.map((f) => (
{f.label}
{f.value}
))}
{t('similarProjectCta')}
{project.gallery.slice(1).map((img, i) => ( ))}
{/* پیمایش پروژه‌ها — رفتن به پروژهٔ قبلی/بعدی بدون بازگشت به فهرست */} {(prevProject || nextProject) && ( )}

{t('otherProjects')}

{related.map((item, i) => ( ))}
setLightbox(null)} onChange={setLightbox} /> ) }