<?= $this->extend('layout/template');?>

<?= $this->section('conten');?>
<!-- KONTEN AREA UTAMA -->
<div class="max-w-7xl mx-auto px-4 py-8">
    <!-- GRID UTAMA (Membagi Kiri 3 Kolom & Kanan 1 Kolom) -->
    <div class="grid grid-cols-1 lg:grid-cols-4 gap-6 items-start">

        <!-- SISI KIRI: PREVIEW & DETAIL (Lebar 3 Kolom) -->
        <div class="lg:col-span-3 space-y-4">

            <!-- BUTTON KEMBALI -->
            <div class="flex items-center justify-between">
                <a href="<?= base_url('perpustakaan')?>" class="inline-flex items-center gap-1.5 bg-white hover:bg-gray-100 text-gray-700 border border-gray-300 rounded-lg p-2 px-4 text-xs font-bold shadow-sm transition">
                    ⬅ Kembali ke Perpustakaan
                </a>
            </div>

            <!-- BLOK DETAIL UTAMA -->
            <div class="bg-white border border-gray-200 rounded-xl p-6 shadow-sm space-y-6">

                <!-- HEADER INFORMASI TEMPLATE -->
                <div class="border-b border-gray-100 pb-4">
                    <div class="flex items-center gap-2 mb-2">
    <span class="text-[10px] bg-blue-100 text-blue-700 px-2 py-0.5 rounded font-bold uppercase tracking-wider"><?= esc($type); ?></span>
                        <span class="text-[10px] bg-gray-100 text-gray-600 px-2 py-0.5 rounded font-medium">Format: <?= esc($type); ?></span>
                    </div>
                    <h2 class="text-xl font-bold text-gray-900 md:text-2xl"><?= esc($infografis['judul']); ?></h2>
                </div>

                <!-- LAYOUT 2 COLUMN (PREVIEW & DESKRIPSI) -->
                <div class="grid grid-cols-1 md:grid-cols-5 gap-6">

                    <!-- SUB-KOLOM IFRAME PREVIEW (2 KOLOM) -->
                    <div class="md:col-span-2 space-y-3">
                        <div class="rounded-2xl p-3 bg-gradient-to-br from-slate-100 to-white border border-gray-200 shadow-lg relative overflow-hidden">
                            <!-- Header Preview -->
                            <div class="flex items-center justify-between mb-3 px-2">
                                <div class="flex items-center gap-2">
                                    <div class="w-8 h-8 rounded-lg bg-emerald-600 flex items-center justify-center text-white text-xs">
                                        📕
                                    </div>
                                    <div>
                                        <p class="text-xs font-bold text-gray-700">Perpustakaan Preview</p>
                                        <p class="text-[10px] text-gray-400">Mode tampilan saja</p>
                                    </div>
                                </div>
                                <span class="bg-emerald-600 text-white text-[9px] font-bold px-3 py-1 rounded-full shadow">LIVE</span>
                            </div>

                            <!-- Iframe Box -->
                            <div class="w-full aspect-[3/4] bg-white rounded-xl overflow-hidden shadow-inner border border-gray-200 relative select-none" oncontextmenu="return false;">
                                <!-- Pastikan URL Google Drive menggunakan ID yang dinamis -->
                                <iframe src="https://drive.google.com/file/d/<?= esc($infografis['tautan']); ?>/preview" class="w-full h-full border-0 pointer-events-auto" allow="autoplay" sandbox="allow-scripts allow-same-origin allow-forms" loading="lazy"></iframe>
                                <!-- Overlay anti copy -->
                                <div class="absolute inset-0 pointer-events-none"></div>
                            </div>
                        </div>
                        <p class="text-[10px] text-gray-400 text-center mt-3 italic">Gunakan zoom untuk Melihat Pdf lebih jelas</p>
                    </div>

                    <!-- SUB-KOLOM DESKRIPSI & DOWNLOAD (3 KOLOM) -->
                    <div class="md:col-span-3 flex flex-col justify-between space-y-4">
                        <div class="space-y-3">
                            <h3 class="text-xs font-bold text-gray-900 uppercase tracking-wider">Tentang File Ini</h3>
                            <div class="text-xs text-gray-600 leading-relaxed space-y-2">
                                <?= $infografis['keterangan']; ?>
                            </div>

                            <!-- DETAIL METADATA FILE -->
                            <div class="bg-slate-50 border border-gray-100 rounded-lg p-3 pt-2">
                                <h4 class="text-[11px] font-bold text-gray-700 mb-2">Informasi File:</h4>
                                <table class="w-full text-[11px] text-gray-600">
                                    <tbody>
                                        <tr>
                                            <td class="py-1 font-medium w-24">Ukuran File</td>
                                            <td class="py-1 text-gray-900">: <?= esc($infografis['kapasitas']); ?> KB</td>
                                        </tr>
                                        <tr>
                                            <td class="py-1 font-medium">Lisensi</td>
                                            <td class="py-1 text-emerald-600 font-semibold">: Gratis</td>
                                        </tr>
                                        <tr>
                                            <td class="py-1 font-medium">Kecocokan</td>
                                            <td class="py-1 text-gray-900">: Aplikasi Pdf, Crome , dll </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>

                        <!-- RUNNING DOWNLOAD ACTION -->
                        <div class="pt-4 border-t border-gray-100">
                            <p class="text-[11px] text-gray-400 mb-2">Klik tombol di bawah ini untuk mengunduh berkas:</p>
                            <div class="flex flex-col sm:flex-row gap-2">
                                <a href="https://docs.google.com/uc?export=download&id=<?= esc($infografis['tautan']); ?>" 
                                 target="_blank" 
                                 rel="noopener noreferrer" 
                                 class="flex-1 bg-[#007f98] hover:bg-[#00657a] text-white text-xs font-bold py-3 px-4 rounded-lg shadow-sm transition flex items-center justify-center gap-2 text-center">
                                 📥 DOWNLOAD (<?= strtoupper(esc($type)); ?>)
                             </a>
                         </div>
                     </div>
                 </div> <!-- AKHIR SUB-KOLOM DESKRIPSI -->

             </div> <!-- AKHIR LAYOUT 2 COLUMN -->
         </div> <!-- AKHIR BLOK DETAIL UTAMA -->
     </div> <!-- AKHIR SISI KIRI -->


     <!-- SISI KANAN: SIDEBAR REKOMENDASI (Lebar 1 Kolom) -->
     <div class="space-y-4">

         <div class="bg-white border border-slate-200/70 rounded-xl p-4 shadow-sm">
                <h4 class="text-xs font-bold text-slate-800 uppercase tracking-wide border-b border-slate-100 pb-2 mb-3">📋 Dokumen & Template</h4>
                <ul class="space-y-2 text-[11px] font-semibold text-slate-600">
                 <li class="flex items-center justify-between hover:text-[#0099b8] cursor-pointer transition">
                    <span class="flex items-center gap-2"><i class="fa-regular fa-file-word text-blue-600 text-sm w-4 text-center"></i> <a href="<?= base_url('dokumenfile/?type=word')?>">WORD</a></span>
                    <span class="bg-blue-50 text-blue-600 text-[9px] font-bold px-1.5 py-0.5 rounded"><?= $total_word ?></span>
                </li>
                <li class="flex items-center justify-between hover:text-[#0099b8] cursor-pointer transition">
                    <span class="flex items-center gap-2"><i class="fa-regular fa-file-excel text-emerald-600 text-sm w-4 text-center"></i> <a href="<?= base_url('dokumenfile/?type=excel')?>">EXCEL</a></span>
                    <span class="bg-emerald-50 text-emerald-600 text-[9px] font-bold px-1.5 py-0.5 rounded"><?= $total_xls ?></span>
                </li>
                <li class="flex items-center justify-between hover:text-[#0099b8] cursor-pointer transition">
                    <span class="flex items-center gap-2"><i class="fa-regular fa-file-powerpoint text-orange-600 text-sm w-4 text-center"></i> <a href="<?= base_url('dokumenfile/?type=ppt')?>">PPT</a></span>
                    <span class="bg-orange-50 text-orange-600 text-[9px] font-bold px-1.5 py-0.5 rounded"><?= $total_ppt ?></span>
                </li>
                <li class="flex items-center justify-between hover:text-[#0099b8] cursor-pointer transition">
                    <span class="flex items-center gap-2"><i class="fa-regular fa-file-pdf text-red-600 text-sm w-4 text-center"></i><a href="<?= base_url('dokumenfile/?type=pdf')?>"> PDF</a></span>
                    <span class="bg-red-50 text-red-600 text-[9px] font-bold px-1.5 py-0.5 rounded"><?= $total_pdf ?></span>
                </li>
                <li class="flex items-center justify-between hover:text-[#0099b8] cursor-pointer transition">
                    <span class="flex items-center gap-2"><i class="fa-regular fa-file-zipper text-purple-600 text-sm w-4 text-center"></i> <a href="<?= base_url('dokumenfile/?type=zip')?>">ZIP</a></span>
                    <span class="bg-purple-50 text-purple-600 text-[9px] font-bold px-1.5 py-0.5 rounded"><?= $total_zip ?></span>
                </li>
            </ul>
        </div>

        <!-- ===== BOX 1: UPDATE TERKINI ===== -->
        <div class="bg-white border border-gray-200 rounded-xl shadow-sm overflow-hidden">
            <div class="bg-slate-50 border-b border-gray-100 p-3 flex items-center justify-between">
                <div class="flex items-center gap-2">
                    <span class="text-amber-500"><i class="fa-solid fa-bolt"></i></span>
                    <span class="text-xs font-bold text-slate-800 uppercase tracking-wide">Update terkini</span>
                </div>
                <span class="bg-amber-100 text-amber-700 text-[9px] font-bold px-2 py-0.5 rounded">Baru</span>
            </div>

            <!-- ITEM 1: EXCEL -->
            <a href="dokumenfile.html?type=excel" class="flex items-center gap-3 p-3 hover:bg-slate-50 transition border-b border-slate-100 last:border-0">
                <div class="flex items-center justify-center w-9 h-9 rounded-lg bg-emerald-50 shrink-0">
                    <i class="fa-regular fa-file-excel text-emerald-600 text-base"></i>
                </div>
                <div class="flex-1 flex flex-col min-w-0">
                    <span class="text-xs font-semibold text-slate-700 truncate">Administrasi Kelurahan / RT</span>
                    <span class="text-[10px] text-slate-400 mt-0.5">Excel · Administrasi</span>
                </div>
                <span class="text-slate-400 text-sm"><i class="fa-solid fa-chevron-right text-[10px]"></i></span>
            </a>

            <!-- ITEM 2: WORD -->
            <a href="dokumenfile.html?type=word" class="flex items-center gap-3 p-3 hover:bg-slate-50 transition border-b border-slate-100 last:border-0">
                <div class="flex items-center justify-center w-9 h-9 rounded-lg bg-blue-50 shrink-0">
                    <i class="fa-regular fa-file-word text-blue-600 text-base"></i>
                </div>
                <div class="flex-1 flex flex-col min-w-0">
                    <span class="text-xs font-semibold text-slate-700 truncate">Struktur Komite Workshop Sekolah</span>
                    <span class="text-[10px] text-slate-400 mt-0.5">Word · Pendidikan</span>
                </div>
                <span class="text-slate-400 text-sm"><i class="fa-solid fa-chevron-right text-[10px]"></i></span>
            </a>
        </div>

       

        <!-- ===== pojok ilmu ===== -->
          <div class="sb-card">
            <div class="sb-head">
                <span class="sb-head-icon"><i class="fa-solid fa-display text-amber-500 text-sm"></i></span>
                <span class="sb-head-label">Pojok Ilmu Terbaru</span>
                <span class="sb-badge badge-hot">Baru</span>
            </div>

            <!-- pojok ilmu -->
            <?php foreach ($pojok_terbaru as $doc) : ?>
            <a href="<?= base_url('baca_pojok/' . $doc['id']); ?>" class="artikel-item flex items-center gap-3 p-3 hover:bg-slate-50 transition border-b border-slate-100 last:border-0">
                <div class="art-thumb flex items-center justify-center w-9 h-9 rounded-lg bg-blue-50 shrink-0">
                    <i class="fa-regular fa-lightbulb text-amber-500 text-sm"></i>
                </div>
                <div class="flex-1 flex flex-col min-w-0">
                    <span class="art-title text-xs font-semibold text-slate-700 truncate"><?= ucfirst(esc($doc['judul'])); ?></span>
                    <span class="art-sub text-[10px] text-slate-400 mt-0.5"><i class="fa-regular fa-clock text-[9px] mr-0.5"></i> <?= ucfirst(esc($doc['kategori'])); ?> </span>
                </div>
            </a>
             <?php endforeach; ?>
        </div>

    </div> <!-- AKHIR SISI KANAN -->
</div> <!-- AKHIR GRID UTAMA -->
</div> <!-- AKHIR KONTEN AREA UTAMA -->

<!-- Script Proteksi Konten -->
<script>
    document.addEventListener("copy", e => e.preventDefault());
    document.addEventListener("cut", e => e.preventDefault());
    document.addEventListener("contextmenu", e => e.preventDefault());
</script>
<?= $this->endSection(); ?>