<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Informasi</title>

  <!-- Font Awesome -->
  <link
    href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
    rel="stylesheet"
  />

  <style>
    /* Efek background gradasi RGB lebih halus dan lambat */
    body {
      background: linear-gradient(270deg, #ff7f7f, #7fff7f, #7f7fff, #ff7fff);
      background-size: 800% 800%;
      animation: gradientAnimation 250s ease infinite; /* dari 15s jadi 60s */
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-start;
      min-height: 100vh;
      margin: 0;
      font-family: "Times New Roman", sans-serif;
    }

    /* Animasi gradasi bergerak */
    @keyframes gradientAnimation {
      0% { background-position: 0% 50%; }
      50% { background-position: 100% 50%; }
      100% { background-position: 0% 50%; }
    }

    /* Glassmorphism transparan mengikuti background */
    .informasi-item {
      background: rgba(255, 255, 255, 0.18) !important;
      backdrop-filter: blur(15px) !important;
      -webkit-backdrop-filter: blur(15px) !important;
      border: 1px solid rgba(255, 255, 255, 0.25) !important;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25) !important;
      position: relative;
      border-radius: 15px;
      padding: 15px;
      margin-bottom: 20px;
      transition: transform 0.3s ease;
    }
    .informasi-item:hover {
      transform: scale(1.02);
    }

    /* Header tambahan */
    .additional-header {
      background: rgba(21, 101, 192, 0.4) !important;
      backdrop-filter: blur(10px) !important;
      -webkit-backdrop-filter: blur(10px) !important;
      border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
      color: white;
      padding: 10px;
      text-align: center;
      font-size: 18px;
      font-weight: bold;
      width: 94.1%;
      position: sticky;
      top: 0;
      z-index: 10;
    }

    /* Gaya lainnya tetap sama */
    #informasi-container {
      max-width: 330px;
      max-height: 200px;
      margin: 30px auto;
    }
    .informasi-item img {
      display: block;
      margin-bottom: 10px;
      margin-top: 1px;
      border-radius: 15px;
      max-width: 95%;
      height: auto;
    }
    .informasi-item h3 {
      font-size: 1.2em;
      margin-bottom: 10px;
      color: #2c3e50;
      display: flex;
      font-weight: 700;
      align-items: center;
    }
    .informasi-item h3 i {
      margin-right: 15px !important;
      color: green;
    }
    .informasi-item p {
      font-size: 15px;
      color: black;
      margin-bottom: 10px;
      white-space: pre-wrap;
    }
    .clickable-link {
      display: inline-block;
      color: #007bff;
      font-weight: bold;
      text-decoration: none;
      margin-top: 5px;
    }
    .clickable-link:hover {
      text-decoration: underline;
    }
    .tanggal {
      font-size: 12px;
      color: #1565c0;
      display: block;
      text-align: right;
    }
    .bola-kedip {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      animation: kedip 1.5s infinite;
    }
    @keyframes kedip {
      0% {opacity: 1; background-color: red;}
      20% {opacity: 0.8; background-color: blue;}
      40% {opacity: 0.6; background-color: green;}
      60% {opacity: 0.8; background-color: orange;}
      80% {opacity: 1; background-color: purple;}
      100% {opacity: 1; background-color: red;}
    }
    .hashtag {
      color: #1565c0;
      font-weight: bold;
    }
    .signature {
      font-size: 16px;
      font-weight: 700;
      color: #1565c0;
      font-style: italic;
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div class="additional-header">📢 INFORMASI {{nama_toko}}</div>
  <div id="informasi-container"></div>

  <script>
    function tambahkanHighlight(teks) {
      return teks.replace(/\*(.*?)\*/g, '<span class="highlight">$1</span>');
    }
    function replaceHashtags(text) {
      return text.replace(/#\w+/g, function(match) {
        return '<span class="hashtag">' + match + '</span>';
      });
    }
    function loadInformasi() {
      fetch("https://mdcjombang.id/siap/data.php")
        .then(response => response.json())
        .then(data => {
          data = data.filter(item => item.tanggal && !isNaN(new Date(item.tanggal).getTime()));
          data.sort((a, b) => new Date(b.tanggal).getTime() - new Date(a.tanggal).getTime());

          let informasiHTML = "";
          data.forEach((info, index) => {
            let tanggalStr = info.tanggal
              ? new Date(info.tanggal).toLocaleDateString("id-ID", {
                  year: "numeric",
                  month: "long",
                  day: "numeric"
                })
              : "";

            let konten = info.isi ? info.isi : "";
            konten = tambahkanHighlight(konten);
            konten = replaceHashtags(konten);

            informasiHTML += `<div class="informasi-item">`;
            if (index === 0) {
              informasiHTML += `<div class="bola-kedip"></div>`;
            }
            if (info.gambar) {
              informasiHTML += `<img src="${info.gambar}" alt="Gambar">`;
            }
            informasiHTML += `
                <h3>🔔  ${info.judul || "Tanpa Judul"}</h3>
                <p>${konten}</p>`;
            if (info.link) {
              informasiHTML += `<p><a href="${info.link}" target="_blank" class="clickable-link">🔗 Baca Selengkapnya Disini..</a></p>`;
            }
            informasiHTML += `
                ${tanggalStr ? `<div class="tanggal">${tanggalStr}</div>` : ""}
                <div class="signature">TEAM~DUNIA DIGITAL~</div>
              </div>
            `;
          });

          document.getElementById("informasi-container").innerHTML = informasiHTML;
        })
        .catch(error => {
          console.error("Error fetching data:", error);
          document.getElementById("informasi-container").innerHTML = "<p>Gagal memuat data.</p>";
        });
    }
    window.onload = function() {
      loadInformasi();
      setInterval(loadInformasi, 5000);
    };
  </script>
  
  <audio id="notifSound" src="https://assets.mixkit.co/active_storage/sfx/2446/2446-preview.mp3"></audio>
  <script>
    function playNotificationSound() {
        let audio = document.getElementById("notifSound");
        audio.play();
    }
    function checkForNewInfo() {
        fetch("https://mdcjombang.id/siap/data.php")
            .then(response => response.json())
            .then(data => {
                let lastInfo = localStorage.getItem("lastInfo");
                let newInfo = JSON.stringify(data); 
                if (lastInfo !== newInfo) {
                    playNotificationSound();
                    localStorage.setItem("lastInfo", newInfo);
                }
            })
            .catch(error => console.error("Error fetching data:", error));
    }
    setInterval(checkForNewInfo, 5000);
  </script>
</body>
</html>
