<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GKPB-MDC Jombang</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 -->
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">

    <style>
        /* === style awal Anda tetap sama === */
        @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);
    }

        /* tambahan untuk card form edit */
        .card-edit {
            width: 100%;
            max-width: 900px;
            padding: 30px;
            border-radius: 20px;
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(20px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
            margin: auto;
        }
        .card-edit h2 { color: #fff; text-align: center; margin-bottom: 20px; }
        .card-edit label { color: #fff; font-weight: 600; display:block; margin: 15px 0 8px; }
        .card-edit input[type=text], 
        .card-edit textarea {
          width: 100%;
          padding: 14px;
          font-size: 16px;
          border-radius: 12px;
          border: 1px solid rgba(255, 255, 255, 0.3);
          background: rgba(255, 255, 255, 0.25);
          resize: vertical;
          box-sizing: border-box;
          color: #000;
        }
        .card-edit textarea.small { min-height: 100px; }
        .card-edit textarea.large { min-height: 500px; }
        .card-edit button {
          margin-top: 18px;
          width: 100%;
          padding: 16px;
          border: none;
          border-radius: 14px;
          font-size: 18px;
          font-weight: 600;
          color: white;
          background: linear-gradient(135deg, #4facfe, #00f2fe);
          cursor: pointer;
          transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        .card-edit button:active {
          transform: scale(0.94);
          box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25) inset;
        }
        #msg {
          text-align:center;
          margin-top:10px;
          font-weight:600;
          color:#fff;
          display:none;
        }
    </style>
</head>
<body>

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

<!-- Sidebar -->
<div class="sidebar" id="sidebar">
    <ul>
        <li><a href="/index"><i class="fas fa-th-large"></i> Home</a></li>
        <li><a href="/siap/warta"><i class="fa-solid fa-person-praying"></i> Warta</a></li>
        <li><a href="/siap/khotbah" class="active"><i class="fa-brands fa-youtube"></i> Khotbah mingguan</a></li>
        <li><a href="/siap/infouser"><i class="fa-solid fa-bell"></i> Informasi</a></li>
        <li><a href="/siap/youht"><i class="fa-solid fa-church"></i> Peserta Youht</a></li>
        <li><a href="/siap/kids"><i class="fas fa-heart"></i> star kids</a></li>
        <li><a href="#"><i class="fa-solid fa-user"></i> Akun Saya</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">GKPB MDC Jombang</h5>
</div>

<!-- Main Content -->
<div class="glass-card">
<?php
include 'db.php';

// --- Jika request via AJAX (fetch) untuk update ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax'])) {
    $id           = $_POST['id'];
    $youtube_link = $_POST['youtube_link'];
    $title        = $_POST['title'];
    $notes        = $_POST['notes'];

    $stmt = $conn->prepare("UPDATE catatan SET youtube_link=?, title=?, notes=? WHERE id=?");
    $stmt->bind_param("sssi", $youtube_link, $title, $notes, $id);

    if ($stmt->execute()) {
        echo json_encode(["status" => "success", "message" => "Sukses Simpan!"]);
    } else {
        echo json_encode(["status" => "error", "message" => "Gagal Simpan!"]);
    }
    exit;
}

// --- Ambil data awal ---
$sql = "SELECT * FROM catatan LIMIT 1";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
?>

  <div class="card-edit">
    <h2>Khotbah mingguan</h2>
    <form id="catatanForm">
      <input type="hidden" name="id" value="<?php echo $row['id']; ?>">

      <label for="youtube_link">YouTube (ganti tulisan live menjadi = embed) :</label>
      <input type="text" name="youtube_link" id="youtube_link" value="<?php echo htmlspecialchars($row['youtube_link']); ?>">

      <label for="title">Judul:</label>
      <textarea name="title" id="title" class="small"><?php echo htmlspecialchars($row['title']); ?></textarea>

      <label for="notes">Deskripsi Youtube :</label>
      <textarea name="notes" id="notes" class="large"><?php echo htmlspecialchars($row['notes']); ?></textarea>

      <button type="submit">Simpan</button>
    </form>
    <div id="msg"></div>
  </div>
</div> <!-- end glass-card -->

<footer>
  © 2025 GKPB MDC Jombang
</footer>

<!-- Script -->
<script>
document.getElementById('catatanForm').addEventListener('submit', async function(e){
    e.preventDefault();

    let formData = new FormData(this);
    formData.append('ajax', '1'); 

    let res = await fetch('', {
        method: 'POST',
        body: formData
    });
    let data = await res.json();

    const msg = document.getElementById('msg');
    msg.style.display = "block";
    msg.textContent = data.message;

    msg.style.color = (data.status === "success") ? "lime" : "red";

    setTimeout(() => { msg.style.display = "none"; }, 2000);
});

// 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;
    navigator.clipboard.writeText(text).then(() => {
        alert('Teks disalin: ' + text);
    });
}
</script>

</body>
</html>
