<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>mdcjombang</title>
    <link rel="icon" href="asecet/icon.png" type="image/x-icon">

    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- AOS (CSS) -->
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">

    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap');

        body {
            font-family: 'Poppins', sans-serif;
            background: conic-gradient(from -45deg, #ca49f7, #5a8ade, #62c6e0, #ca49f7);
            padding: 10px;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            margin: 0;
            overflow-x: hidden;
        }

        /* Overlay */
        .overlay {
            position: fixed;
            top: 0; left: 0;
            width: 100%; height: 100%;
            background: rgba(0,0,0,0.35);
            opacity: 0; visibility: hidden;
            transition: opacity 0.35s ease;
            z-index: 1000;
        }
        .overlay.active { opacity: 1; visibility: visible; }

        /* Sidebar */
        .sidebar {
            position: fixed; top: 0; left: 0;
            width: 270px; height: 100vh;
            background: rgba(255,255,255,0.15);
            backdrop-filter: blur(20px);
            color: white;
            padding-top: 70px;
            z-index: 1100;
            border-top-right-radius: 30px;
            border-bottom-right-radius: 30px;
            box-shadow: 4px 0 20px rgba(0,0,0,0.25);
            transform: translateX(-100%);
            transition: transform 0.35s cubic-bezier(0.25, 1, 0.3, 1);
        }
        .sidebar.active { transform: translateX(0); }
        .sidebar ul { list-style: none; padding: 0; margin: 0; }
        .sidebar ul li a {
            display: flex; align-items: center;
            padding: 14px 20px; margin: 6px 12px;
            border-radius: 12px; color: white;
            text-decoration: none; font-size: 16px;
        }
        .sidebar ul li a:hover {
            background: rgba(255,255,255,0.25);
        }
        .sidebar ul li a.active {
            background: rgba(0,123,255,0.35);
            box-shadow: inset 0 0 8px rgba(0,123,255,0.6);
        }
        .sidebar ul li i { margin-right: 14px; font-size: 20px; width: 25px; text-align: center; }

        /* Navbar */
        #navbar-top { position: sticky; top: 10px; z-index: 999; }
        .menu-btn { font-size: 24px; cursor: pointer; margin-right: 15px; color: #fff; }

        /* Konten */
        .glass-card {
            backdrop-filter: blur(20px);
            background: rgba(255, 255, 255, 0.25);
            border-radius: 20px;
            padding: 22px;
            max-width: 420px;
            width: 100%;
            color: #222;
            box-shadow: 0 8px 24px rgba(0,0,0,0.15);
            margin: 20px auto;
        }
        h2 {
            text-align: center;
            font-size: 20px;
            margin-bottom: 6px;
            font-weight: 600;
            color: #111;
        }
        .owner {
            text-align: center;
            font-size: 14px;
            color: #555;
            margin-bottom: 20px;
        }
        .account {
            background: rgba(255,255,255,0.6);
            padding: 14px 16px;
            border-radius: 14px;
            margin-bottom: 14px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: inset 0 0 6px rgba(0,0,0,0.05);
        }
        .label {
            font-size: 13px;
            font-weight: 500;
            color: #666;
            margin-bottom: 2px;
        }
        .number {
            font-size: 16px;
            font-weight: 600;
            color: #000;
            letter-spacing: 0.5px;
        }
        .copy-btn {
            background: rgba(0,0,0,0.05);
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
            padding: 6px 10px;
            color: #007aff;
            transition: all 0.25s ease;
        }
        .copy-btn:hover { background: rgba(0,0,0,0.1); }
        .upload-box {
            text-align: center;
            margin-top: 15px;
            padding: 15px;
            background: rgba(255,255,255,0.6);
            border-radius: 14px;
            cursor: pointer;
            border: 2px dashed rgba(0,0,0,0.1);
            transition: all 0.25s ease;
            font-size: 14px;
            color: #555;
        }
        .upload-box:hover { background: rgba(255,255,255,0.8); }
        .upload-box input { display: none; }
        .preview-img {
            max-width: 100%;
            margin-top: 10px;
            border-radius: 12px;
            display: none;
        }
        textarea {
            width: 100%;
            margin-top: 12px;
            padding: 12px;
            border-radius: 12px;
            border: 1px solid rgba(0,0,0,0.1);
            resize: none;
            font-family: inherit;
            font-size: 14px;
            background: rgba(255,255,255,0.6);
            transition: border 0.2s ease;
        }
        textarea:focus { border: 1px solid #007aff; outline: none; }
        button.send {
            margin-top: 15px;
            width: 100%;
            padding: 14px;
            border: none;
            border-radius: 12px;
            background: linear-gradient(135deg, #007aff, #0051c3);
            color: white;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            box-shadow: 0 4px 12px rgba(0,122,255,0.3);
            transition: all 0.3s ease;
        }
        button.send:hover {
            background: linear-gradient(135deg, #0066d6, #003e99);
            box-shadow: 0 6px 16px rgba(0,122,255,0.4);
        }
        /* Toast Notification */
        #toast {
            visibility: hidden;
            min-width: 220px;
            background-color: rgba(0,0,0,0.85);
            color: #fff;
            text-align: center;
            border-radius: 10px;
            padding: 12px;
            position: fixed;
            z-index: 1;
            left: 50%;
            bottom: 30px;
            transform: translateX(-50%);
            font-size: 14px;
            opacity: 0;
            transition: opacity 0.4s, visibility 0.4s;
        }
        #toast.show { visibility: visible; opacity: 1; }

        /* Kartu admin di dalam glass-card */
        .admin-card .card { border-radius:16px; box-shadow:0 6px 24px rgba(16,24,40,.06); }
        .admin-card .btn-gradient { background: linear-gradient(135deg,#2563eb,#06b6d4); color:#fff; border:none; }
        .admin-card .btn-gradient:hover { filter:brightness(1.05); }
        .admin-card .file-row { display:flex; align-items:center; gap:12px; }
        .admin-card .file-title { font-weight:700; }
        .admin-card .small-muted { font-size:12px; color:#64748b; }
        .admin-card iframe { width:100%; height:65vh; border:0; border-radius:12px; background:#fff; }
    </style>
</head>
<body>

<!-- Overlay -->
<div class="overlay" id="overlay"></div>

<!-- Sidebar -->
<div class="sidebar" id="sidebar">
    <ul>
 <li><a href="https://mdcjombang.id"><i class="fas fa-th-large"></i> Home</a></li>
        <li><a href="https://mdcjombang.id/siap/warta"><i class="fa-solid fa-person-praying"></i> Warta</a></li>
        <li><a href="https://mdcjombang.id/siap/khotbah"><i class="fa-brands fa-youtube"></i> Khotbah mingguan</a></li>
        <li><a href="https://mdcjombang.id/siap/ppt"><i class="fa-brands fa-youtube"></i> ppt mingguan</a></li>
        <li><a href="https://mdcjombang.id/siap/informasi"><i class="fa-solid fa-bell"></i> Informasi</a></li>
        <li><a href="https://mdcjombang.id/siap/youth" ><i class="fa-solid fa-church"></i> Peserta Youth</a></li>
        <li><a href="https://mdcjombang.id/id/starkids/starkids"><i class="fas fa-heart"></i> star kids</a></li>
        <li><a href="/siap/jadwal"><i class="fa-solid fa-user"></i> jadwal ibadah</a></li>
        <li><a href="/siap/youth/jadwal" class="active"><i class="fa-solid fa-user"></i> jadwal youth</a></li>
         <li><a href="/siap/youth/ppt"><i class="fa-solid fa-user"></i> ppt youhth</a></li>
         <li><a href="/siap/youth/id"><i class="fa-solid fa-user"></i> edit web youth</a></li>
        <li><a href="#"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
    </ul>
</div>

<!-- Navbar Top -->
<div id="navbar-top" class="d-flex align-items-center mb-3">
    <span class="menu-btn" id="menu-btn"><i class="fas fa-bars"></i></span>
    <h5 class="text-white m-0">mdcjombang</h5>
</div>

<!-- Main Content -->
<div class="glass-card">
    <?php // admin_ppt.php — dipertahankan fungsinya tanpa nested dokumen ?>
    <div class="container py-2 admin-card">
        <h1 class="mb-3">Admin File Manager <small class="text-muted">(PPT/PDF)</small></h1>
        <div class="row g-3">
            <div class="col-lg-5">
                <div class="card p-3">
                    <h5 class="mb-3">Upload PPT / PPTX / PDF</h5>
                    <form id="uploadForm">
                        <div class="mb-3">
                            <label class="form-label">Judul</label>
                            <input type="text" name="title" class="form-control" placeholder="Judul dokumen" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">File (.ppt / .pptx / .pdf)</label>
                            <input type="file" name="ppt_file" accept=".ppt,.pptx,.pdf" class="form-control" required>
                            <div class="form-text">Maks. 50MB</div>
                        </div>
                        <button class="btn btn-gradient" type="submit">
                            <i class="fa-solid fa-cloud-arrow-up me-1"></i> Upload
                        </button>
                    </form>
                </div>
            </div>
            <div class="col-lg-7">
                <div class="card p-3">
                    <div class="d-flex justify-content-between align-items-center mb-2">
                        <h5 class="m-0">Daftar File</h5>
                        <button class="btn btn-sm btn-outline-secondary" id="refreshBtn">
                            <i class="fa-solid fa-rotate"></i>
                        </button>
                    </div>
                    <div id="listArea"></div>
                </div>
            </div>
        </div>

        <div class="card p-3 mt-3" id="previewCard" style="display:none;">
            <div class="d-flex justify-content-between align-items-center mb-2">
                <h5 class="m-0" id="pvTitle">Preview</h5>
                <button class="btn btn-sm btn-outline-danger" onclick="hidePreview()">
                    <i class="fa-solid fa-xmark"></i>
                </button>
            </div>
            <iframe id="pvFrame"></iframe>
        </div>
    </div>
</div>

<footer>
  © 2025 SCARD-PROJECT
</footer>

<!-- Script -->
<script>
    // Sidebar toggle
    const menuBtn = document.getElementById('menu-btn');
    const sidebar = document.getElementById('sidebar');
    const overlay = document.getElementById('overlay');

    menuBtn.addEventListener('click', () => {
        sidebar.classList.toggle('active');
        overlay.classList.toggle('active');
    });

    overlay.addEventListener('click', () => {
        sidebar.classList.remove('active');
        overlay.classList.remove('active');
    });

    function copyText(id) {
        const text = document.getElementById(id)?.innerText || '';
        if (!text) return;
        navigator.clipboard.writeText(text).then(() => {
            alert('Teks disalin: ' + text);
        });
    }

    // ==== Admin File Manager JS (dipertahankan fungsinya) ====
    const listUrl = 'list_ppt.php';
    const uploadUrl = 'upload_ppt.php';
    const deleteUrl = 'delete_ppt.php';

    function bytesToSize(bytes) {
      const sizes = ['B','KB','MB','GB'];
      if (!bytes || bytes <= 0) return '-';
      const i = Math.floor(Math.log(bytes) / Math.log(1024));
      return (bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i];
    }
    function toAbs(u){ try{ return new URL(u, location.href).href }catch(e){ return u } }
    function iconFor(filename) {
      const f = (filename || '').toLowerCase();
      if (f.endsWith('.pdf')) return '<i class="fa-regular fa-file-pdf fa-2x text-danger"></i>';
      return '<i class="fa-regular fa-file-powerpoint fa-2x text-warning"></i>';
    }
    function esc(s){
      return String(s ?? '')
        .replace(/&/g,'&amp;')
        .replace(/</g,'&lt;')
        .replace(/>/g,'&gt;');
    }

    async function loadList() {
      const res = await fetch(listUrl, {cache:'no-store'});
      const data = await res.json();
      const wrap = document.getElementById('listArea');
      if (!Array.isArray(data) || data.length === 0) {
        wrap.innerHTML = '<div class="text-muted">Belum ada data.</div>'; return;
      }
      let html = '<div class="list-group">';
      data.forEach(it => {
        const uploaded = it.uploaded_at ? new Date(it.uploaded_at).toLocaleString('id-ID') : '-';
        const safeTitle = esc(it.title || 'Tanpa Judul');
        const safeFile = esc(it.filename || '');
        html += `
          <div class="list-group-item d-flex justify-content-between align-items-center">
            <div>
              <div class="file-row">
                ${iconFor(it.filename)}
                <div>
                  <div class="file-title">${safeTitle}</div>
                  <div class="small-muted">${safeFile} • ${bytesToSize(it.size||0)} • ${uploaded}</div>
                </div>
              </div>
            </div>
            <div class="d-flex gap-2">
              <a class="btn btn-sm btn-outline-primary" target="_blank" href="${it.url}"><i class="fa-solid fa-arrow-up-right-from-square"></i></a>
              <button class="btn btn-sm btn-outline-success" onclick="preview('${encodeURIComponent(it.url)}','${safeTitle.replace(/'/g,'&#39;')}')"><i class="fa-solid fa-eye"></i></button>
              <button class="btn btn-sm btn-outline-danger" onclick="hapus('${it.id}')"><i class="fa-solid fa-trash"></i></button>
            </div>
          </div>`;
      });
      html += '</div>';
      wrap.innerHTML = html;
    }

    function gviewURL(abs){
      const bust = (abs.indexOf('?')>-1)? '&' : '?';
      return 'https://docs.google.com/gview?embedded=true&url=' + encodeURIComponent(abs + bust + 't=' + Date.now());
    }

    function preview(encUrl, title) {
      const raw = decodeURIComponent(encUrl);
      const abs = toAbs(raw);
      const frame = document.getElementById('pvFrame');
      const pvCard = document.getElementById('previewCard');
      const pvTitle = document.getElementById('pvTitle');
      frame.src = gviewURL(abs);
      pvTitle.textContent = 'Preview: ' + title + ' (Google Viewer)';
      pvCard.style.display = 'block';
      window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'});
    }
    function hidePreview() {
      document.getElementById('pvFrame').src = '';
      document.getElementById('previewCard').style.display = 'none';
    }
    async function hapus(id) {
      if (!confirm('Yakin hapus file ini?')) return;
      const fd = new FormData();
      fd.append('id', id);
      const res = await fetch(deleteUrl, {method:'POST', body: fd});
      const json = await res.json();
      if (json && json.ok) { alert('Berhasil dihapus'); hidePreview(); loadList(); }
      else { alert(json.error || 'Gagal menghapus'); }
    }
    document.getElementById('uploadForm').addEventListener('submit', async (e) => {
      e.preventDefault();
      const fd = new FormData(e.target);
      const res = await fetch(uploadUrl, {method:'POST', body: fd});
      const json = await res.json();
      if (json && json.ok) { alert('Upload berhasil'); e.target.reset(); loadList(); }
      else { alert(json.error || 'Gagal upload'); }
    });
    document.getElementById('refreshBtn').addEventListener('click', loadList);
    window.addEventListener('load', loadList);
</script>

</body>
</html>