import React, { useMemo, useState } from 'react'; import { PageHero } from '../components/PageHero'; import { Reveal } from '../components/Reveal'; import { ProjectCard } from '../components/ProjectCard'; import { PremiumButton } from '../components/PremiumButton'; import { Gallery } from '../components/home/Gallery'; import { ContactSection } from '../components/ContactSection'; import { useSite, useStatusLabel } from '../api'; import { useLang } from '../i18n/lang'; import { useFieldSaver } from '../admin/AdminContext'; import { InlineEdit } from '../components/admin/InlineEdit'; import { projectsData } from '../data/projectsData'; import { LazyProjectsMapAll } from '../map/LazyMaps'; import { MAP_PROJECTS, type MapProject } from '../data/mapProjects'; export function Projects() { const { status_labels } = useSite(); const { t } = useLang(); const save = useFieldSaver(); const saveStatusLabel = (key: string, value: string) => { const label = status_labels.find((s) => s.key === key); if (!label) return; void save('status-labels', label.id, { label: value }, (d) => { const s = d.status_labels.find((x) => x.id === label.id); if (s) s.label = value; }); }; const doneLabel = useStatusLabel('done'); const progressLabel = useStatusLabel('progress'); const FILTERS: { key: 'done' | 'progress'; label: string; }[] = [ { key: 'done', label: doneLabel }, { key: 'progress', label: progressLabel } ]; const [status, setStatus] = useState<'done' | 'progress'>('done'); // Filtering and Pagination State const [page, setPage] = useState(1); const [isLoading, setIsLoading] = useState(false); const itemsPerPage = 12; // Filter projects by status const filteredProjects = useMemo(() => { return projectsData.filter((p) => p.status === status); }, [status]); // Currently displayed projects const displayedProjects = useMemo(() => { return filteredProjects.slice(0, page * itemsPerPage); }, [filteredProjects, page]); // Handle Tab Switch const handleTabSwitch = (newStatus: 'done' | 'progress') => { setStatus(newStatus); setPage(1); // Reset pagination on tab switch }; // Handle Load More const handleLoadMore = () => { setIsLoading(true); // Brief loading state setTimeout(() => { setPage((prev) => prev + 1); setIsLoading(false); }, 400); }; const BASE_IMG_URL = "/seed-media/2026/09/"; // Resolve a project href from a MapProject entry by matching against projectsData slugs const resolveProjectHref = (mapProject: MapProject): string | undefined => { const match = projectsData.find( (p) => p.name.fa === mapProject.name || p.name.en === mapProject.name ); return match ? `/projects/${match.slug}` : undefined; }; return ( <> {/* نقشهٔ محدود‌شده — همهٔ پروژه‌ها با سنجاق مسی */}
{/* دکمه‌های فیلتر */}
{FILTERS.map((filter, index) => { const isSelected = status === filter.key; return ( {index > 0 && ( ); })}
{displayedProjects.map((project, index) => { const dummyImageName = `${(index % 6) + 1}.png`; const imageUrl = `${BASE_IMG_URL}${dummyImageName}`; return ( ); })}
{/* Load More Button */} {displayedProjects.length < filteredProjects.length && (
{isLoading ? 'در حال بارگذاری...' : 'مشاهده بیشتر'}
)}
); }