// ─────────────────────────────────────────────────────────── // Huio Control Panel — Documents & Group Icons View (cp-documents-view.jsx) // ─────────────────────────────────────────────────────────── if (!window.CP_STYLES) throw new Error('[cp-documents-view] window.CP_STYLES not loaded (check cp-styles.jsx)'); function DocumentsViewComponent({ lang = 'vi', t: rawT, appStyles: rawAppStyles, }) { const appStyles = rawAppStyles || window.CP_STYLES || {}; const t = typeof rawT === 'function' ? rawT : (k) => k; // Active top-level subtab: 'gallery' (Documents) | 'icons' (Group Icons) const [activeTab, setActiveTab] = React.useState('gallery'); // Manifest and loading state const [manifest, setManifest] = React.useState(null); const [isLoading, setIsLoading] = React.useState(true); const [loadError, setLoadError] = React.useState(null); // Gallery Filters const [searchQuery, setSearchQuery] = React.useState(''); const [selectedCategory, setSelectedCategory] = React.useState('all'); const [selectedLang, setSelectedLang] = React.useState('all'); // 'all', 'vi', 'en' const [selectedFormat, setSelectedFormat] = React.useState('all'); // 'all', 'Dọc', 'Ngang' const [selectedSkin, setSelectedSkin] = React.useState('all'); // 'all', 'classic', 'cute_cat', etc. // Modal Viewer State const [modalSheet, setModalSheet] = React.useState(null); const [activePageIndex, setActivePageIndex] = React.useState(0); // Reset page index whenever modalSheet changes React.useEffect(() => { setActivePageIndex(0); }, [modalSheet?.id, modalSheet?.file]); // Icons Tab State const [iconSearch, setIconSearch] = React.useState(''); const [selectedIconCat, setSelectedIconCat] = React.useState('all'); const [selectedIconColor, setSelectedIconColor] = React.useState('#B85C38'); const [copiedToast, setCopiedToast] = React.useState(null); // Fetch Manifest on mount const loadManifest = React.useCallback(async () => { setIsLoading(true); setLoadError(null); try { const res = await fetch('./docs-gallery/manifest.json'); if (!res.ok) { throw new Error(`HTTP ${res.status}: Không thể tải manifest.json`); } const data = await res.json(); setManifest(data); } catch (err) { console.error('[cp-documents-view] Error loading manifest:', err); setLoadError(err.message || 'Lỗi khi tải dữ liệu thư viện tài liệu'); } finally { setIsLoading(false); } }, []); React.useEffect(() => { loadManifest(); }, [loadManifest]); // Keyboard navigation for Modal Viewer React.useEffect(() => { if (!modalSheet || !manifest?.sheets) return; const handleKeyDown = (e) => { if (e.key === 'Escape') { setModalSheet(null); } else if (e.key === 'ArrowLeft') { if (modalSheet.pages && modalSheet.pages.length > 1 && activePageIndex > 0) { setActivePageIndex((idx) => idx - 1); } else { navigateModal(-1); } } else if (e.key === 'ArrowRight') { if (modalSheet.pages && modalSheet.pages.length > 1 && activePageIndex < modalSheet.pages.length - 1) { setActivePageIndex((idx) => idx + 1); } else { navigateModal(1); } } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [modalSheet, manifest, activePageIndex, navigateModal]); // Filtered sheets const filteredSheets = React.useMemo(() => { if (!manifest?.sheets) return []; return manifest.sheets.filter((sheet) => { // Search filter if (searchQuery.trim()) { const q = searchQuery.toLowerCase().trim(); const matchTitleVi = (sheet.docTitleVi || '').toLowerCase().includes(q); const matchTitleEn = (sheet.docTitleEn || '').toLowerCase().includes(q); const matchFile = (sheet.file || '').toLowerCase().includes(q); const matchDocId = (sheet.docId || '').includes(q); const matchPrefix = (sheet.docPrefix || '').toLowerCase().includes(q); if (!matchTitleVi && !matchTitleEn && !matchFile && !matchDocId && !matchPrefix) { return false; } } // Category filter if (selectedCategory !== 'all' && sheet.docId !== selectedCategory) { return false; } // Lang filter if (selectedLang !== 'all' && sheet.lang !== selectedLang) { return false; } // Format filter if (selectedFormat !== 'all' && sheet.format !== selectedFormat) { return false; } // Skin filter if (selectedSkin !== 'all' && sheet.theme !== selectedSkin) { return false; } return true; }); }, [manifest, searchQuery, selectedCategory, selectedLang, selectedFormat, selectedSkin]); // Unique document generators count in current filtered view const uniqueDocsCount = React.useMemo(() => { const ids = new Set(filteredSheets.map((s) => s.docId || s.generator)); return ids.size; }, [filteredSheets]); // Navigate Modal Previous / Next const navigateModal = (delta) => { if (!modalSheet || !filteredSheets.length) return; const currentIndex = filteredSheets.findIndex((s) => s.file === modalSheet.file); if (currentIndex === -1) return; const nextIndex = currentIndex + delta; if (nextIndex >= 0 && nextIndex < filteredSheets.length) { setModalSheet(filteredSheets[nextIndex]); } }; // Find theme variants for currently selected document in modal const modalDocThemeVariants = React.useMemo(() => { if (!modalSheet || !manifest?.sheets) return []; return manifest.sheets.filter( (s) => s.docId === modalSheet.docId && s.format === modalSheet.format && s.lang === modalSheet.lang ); }, [modalSheet, manifest]); // Filtered Icons const filteredIcons = React.useMemo(() => { if (!manifest?.icons?.list) return []; return manifest.icons.list.filter((ic) => { if (selectedIconCat !== 'all' && ic.categoryId !== selectedIconCat) { return false; } if (iconSearch.trim()) { const q = iconSearch.toLowerCase().trim(); const matchName = ic.name.toLowerCase().includes(q); const matchVi = (ic.titleVi || '').toLowerCase().includes(q); const matchEn = (ic.titleEn || '').toLowerCase().includes(q); if (!matchName && !matchVi && !matchEn) return false; } return true; }); }, [manifest, selectedIconCat, iconSearch]); // Copy Icon URI helper const handleCopyIcon = (iconName) => { const uri = `icon:${iconName}:${selectedIconColor}`; if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(uri).catch(() => {}); } setCopiedToast(uri); setTimeout(() => { setCopiedToast((cur) => (cur === uri ? null : cur)); }, 2200); }; // Contrast helper for icon preview const getIconContrast = (bgHex) => { const norm = (bgHex || '').toUpperCase(); if (norm === '#C19433' || norm === '#A89684' || norm === '#F4EFE6' || norm === '#FFFFFF') { return '#1C1A15'; } return '#FFFFFF'; }; // Loading state if (isLoading) { return (

