<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= title %> - Website Hosting Service</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .hero-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 100px 0;
        }
        .feature-icon {
            font-size: 3rem;
            color: #667eea;
            margin-bottom: 1rem;
        }
        .upload-area {
            border: 2px dashed #ddd;
            border-radius: 10px;
            padding: 40px;
            text-align: center;
            transition: all 0.3s ease;
        }
        .upload-area:hover {
            border-color: #667eea;
            background-color: #f8f9ff;
        }
        .upload-area.dragover {
            border-color: #667eea;
            background-color: #eef2ff;
        }
        .lang-switch {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
        }
        .terms-link {
            color: #667eea;
            text-decoration: none;
        }
        .terms-link:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <!-- Google Translate Widget -->
    <div id="google_translate_element"></div>
    <script type="text/javascript">
        function googleTranslateElementInit() {
            new google.translate.TranslateElement({
                pageLanguage: 'en',
                includedLanguages: 'en,es,fr,de,ru',
                layout: google.translate.TranslateElement.InlineLayout.SIMPLE
            }, 'google_translate_element');
        }
    </script>
    <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

    <!-- Hero Section -->
    <section class="hero-section">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8 text-center">
                <h1 class="display-4 fw-bold mb-4">
                    <i class="fas fa-cloud-upload-alt me-3"></i>
                    Website Hosting Service
                </h1>
                <p class="lead mb-4">
                    Host your website for free for 24 hours. Simply upload your files and get started!
                </p>
                <div class="d-flex justify-content-center gap-3">
                    <a href="#upload" class="btn btn-light btn-lg">
                        <i class="fas fa-upload me-2"></i>Get Started
                    </a>
                    <a href="/plans" class="btn btn-outline-light btn-lg">
                        <i class="fas fa-list me-2"></i>View Plans
                    </a>
                </div>
            </div>
        </div>
    </div>
    </section>

    <!-- Features Section -->
    <section class="py-5">
        <div class="container">
            <div class="row text-center mb-5">
                <div class="col-lg-8 mx-auto">
                    <h2 class="display-5 fw-bold">Why Choose Us?</h2>
                    <p class="lead text-muted">Everything you need to host your website quickly and easily</p>
                </div>
            </div>
            <div class="row g-4">
                <div class="col-lg-4">
                    <div class="text-center">
                        <i class="fas fa-clock feature-icon"></i>
                        <h4>24-Hour Hosting</h4>
                        <p class="text-muted">Free hosting for a full day to test your website or run temporary campaigns</p>
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="text-center">
                        <i class="fas fa-file-archive feature-icon"></i>
                        <h4>Easy Upload</h4>
                        <p class="text-muted">Simply zip your website files and upload. We handle the rest!</p>
                    </div>
                </div>
                <div class="col-lg-4">
                    <div class="text-center">
                        <i class="fas fa-shield-alt feature-icon"></i>
                        <h4>Secure & Reliable</h4>
                        <p class="text-muted">Your files are safe with enterprise-grade security and fast global delivery</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Upload Section -->
    <section id="upload" class="py-5 bg-light">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-8">
                    <div class="card shadow">
                        <div class="card-body p-5">
                            <h3 class="card-title text-center mb-4">
                                <i class="fas fa-upload text-primary me-2"></i>
                                Upload Your Website
                            </h3>

                            <% if (typeof error !== 'undefined' && error) { %>
                                <div class="alert alert-danger" role="alert">
                                    <i class="fas fa-exclamation-triangle me-2"></i>
                                    <%= error %>
                                </div>
                            <% } %>

                            <form action="/rent" method="post" enctype="multipart/form-data" id="uploadForm">
                                <div class="mb-4">
                                    <input type="hidden" name="subdomain" value="site">
                                </div>

                                    <div class="mb-4">
                                        <label for="website" class="form-label">Website Files (ZIP or HTML)</label>
                                        <div class="upload-area" id="uploadArea">
                                            <div id="uploadContent">
                                                <i class="fas fa-cloud-upload-alt fa-3x text-muted mb-3"></i>
                                                <h5>Drag & drop your ZIP or HTML file here</h5>
                                                <p class="text-muted">or</p>
                                                <input type="file" class="form-control" id="website" name="website"
                                                       accept=".zip,.html" required style="display: none;">
                                                <button type="button" class="btn btn-primary" onclick="document.getElementById('website').click()">
                                                    <i class="fas fa-folder-open me-2"></i>Choose File
                                                </button>
                                                <p class="text-muted mt-2">
                                                    <small>Maximum file size: 100MB</small>
                                                </p>
                                            </div>
                                            <div id="fileInfo" style="display: none;">
                                                <i class="fas fa-file-archive fa-3x text-success mb-3"></i>
                                                <h5 id="fileName"></h5>
                                                <p class="text-muted" id="fileSize"></p>
                                                <button type="button" class="btn btn-outline-secondary" onclick="resetUpload()">
                                                    <i class="fas fa-times me-2"></i>Change File
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="mb-4">
                                        <label for="domains" class="form-label">Available Domains</label>
                                        <div class="card">
                                            <div class="card-body">
                                                <ul class="list-group">
                                                    <% if (typeof domains !== 'undefined' && domains.length > 0) { %>
                                                        <% domains.forEach(function(domain) { %>
                                                            <li class="list-group-item"><%= domain %></li>
                                                        <% }); %>
                                                    <% } else { %>
                                                        <li class="list-group-item">No domains available</li>
                                                    <% } %>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>

                                <div class="mb-4">
                                    <div class="form-check">
                                        <input type="checkbox" class="form-check-input" id="terms" name="terms" required>
                                        <label class="form-check-label" for="terms">
                                            I agree to the
                                            <a href="#termsModal" data-bs-toggle="modal" class="terms-link">
                                                Terms of Service
                                            </a>
                                        </label>
                                    </div>
                                </div>

                                <div class="d-grid">
                                    <button type="submit" class="btn btn-success btn-lg" id="submitBtn" disabled>
                                        <i class="fas fa-rocket me-2"></i>Launch Website
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Terms Modal -->
    <div class="modal fade" id="termsModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Terms of Service</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <h6>Free Hosting Terms</h6>
                    <ul>
                        <li>Websites are hosted for 24 hours only</li>
                        <li>Maximum file size is 100MB</li>
                        <li>No illegal, harmful, or malicious content allowed</li>
                        <li>We reserve the right to remove any content that violates these terms</li>
                        <li>Service is provided as-is without warranties</li>
                    </ul>
                    <h6>Acceptable Use</h6>
                    <ul>
                        <li>Personal websites and portfolios</li>
                        <li>Business landing pages</li>
                        <li>Event promotion pages</li>
                        <li>Testing and development sites</li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // File upload handling
        const uploadArea = document.getElementById('uploadArea');
        const uploadContent = document.getElementById('uploadContent');
        const fileInfo = document.getElementById('fileInfo');
        const fileInput = document.getElementById('website');
        const fileName = document.getElementById('fileName');
        const fileSize = document.getElementById('fileSize');
        const submitBtn = document.getElementById('submitBtn');
        const termsCheckbox = document.getElementById('terms');

        // Drag and drop functionality
        uploadArea.addEventListener('click', () => fileInput.click());

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

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

        uploadArea.addEventListener('drop', (e) => {
            e.preventDefault();
            uploadArea.classList.remove('dragover');

            const files = e.dataTransfer.files;
            if (files.length > 0) {
                fileInput.files = files;
                handleFileSelection(files[0]);
            }
        });

        fileInput.addEventListener('change', (e) => {
            if (e.target.files.length > 0) {
                handleFileSelection(e.target.files[0]);
            }
        });

        function handleFileSelection(file) {
            if ((file.type !== 'application/zip' && !file.name.endsWith('.zip')) && (file.type !== "text/html" && !file.name.endsWith(".html"))) {
                alert('Please select a valid ZIP or HTML file');
                return;
            }

            if (file.size > 100 * 1024 * 1024) {
                alert('File size must be less than 100MB');
                return;
            }

            fileName.textContent = file.name;
            fileSize.textContent = formatFileSize(file.size);
            uploadContent.style.display = 'none';
            fileInfo.style.display = 'block';
            submitBtn.disabled = !termsCheckbox.checked;
        }

        function resetUpload() {
            fileInput.value = '';
            uploadContent.style.display = 'block';
            fileInfo.style.display = 'none';
            submitBtn.disabled = true;
        }

        function formatFileSize(bytes) {
            if (bytes === 0) return '0 Bytes';
            const k = 1024;
            const sizes = ['Bytes', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        }

        termsCheckbox.addEventListener('change', () => {
            submitBtn.disabled = !termsCheckbox.checked || !fileInput.files.length;
        });

        // Form validation
        document.getElementById('uploadForm').addEventListener('submit', (e) => {
            if (!fileInput.files.length) {
                e.preventDefault();
                alert('Please select a file to upload');
                return;
            }

            if (!termsCheckbox.checked) {
                e.preventDefault();
                alert('Please accept the terms of service');
                return;
            }

            submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Uploading...';
            submitBtn.disabled = true;
        });
    </script>
</body>
</html>
