<html lang="en">

<head>
  <script>
    // Website status check
    console.log('🏄‍♂️ Tropical Corner Main Website is LIVE - ' + new Date().toLocaleString('fr-CH'));
    console.log('🌊 Services: Windsurf, SUP, Wing Foil & Restaurant');
    console.log('🛒 Shop: https://trop.ch/shop/');
  </script>

  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <!-- Compiled and minified CSS -->
  <!-- Bootstrap CSS V4.4 -->
  <!-- <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
      integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
      crossorigin="anonymous"
    /> -->
  <!-- Bootstrap V5.3 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
  <!-- Cookies -->
  <script src="https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js"
    integrity="sha256-0H3Nuz3aug3afVbUlsu12Puxva3CP4EhJtPExqs54Vg=" crossorigin="anonymous"></script>

  <!-- fontAwesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer">
  <!-- FONT : orkney -->
  <link rel="stylesheet" href="fonts/orkney_regular_macroman/stylesheet.css" type="text/css" charset="utf-8" />
  <link rel="icon" href="images/picto-cigne3.png" />
  <!-- fichier css -->
  <link rel="stylesheet" href="index.css" />

  <title>Tropical</title>

  <meta name="description" content="Windsurf, stand up paddle et guinguette" />
  <meta name="keywords" content="SUP, Windsurf, Buvette, Foil, Lac, Voile, Vent " />
  <!-- balise qui crée le thumbnail du site avec une image -->
  <meta property="og:title" content="Tropical" />
  <meta property="og:type" content="website" />
  <meta property="og:url" content="https://trop.ch/index.html" />
  <meta property="og:image" content="images/logoWhite3.png" />
</head>

