/* ════════════════════════════════════════════════ Halaman Toko Buku — katalog + detail buku ════════════════════════════════════════════════ */ function TokoPage({ navigate }) { const [books, setBooks] = useState(((window.MQA || {}).buku || []).filter(b => b.active !== false)); const [cat, setCat] = useState('Semua'); const [detail, setDetail] = useState(null); useEffect(() => { const b = window.__openBuku; if (b && b.id) { window.__openBuku = null; setTimeout(() => setDetail(b), 120); } }, []); useEffect(() => { api.get('content.php?action=get_section§ion=buku').then(r => { const arr = (r.ok && r.data && Array.isArray(r.data.items)) ? r.data.items : null; if (arr && arr.length) setBooks(arr.filter(b => b.active !== false)); }).catch(() => {}); }, []); const allCats = ['Semua', ...new Set(books.flatMap(b => b.categories || []))]; const list = cat === 'Semua' ? books : books.filter(b => (b.categories || []).includes(cat)); return (
{allCats.map(c => { const active = c === cat; return ; })}
{list.map(b => { const disc = b.originalPrice && b.originalPrice > b.price; const bslug = b.slug || (window.slugify ? slugify(b.title) : b.id); const handle = (e) => { if (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1) return; e.preventDefault(); setDetail(b); }; return (
{b.cover_url ? : } {b.featured ? UNGGULAN : null} {disc ? HEMAT : null}

{b.title}

{b.author}
{fmtRp(b.price)} {disc ? {fmtRp(b.originalPrice)} : null}
); })}
{list.length === 0 &&
Belum ada buku di kategori ini.
}
{detail && setDetail(null)} />}
); } function BukuModal({ b, onClose }) { const disc = b.originalPrice && b.originalPrice > b.price; const pesanWA = () => window.open('https://wa.me/628123456789?text=' + encodeURIComponent(`Assalamu'alaikum, saya ingin memesan buku "${b.title}" (${fmtRp(b.price)}).`), '_blank'); return (
e.stopPropagation()} style={{ background: 'var(--surface)', borderRadius: 20, width: '100%', maxWidth: 560, maxHeight: '90vh', overflowY: 'auto', boxShadow: '0 30px 80px rgba(0,0,0,.35)' }}>
{b.cover_url ? : }

{b.title}

oleh {b.author}
{fmtRp(b.price)} {disc ? {fmtRp(b.originalPrice)} : null}

{b.desc}

{b.pages ? {b.pages} halaman : null} {b.weight ? · {b.weight} : null} {typeof b.stock === 'number' ? · Stok {b.stock} : null}
{b.tokopedia_url ? Tokopedia : null} {b.shopee_url ? Shopee : null}
); } window.TokoPage = TokoPage;