{lang === 'vi' ? 'Đang tải dữ liệu thư viện tài liệu R5...' : 'Loading R5 documents gallery...'}

); } // Error state if (loadError) { return (
⚠️

{lang === 'vi' ? 'Không thể tải thư viện tài liệu' : 'Failed to load documents gallery'}

{loadError}

); } const skins = manifest?.skins || []; const categories = manifest?.categories || []; const totalSheets = manifest?.sheets?.length || 0; const currentModalIndex = modalSheet ? filteredSheets.findIndex((s) => s.file === modalSheet.file) : -1; return (
{/* Toast Notification */} {copiedToast && (
✓ {lang === 'vi' ? 'Đã sao chép:' : 'Copied URI:'} {copiedToast}
)} {/* Header Banner */}
📄

{t('docs.title') || (lang === 'vi' ? 'Thư viện tài liệu & Biểu tượng R5' : 'Documents & Group Icons R5 Gallery')}

CANON R5

{t('docs.subtitle') || (lang === 'vi' ? 'Xem toàn bộ 17 loại tài liệu Huio trên dữ liệu mẫu chuẩn R5, kiểm tra các giao diện (skin) và định dạng dọc/ngang.' : 'View all 17 Huio documents rendered with canonical R5 sample data, inspect theme skins and portrait/landscape formats.')}

{/* Tab Switcher Pills */}
{/* ═══════════════════════════════════════════════════════════════ TAB 1: DOCUMENTS GALLERY ═══════════════════════════════════════════════════════════════ */} {activeTab === 'gallery' && (
{/* Controls Bar */}
{/* Top row: Search + Document Type Select */}
🔍 setSearchQuery(e.target.value)} placeholder={t('docs.search_placeholder') || (lang === 'vi' ? 'Tìm theo tên tài liệu, mã số (#01-#17)...' : 'Search document title or code...')} style={{ width: '100%', padding: '8px 12px 8px 36px', borderRadius: '8px', border: '1px solid var(--hu-border)', background: 'var(--hu-bg-elev)', color: 'var(--hu-fg)', fontSize: '13px', boxSizing: 'border-box', outline: 'none', }} /> {searchQuery && ( )}
{/* Document Type Dropdown */}
{/* Bottom row: Filter Chips (Language, Format, Skin) */}
{/* Language Chips */}
{lang === 'vi' ? 'Ngôn ngữ:' : 'Lang:'} {[ { id: 'all', label: lang === 'vi' ? 'Tất cả' : 'All' }, { id: 'vi', label: 'Tiếng Việt (VI)' }, { id: 'en', label: 'English (EN)' }, ].map((item) => ( ))}
{/* Format Chips */}
{lang === 'vi' ? 'Định dạng:' : 'Format:'} {[ { id: 'all', label: lang === 'vi' ? 'Tất cả' : 'All' }, { id: 'Dọc', label: lang === 'vi' ? 'Dọc (A4)' : 'Portrait' }, { id: 'Ngang', label: lang === 'vi' ? 'Ngang' : 'Landscape' }, ].map((item) => ( ))}
{/* Skin Chips (Dynamically rendered from manifest.skins) */}
{lang === 'vi' ? 'Skin / Giao diện:' : 'Theme Skin:'} {skins.map((skin) => ( ))}
{/* Stats Bar */}
{lang === 'vi' ? `Hiển thị ${filteredSheets.length} bản in (${uniqueDocsCount}/17 tài liệu) / ${totalSheets} bản in mẫu` : `Showing ${filteredSheets.length} sheets (${uniqueDocsCount}/17 documents) of ${totalSheets} sample sheets`} {(searchQuery || selectedCategory !== 'all' || selectedLang !== 'all' || selectedFormat !== 'all' || selectedSkin !== 'all') && ( )}
{/* Empty state */} {filteredSheets.length === 0 && (
🔍

{t('docs.empty_search') || (lang === 'vi' ? 'Không tìm thấy tài liệu nào phù hợp với bộ lọc.' : 'No documents found matching the active filters.')}

)} {/* Document Cards Grid */}
{filteredSheets.map((sheet) => { const skinMeta = skins.find((s) => s.id === sheet.theme) || skins[0] || {}; const isLandscape = sheet.format === 'Ngang'; return (
setModalSheet(sheet)} style={{ borderRadius: 'var(--hu-r-md, 12px)', background: 'var(--hu-bg-card)', border: '1px solid var(--hu-border)', overflow: 'hidden', cursor: 'pointer', display: 'flex', flexDirection: 'column', transition: 'transform 0.15s ease, box-shadow 0.15s ease', }} onMouseEnter={(e) => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = 'var(--hu-shadow-md)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }} > {/* Thumbnail Container (Clean sheet preview - NO overlays covering document header) */}
{sheet.docTitleVi} {/* Fallback Stub Overlay for Unsupported Skin */} {sheet.skinSupported === false && (
🎨
ℹ️ {lang === 'vi' ? 'Skin không áp dụng' : 'Skin not applied'}
{lang === 'vi' ? 'Tài liệu chuẩn — chỉ hỗ trợ giao diện Cổ điển' : 'Standard document — Classic layout only'}
)}
{/* Card Details & Badges Row (UNDER the image, completely unobstructed) */}
{/* Badges Row */}
{sheet.format} {sheet.lang} {/* Multipage Badge */} {sheet.totalSheets > 1 && ( 📄 1/{sheet.totalSheets} )} {/* Skin Badge: if unsupported, show neutral dashed badge; if supported & non-classic, show theme badge */} {sheet.skinSupported === false ? ( ⚠️ {lang === 'vi' ? 'Skin không áp dụng' : 'Skin not applied'} ) : sheet.theme !== 'classic' ? ( {lang === 'vi' ? skinMeta.nameVi : skinMeta.nameEn} ) : null}
#{sheet.docId}

{lang === 'vi' ? sheet.docTitleVi : sheet.docTitleEn}

{sheet.width}×{sheet.height}

{lang === 'vi' ? (sheet.docDescVi || sheet.docTitleEn) : (sheet.docDescEn || sheet.docTitleVi)}

{sheet.sizeKb} KB · md5:{sheet.md5 ? sheet.md5.slice(0, 6) : ''} {lang === 'vi' ? 'Xem đầy đủ' : 'View'} →
); })}
)} {/* ═══════════════════════════════════════════════════════════════ TAB 2: GROUP ICONS ═══════════════════════════════════════════════════════════════ */} {activeTab === 'icons' && (
{/* Controls Card */}
{/* Color Palette Selector */}
{t('docs.icons_color') || (lang === 'vi' ? 'Bảng màu đại diện dây hụi (8 màu chuẩn):' : 'Official Group Color Palette:')} {selectedIconColor}
{(manifest?.icons?.colors || []).map((colorHex) => { const isSelected = selectedIconColor.toUpperCase() === colorHex.toUpperCase(); return ( ); })}
{/* Search + Category Filter */}
🔍 setIconSearch(e.target.value)} placeholder={t('docs.icons_search') || (lang === 'vi' ? 'Tìm biểu tượng theo tên, mã khóa...' : 'Search icons by name or key...')} style={{ width: '100%', padding: '8px 12px 8px 36px', borderRadius: '8px', border: '1px solid var(--hu-border)', background: 'var(--hu-bg-elev)', color: 'var(--hu-fg)', fontSize: '13px', outline: 'none', boxSizing: 'border-box', }} />
{/* Category Chips */}
{(manifest?.icons?.categories || []).map((cat) => ( ))}
{/* Stats & Click-to-copy tip */}
{lang === 'vi' ? `Hiển thị ${filteredIcons.length} / 80 biểu tượng Lucide vector` : `Showing ${filteredIcons.length} of 80 Lucide vector icons`} 💡 {lang === 'vi' ? 'Nhấp vào thẻ để sao chép mã URI icon::' : 'Click any icon to copy its URI'}
{/* Icons Grid */}
{filteredIcons.map((ic) => { const iconContrast = getIconContrast(selectedIconColor); return (
handleCopyIcon(ic.name)} style={{ padding: '16px 10px 12px', borderRadius: 'var(--hu-r-md, 12px)', background: 'var(--hu-bg-card)', border: '1px solid var(--hu-border)', display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', cursor: 'pointer', transition: 'transform 0.15s ease, box-shadow 0.15s ease', position: 'relative', }} onMouseEnter={(e) => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = 'var(--hu-shadow-md)'; }} onMouseLeave={(e) => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }} > {/* Legacy Badge */} {ic.isLegacy && ( CORE )} {/* Circular Avatar with Active Color */}
{/* Name code */} {ic.name} {/* Friendly Title */} {lang === 'vi' ? ic.titleVi : ic.titleEn} {lang === 'vi' ? ic.categoryVi : ic.categoryEn}
); })}
)} {/* ═══════════════════════════════════════════════════════════════ MODAL VIEWER: FULL DOCUMENT SHEET (794px / Landscape) ═══════════════════════════════════════════════════════════════ */} {modalSheet && (
setModalSheet(null)} >
e.stopPropagation()} style={{ width: '100%', maxWidth: modalSheet.format === 'Ngang' ? '1180px' : '860px', maxHeight: '92vh', background: 'var(--hu-bg-card)', borderRadius: '16px', display: 'flex', flexDirection: 'column', boxShadow: 'var(--hu-shadow-lg)', border: '1px solid var(--hu-border-strong)', overflow: 'hidden', }} > {/* Modal Header */}
#{modalSheet.docId}

