<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IfcGref</title>
    <link rel="icon" type="image/x-icon" href="../static/images/flavicon.png">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            justify-content: flex-start;
            background-color: #f8f9fa;
            align-items: center;
            margin: 0;
            min-height: 100vh;
            padding: 20px 20px 130px;
            flex-direction: column;
            box-sizing: border-box;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            max-width: 500px;
            width: 100%;
            text-align: center;
            position: relative;
        }
        .header {
            width: 100%;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .logo {
            max-height: 60px;
        }
        h1 {
            margin-bottom: 20px;
            font-size: 24px;
            color: #333;
        }
        .error-message {
            color: red;
            margin-bottom: 20px;
        }
        .drop-zone {
            border: 2px dashed #ccc;
            padding: 30px;
            margin-bottom: 20px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .drop-zone.dragover {
            background-color: #e0e0e0;
        }
        input[type="file"] {
            display: none;
        }
        .highlight {
            color: #007bff;
            cursor: pointer;
        }
        .loader {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            display: none;
        }
        .loader img {
            width: 100px;
            height: 100px;
            animation: fadeInOut 2s infinite;
        }
        @keyframes fadeInOut {
            0% { opacity: 0; }
            50% { opacity: 1; }
            100% { opacity: 0; }
        }
        .box {
            display: inline-block;
            margin: 10px;
            padding: 20px;
            width: 50px;
            height: 50px;
            border: 0px solid #ccc;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
            overflow: hidden;
            position: relative;
            z-index: 2;
        }
        .box img {
            display: block;
            width: 30px;
            height: auto;
            margin: 0 auto;
        }
        .info-text {
            margin-top: 10px;
            font-size: 10px;
            text-align: center;
            color: #333;
        }
        .footer {
            position: fixed;
            left: 20px;
            right: 20px;
            bottom: 14px;
            display: grid;
            grid-template-columns: minmax(90px, 170px) minmax(220px, 1fr) minmax(90px, 170px);
            align-items: center;
            gap: 20px;
            z-index: 1;
        }
        .footer-logo {
            max-width: 170px;
            max-height: 58px;
            object-fit: contain;
        }
        .footer-logo-left {
            justify-self: start;
        }
        .footer-logo-right {
            justify-self: end;
        }
        .footer-copy {
            justify-self: center;
            max-width: 560px;
            text-align: center;
        }
        .footer-text {
            margin: 0;
            font-size: 8px;
            color: #333;
        }
        .footer-text2 {
            margin: 4px 0 0;
            font-size: 15px;
            color: #333;
        }
        .desktop-option {
            margin-top: 18px;
            padding-top: 16px;
            border-top: 1px solid #e6e8eb;
            text-align: left;
        }
        .desktop-option h2 {
            margin: 0 0 6px;
            font-size: 15px;
            font-weight: 600;
            color: #2f343a;
        }
        .desktop-option p {
            margin: 0 0 12px;
            font-size: 13px;
            line-height: 1.45;
            color: #5d6670;
        }
        .desktop-action {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-height: 34px;
            padding: 0 14px;
            border-radius: 6px;
            background: #24364b;
            color: #fff;
            font-size: 13px;
            font-weight: 600;
            text-decoration: none;
        }
        .desktop-action:hover {
            background: #182738;
        }
        .desktop-action[aria-disabled="true"] {
            background: #d4d8dd;
            color: #626c76;
            cursor: not-allowed;
        }
        .desktop-downloads {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
        }
        .desktop-download-card {
            min-width: 0;
        }
        .desktop-download-card .desktop-action {
            width: 100%;
            box-sizing: border-box;
        }
        .desktop-note {
            margin-top: 8px;
            font-size: 11px;
            color: #6f7882;
            overflow-wrap: anywhere;
        }
        @media (max-width: 700px) {
            body {
                padding-bottom: 170px;
            }
            .footer {
                grid-template-columns: 1fr 1fr;
                align-items: end;
                gap: 8px 16px;
            }
            .footer-logo {
                max-width: 130px;
                max-height: 44px;
            }
            .footer-copy {
                grid-column: 1 / -1;
                grid-row: 2;
                max-width: 100%;
            }
            .desktop-downloads {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <img src="../static/images/logo1.png" alt="Logo 1" class="logo">
        <a href="https://3d.bk.tudelft.nl/"><img src="../static/images/logo2.png" alt="Logo 2" class="logo"></a>
    </div>
    <div class="container">
        <h1>Upload .ifc file</h1>
        
        <!-- Display error message if present -->
        {% if error_message %}
        <p class="error-message">{{ error_message }}</p>
        {% endif %}
        
        <form method="POST" action="/upload" enctype="multipart/form-data" id="upload-form">
            <div class="drop-zone" id="drop-zone">
                <p>Drag & drop your .ifc file here, or <span class="highlight">click</span> to select it.</p>
                <input type="file" name="file" id="file-input">
            </div>
        </form>

        <div class="loader" id="loader">
            <img src="{{ url_for('static', filename='images/loading.png') }}" alt="Loading...">
        </div>

        {% if not desktop_mode %}
        <div class="desktop-option">
            <h2>Prefer to keep files local?</h2>
            <p>Download the desktop app to run IfcGref in your own browser on your computer. Files stay on the local machine and the desktop app has no upload size limit.</p>
            <div class="desktop-downloads">
                <div class="desktop-download-card">
                    {% if windows_desktop_package_available %}
                    <a class="desktop-action" href="{{ url_for('desktop_download', platform='windows') }}">Download Windows app</a>
                    <div class="desktop-note">{{ windows_desktop_package_name }}</div>
                    {% else %}
                    <span class="desktop-action" aria-disabled="true">Windows app unavailable</span>
                    <div class="desktop-note">Windows package is not built yet.</div>
                    {% endif %}
                </div>
                <div class="desktop-download-card">
                    {% if mac_desktop_package_available %}
                    <a class="desktop-action" href="{{ url_for('desktop_download', platform='mac') }}">Download Mac app</a>
                    <div class="desktop-note">{{ mac_desktop_package_name }}</div>
                    {% else %}
                    <span class="desktop-action" aria-disabled="true">Mac app unavailable</span>
                    <div class="desktop-note">Build on macOS to enable this download.</div>
                    {% endif %}
                </div>
            </div>
        </div>
        {% endif %}

    </div>

    <script>
        const dropZone = document.getElementById('drop-zone');
        const fileInput = document.getElementById('file-input');
        const form = document.getElementById('upload-form');
        const loader = document.getElementById('loader');

        dropZone.addEventListener('click', () => {
            fileInput.click();
        });

        fileInput.addEventListener('change', () => {
            if (fileInput.files.length) {
                showLoader();
                form.submit();
            }
        });

        dropZone.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropZone.classList.add('dragover');
        });

        dropZone.addEventListener('dragleave', () => {
            dropZone.classList.remove('dragover');
        });

        dropZone.addEventListener('drop', (e) => {
            e.preventDefault();
            dropZone.classList.remove('dragover');
            const files = e.dataTransfer.files;
            if (files.length) {
                fileInput.files = files;
                showLoader();
                form.submit();
            }
        });

        form.addEventListener('submit', (e) => {
            showLoader();
        });

        function showLoader() {
            loader.style.display = 'block';
        }
    </script>
    <!-- User Guide Box -->
    <div class="box" onclick="window.location.href='/templates/guid.html'">
        <img src="../static/images/info.png" alt="User Guide Image">
        <div class="info-text">User Guide</div>
    </div>
    <div class="footer">
        <img src="../static/images/eu.jpg" alt="Logo 3" class="footer-logo footer-logo-left">
        <div class="footer-copy">
        <p class="footer-text">This project has received funding from the European Union’s Horizon Europe programme under Grant Agreement No.101058559
        </p>
        <p class="footer-text2">Version 3.0
        </p>
        </div>
        <img src="../static/images/chek-logo.png" alt="Logo 4" class="footer-logo footer-logo-right">
    </div>
</body>
</html>
