import { useState, useEffect } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { Download, FileText, ExternalLink, X, Eye, BookOpen } from 'lucide-react' import { useLang } from '@/context/LangContext' import { FALLBACK_TECHNOGEN_REPORTS, type TechnogenReport } from '@/data/technogen' const NAVY = '#032340' const GOLD = '#CD9E53' const EASE = [0.22, 1, 0.36, 1] as const export default function TechnogenSection() { const { lang } = useLang() const isFa = lang === 'fa' const [reports, setReports] = useState(FALLBACK_TECHNOGEN_REPORTS) const [selectedReport, setSelectedReport] = useState(null) useEffect(() => { let unmounted = false fetch('/api/technogen') .then((res) => { if (!res.ok) throw new Error('API error') return res.json() }) .then((data: TechnogenReport[]) => { if (!unmounted && Array.isArray(data) && data.length > 0) { setReports(data) } }) .catch(() => {}) return () => { unmounted = true } }, []) // Featured report (POSCO study) vs analytical notes const featured = reports.find((r) => r.isFeatured) || reports[0] const analyticalNotes = reports.filter((r) => r.id !== featured?.id) const openPreview = (report: TechnogenReport) => { setSelectedReport(report) } const closePreview = () => { setSelectedReport(null) } return (
{/* ── Section Header with Gold Accent Line ── */}

{isFa ? 'تکنوژن؛ برنامه توسعه‌گر ملی فناوری' : 'Technogen: National Technology Developer Program'}

{isFa ? 'گزارش‌های تحلیلی و مطالعات تطبیقی یادگیری صنعتی، انتقال دانش و ساخت قابلیت فناورانه در زنجیره فولاد' : 'Analytical notes and comparative studies on industrial learning, knowledge absorption, and technological capability building in steel.'}

{/* ── Bento Grid Layout (Unified Single Block) ── */}
{/* ── Bento Card 1: Flagship POSCO Study (Spans 7 columns) ── */} {featured && ( {/* Subtle background glow */}
{/* Cover Thumbnail */}
openPreview(featured)} style={{ width: 150, aspectRatio: '1 / 1.414', borderRadius: 10, overflow: 'hidden', boxShadow: '0 14px 28px -6px rgba(0,0,0,0.5)', border: '1px solid rgba(255,255,255,0.15)', cursor: 'pointer', background: NAVY, }} > {isFa
{/* Info & Actions */}
{/* Meta Pills */}
{isFa ? 'مطالعه تطبیقی ویژه' : 'Flagship Study'} {featured.code && ( {featured.code} )} {isFa ? (featured.pagesFa || '۳۰ صفحه') : (featured.pagesEn || '30 Pages')}
{/* Title */}

{isFa ? featured.titleFa : (featured.titleEn || featured.titleFa)}

{/* Subtitle / Excerpt */} {featured.subtitleFa && (

{isFa ? featured.subtitleFa : (featured.subtitleEn || featured.subtitleFa)}

)} {/* Actions */}
{featured.fileUrl && ( {isFa ? 'دانلود PDF کامل' : 'Download PDF'} )}
)} {/* ── Bento Cards 2, 3, 4: Analytical Notes (Spans 5 columns) ── */}
{analyticalNotes.map((note, idx) => ( {/* Mini Cover Thumbnail */}
openPreview(note)} style={{ flex: '0 0 54px', width: 54, aspectRatio: '1 / 1.414', borderRadius: 6, overflow: 'hidden', boxShadow: '0 4px 10px rgba(0,0,0,0.15)', border: '1px solid rgba(3,35,64,0.1)', background: NAVY, cursor: 'pointer', }} > {isFa
{/* Content */}
{note.code && ( {note.code} )} {isFa ? (note.tagFa || 'یادداشت تحلیلی') : (note.tagEn || 'Analytical Note')} {isFa ? (note.pagesFa || '۴ صفحه') : (note.pagesEn || '4 Pages')}

openPreview(note)} style={{ fontSize: 13, fontWeight: 800, color: NAVY, lineHeight: 1.4, margin: '0 0 2px', cursor: 'pointer', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', }} title={isFa ? note.titleFa : (note.titleEn || note.titleFa)} > {isFa ? note.titleFa : (note.titleEn || note.titleFa)}

{note.subtitleFa && (

{isFa ? note.subtitleFa : (note.subtitleEn || note.subtitleFa)}

)}
{/* Quick Action Buttons */}
{note.fileUrl && ( )}
))}
{/* ── Document Reader / Preview Modal ── */} {selectedReport && (
{/* Backdrop */} {/* Modal Window */} {/* Modal Top Header */}
{selectedReport.code} · {isFa ? selectedReport.tagFa : (selectedReport.tagEn || selectedReport.tagFa)}
{isFa ? selectedReport.titleFa : (selectedReport.titleEn || selectedReport.titleFa)}
{selectedReport.fileUrl && ( {isFa ? 'دانلود فایل' : 'Download'} )} {selectedReport.fileUrl && ( )}
{/* Modal Viewer Body */}
{selectedReport.fileUrl ? (