{modalSheet.docTitleVi} · {modalSheet.docTitleEn}

{modalSheet.format} · {modalSheet.lang} · Skin: {modalSheet.themeNameVi || modalSheet.theme} · {modalSheet.width}×{modalSheet.height} px · {modalSheet.sizeKb} KB
{/* Header Action Buttons */}
🔗 {t('docs.open_tab') || (lang === 'vi' ? 'Mở ảnh mới' : 'Open in new tab')}
{/* Modal Navigation & Theme Switcher Bar */}
{/* Left group: Document prev/next + Multipage page flipper */}
{/* Document Prev / Next */}
{currentModalIndex + 1} / {filteredSheets.length}
{/* Multipage Page Flipper & Dots */} {modalSheet.pages && modalSheet.pages.length > 1 && (
{modalSheet.pages.map((p, idx) => (
{lang === 'vi' ? `Trang ${activePageIndex + 1}/${modalSheet.pages.length}` : `Page ${activePageIndex + 1}/${modalSheet.pages.length}`}
)}
{/* Skin / Theme Switcher: Always show all 5 distinct skins with active one highlighted */} {skins.length > 1 && (
{lang === 'vi' ? 'Đổi Skin:' : 'Switch Skin:'} {skins.map((skin) => { const isCurrent = (modalSheet.theme === skin.id) || (!modalSheet.theme && skin.id === 'classic'); return ( ); })}
)}
{/* Unsupported Skin Notice */} {modalSheet.skinSupported === false && (
ℹ️ {lang === 'vi' ? `Tài liệu #${modalSheet.docId} (${modalSheet.docTitleVi}) không hỗ trợ giao diện «${modalSheet.themeNameVi || modalSheet.theme}». Đang hiển thị định dạng chuẩn Cổ điển.` : `Document #${modalSheet.docId} (${modalSheet.docTitleEn}) does not support skin «${modalSheet.themeNameEn || modalSheet.theme}». Displaying standard Classic format.`}
)} {/* Modal Body: High-Res Sheet Image */}
{modalSheet.docTitleVi}
{/* Modal Footer Info */}
Tệp: {modalSheet.file} MD5: {modalSheet.md5}
)}
); } function renderDocuments(props) { return ; } window.CpDocumentsView = { renderDocuments, DocumentsViewComponent, };