<body style="background-color: #221f20; color: white">
  <!--TOP-->

  <div class="text-center">
    <!-- LOGO SHOP -->
    <div id="logoShop">
      <div style="margin-bottom: 5px">
        <a href="shop/index.php" class="text-white">
          <img src="images/shopping_cart.png" alt="" style="height: 40px;">
        </a>
      </div>
    </div>

    <!-- LOGO WEBCAM -->
    <!-- http://trop.dyndns.tv:10020/mjpg/video.mjpg -->
    <div id="logoWebcam">
      <div style="margin-bottom: 5px">
        <a href="/webcam.php" class="text-white">
          <img src="images/camera_trop.png" alt="" style="height: 30px;">
        </a>
      </div>
    </div>

    <!-- LOGO MON COMPTE -->
    <div class="" id="logoLogin">
      <div style="margin-bottom: 5px">
        <a href="login.php" class="text-white">
          <img src="images/persona_trop.png" alt="" style="height: 40px;">
        </a>
      </div>
    </div>
  </div>

  <!--LOGO QUI TOURNE -->

  <div id="contenurLogoPrincipal">
    <img class="rotate1" src="images/decoupe1.png" alt="imgLogoWeather"
      style="position: absolute; border-radius: 50%" />
    <img class="rotate0" src="images/decoupe2.png" alt="imgLogoWeather"
      style="position: absolute; border-radius: 50%" />
    <img class="rotate2" src="images/decoupe3.png" alt="imgLogoWeather"
      style="position: absolute; border-radius: 50%" />
    <img class="rotate1" src="images/decoupe4.png" alt="imgLogoWeather"
      style="position: absolute; border-radius: 50%" />
    <img class="rotate2" src="images/decoupe5.png" alt="imgLogoWeather"
      style="position: absolute; border-radius: 50%" />

    <a href="main.html">
      <img class="rotateNull" src="images/decoupe7.png" alt="imgLogoWeather" style="position: absolute" />
    </a>
  </div>

  <!-- RIGHT -->
  <div id="div_right">
    <div class="text-center">
      <a href="sports/foil.html">
        <img src="images/btnFoil.png" alt="logo" style="max-width: 100%; border-radius: 50%" />
      </a>

      <a href="sports/wing.html">
        <img src="images/btnWing.png" alt="logo" style="max-width: 100%; border-radius: 50%" />
      </a>
    </div>
  </div>

  <!-- LEFT -->
  <div id="div_left">
    <div class="text-center">
      <a href="sports/windsurf.html">
        <img src="images/btnWind.png" alt="logo" style="max-width: 100%; border-radius: 50%" />
      </a>

      <a href="sports/SUP.html">
        <img src="images/btnSup.png" alt="logo" style="max-width: 100%; border-radius: 50%" />
      </a>
    </div>
  </div>

  <!--BOTTOM (version Mobile) -->
  <div id="bottomdiv" style="text-align: center">
    <a href="sports/windsurf.html">
      <img src="images/btnWind.png" alt="logo" style="max-height: 100%; border-radius: 50%" />
    </a>

    <a href="sports/SUP.html">
      <img src="images/btnSup.png" alt="logo" style="max-height: 100%; border-radius: 50%" />
    </a>

    <a href="sports/foil.html">
      <img src="images/btnFoil.png" alt="logo" style="max-height: 100%; border-radius: 50%" />
    </a>

    <a href="sports/wing.html">
      <img src="images/btnWing.png" alt="logo" style="max-height: 100%; border-radius: 50%" />
    </a>
  </div>

  <!-- Modal WebCam HS -->
  <!-- Modal -->
  <div class="modal fade" id="webcam_hs_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h1 class="modal-title fs-5 text-black" id="exampleModalLabel">Webcam hors service</h1>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body text-black">
          Veuillez nous excuser pour la gêne occasionnée, la webcam sera malheureusement inactive durant la durée du
          chantier qui se déroule actuellement sur le site.
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
        </div>
      </div>
    </div>
  </div>

  <!-- NEWS -->
  <!-- MODAL
        -> Mise à jour: ne pas utiliser PHP mais un call AJAX sur un JSON
  -->

  <div class="modals"></div>


  <script>
    const array_newsID = [];
    var data_JSON;
    console.log("[NEWS] Lancement appel AJAX vers getNews.php...");
    $.ajax({
      url: "https://trop.ch/getNews.php",
      type: 'GET',
      dataType: 'json',
      success: function (res) {
        data_JSON = res;
        const date_now = new Date();
        console.log("[NEWS] Réponse reçue — " + res.length + " event(s) en BDD");
        console.log("[NEWS] Date actuelle:", date_now.toISOString());
        console.log("[NEWS] Données brutes:", JSON.stringify(res, null, 2));

        $.each(res, function (key, value) {
          array_newsID.push(value['id']);
          console.log("[NEWS] --- Event #" + value['id'] + " ---");
          console.log("[NEWS]   Titre: " + value['titre']);
          console.log("[NEWS]   Photo: " + value['photo']);
          console.log("[NEWS]   Période: " + value['date_debut_pub'] + " → " + value['date_fin_pub']);

          // création des modals
          $(".modals").append(`<div class="modal fade" id="ModalNews${value['id']}" tabindex="-1" aria-labelledby="ModalNews${value['id']}Label" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content text-white bg-black border-black" style="--bs-bg-opacity: .7;">
                      <div class="modal-header">
                        <h1 class="modal-title fs-5" id="ModalNews${value['id']}Label">${value['titre']}</h1>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                      <div class="modal-body">
                        <img src="https://admin.trop.ch/uploads/${value['photo']}" class="img-fluid rounded" alt="...">
                      </div>
                      <div class="modal-footer">
                        <a class="btn btn-light" href="news.php" role="button"> Plus d'infos
                        </a>
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
                      </div>
                    </div>
                  </div>
                </div>`
          );
          console.log("[NEWS]   Modal #ModalNews" + value['id'] + " créé dans le DOM");

          // afficher le modal si dans la plage de dates et pas déjà vu
          var cookieName = `cookie_news_${value['id']}`;
          const date_fin_event = new Date(value['date_fin_pub']);
          const date_debut_event = new Date(value['date_debut_pub']);
          const cookieValue = Cookies.get(cookieName);

          console.log("[NEWS]   Cookie '" + cookieName + "': " + (cookieValue ? cookieValue : "NON DÉFINI"));
          console.log("[NEWS]   Début pub: " + date_debut_event.toISOString() + " | Fin pub: " + date_fin_event.toISOString());
          console.log("[NEWS]   Dans la plage ? début <= now: " + (date_debut_event <= date_now) + " | fin >= now: " + (date_fin_event >= date_now));

          if (date_fin_event >= date_now && date_debut_event <= date_now) {
            if (cookieValue != null) {
              console.log("[NEWS]   ⏭️ Popup déjà vu (cookie existant)");
            } else {
              console.log("[NEWS]   ✅ AFFICHAGE du popup #ModalNews" + value['id']);
              $(`#ModalNews${value['id']}`).modal('show');
              Cookies.set(cookieName, 'shown', { expires: 1 });
              console.log("[NEWS]   Cookie '" + cookieName + "' créé (expire dans 1j)");
            }
          } else {
            console.log("[NEWS]   ⏭️ Hors plage de dates, popup non affiché");
          }
        });

        console.log("[NEWS] Terminé — " + array_newsID.length + " modal(s) créé(s), IDs: [" + array_newsID.join(", ") + "]");
      },
      error: function (xhr, status, error) {
        console.error("[NEWS] ❌ Erreur AJAX: " + status + " — " + error);
        console.error("[NEWS] HTTP " + xhr.status + ": " + xhr.responseText);
      }
    });
  </script>


  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
    crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"
    integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
    crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"
    integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD"
    crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM="
    crossorigin="anonymous"></script>


  <script>
    $(document).ready(function () {
      console.log("Document ready! (JQuery up and running :)");
    });

    //open modal for webcam HS
    // $("#logoWebcam").click(function () {
    //   $("#webcam_hs_modal").modal("show");
    // });

  </script>
</body>

</html>