import { useState, useMemo } from 'react' import { Link } from 'react-router-dom' import { reports } from '@/data/reports' import type { ReportCategory, ReportType } from '@/data/reports' /* ─── constants ──────────────────────────────────────────── */ const TYPE_LABELS: Record = { quarterly: 'فصلی', flash: 'فلش', risk: 'ریسک', free: 'رایگان', special: 'ویژه', } const TYPE_COLORS: Record = { quarterly: '#166534', flash: '#9b1c1c', risk: '#92400e', free: '#1d4ed8', special: '#4a1d96', } /* Persian month order for sorting date groups */ const MONTH_ORDER: Record = { 'فروردین': 1, 'اردیبهشت': 2, 'خرداد': 3, 'تیر': 4, 'مرداد': 5, 'شهریور': 6, 'مهر': 7, 'آبان': 8, 'آذر': 9, 'دی': 10, 'بهمن': 11, 'اسفند': 12, } function parseDateGroup(dateStr: string): number { const parts = dateStr.trim().split(' ') if (parts.length < 2) return 0 const month = MONTH_ORDER[parts[0]] ?? 0 const year = parseInt(parts[1]) || 0 return year * 100 + month } /* ─── unique categories from data ───────────────────────── */ const ALL_CATEGORIES: (ReportCategory | 'همه')[] = [ 'همه', ...Array.from(new Set(reports.map((r) => r.category))) as ReportCategory[], ] /* ─── price formatter ────────────────────────────────────── */ function formatPrice(price: number): string { if (price === 0) return 'رایگان' return price.toLocaleString('fa-IR') + ' ت' } /* ─── report row ─────────────────────────────────────────── */ function ReportRow({ report }: { report: (typeof reports)[0] }) { const [hovered, setHovered] = useState(false) const typeColor = TYPE_COLORS[report.type] const typeLabel = TYPE_LABELS[report.type] return (
setHovered(true)} onMouseLeave={() => setHovered(false)} > {/* type label */}
{typeLabel}
{/* title */}
{report.title}
{/* author */}
{report.author}
{/* pages */}
{report.pages.toLocaleString('fa-IR')} ص
{/* price */}
{formatPrice(report.price)}
) } /* ─── main component ─────────────────────────────────────── */ export default function Archive() { const [search, setSearch] = useState('') const [activeCategory, setActiveCategory] = useState('همه') const filtered = useMemo(() => { let result = [...reports] if (activeCategory !== 'همه') { result = result.filter((r) => r.category === activeCategory) } if (search.trim()) { const q = search.trim().toLowerCase() result = result.filter( (r) => r.title.toLowerCase().includes(q) || r.author.toLowerCase().includes(q) || r.category.toLowerCase().includes(q) || r.tags.some((t) => t.toLowerCase().includes(q)) ) } return result }, [search, activeCategory]) /* group by publishDate, sorted newest first */ const groups = useMemo(() => { const map = new Map() for (const report of filtered) { const key = report.publishDate if (!map.has(key)) map.set(key, []) map.get(key)!.push(report) } return Array.from(map.entries()).sort( ([a], [b]) => parseDateGroup(b) - parseDateGroup(a) ) }, [filtered]) return (
{/* ─── Page header ───────────────────────────────────── */}

آرشیو گزارش‌ها

{reports.length.toLocaleString('fa-IR')} گزارش
{/* ─── Search ────────────────────────────────────────── */}
setSearch(e.target.value)} style={{ width: '100%', border: '1px solid var(--ink)', borderRadius: 0, padding: '12px 18px', fontSize: 14, fontFamily: 'inherit', background: 'transparent', color: 'var(--ink)', outline: 'none', direction: 'rtl', }} />
{/* ─── Category filter chips ─────────────────────────── */}
{ALL_CATEGORIES.map((cat) => { const isActive = activeCategory === cat return ( ) })}
{/* ─── Date groups ───────────────────────────────────── */} {groups.length > 0 ? (
{groups.map(([date, groupReports]) => (
{/* section divider */}
{date}
{groupReports.length.toLocaleString('fa-IR')} گزارش
{/* column headers */}
{[ { label: 'نوع', style: { padding: '6px 12px', borderLeft: '1px solid var(--rule-thin)' } }, { label: 'عنوان گزارش', style: { padding: '6px 16px', borderLeft: '1px solid var(--rule-thin)' } }, { label: 'نویسنده', style: { padding: '6px 12px', borderLeft: '1px solid var(--rule-thin)' }, hideMobile: true }, { label: 'صفحه', style: { padding: '6px 10px', borderLeft: '1px solid var(--rule-thin)', textAlign: 'center' as const }, hideMobile: true }, { label: 'قیمت', style: { padding: '6px 12px', textAlign: 'left' as const } }, ].map((col) => (
{col.label}
))}
{/* report rows */}
{groupReports.map((report) => ( ))}
))}
) : (

نتیجه‌ای یافت نشد

عبارت جستجو یا فیلتر دسته‌بندی را تغییر دهید

)} {/* responsive: hide author/pages columns on small screens */}
) }