<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}1D Poisson Simulator{% endblock %}</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    
    <!-- Custom CSS -->
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    
    {% block extra_css %}{% endblock %}
</head>
<body class="d-flex flex-column vh-100">
    <!-- Navigation -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <i class="bi bi-cpu"></i> 1D Poisson Simulator {{ app_version }}
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'index' %}active{% endif %}" href="/">
                            <i class="bi bi-house"></i> Home
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'builder' %}active{% endif %}" href="/builder">
                            <i class="bi bi-tools"></i> Structure Builder
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'results' %}active{% endif %}" href="/results">
                            <i class="bi bi-graph-up"></i> Results
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'materials_page' %}active{% endif %}" href="/materials">
                            <i class="bi bi-table"></i> Materials
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'settings' %}active{% endif %}" href="/settings">
                            <i class="bi bi-gear"></i> Settings
                        </a>
                    </li>
                    <li class="nav-item ms-2">
                        <span class="nav-link" id="licenseStatusBadge" style="cursor: pointer;"
                              title="License status" onclick="window.location.href='/settings'">
                            <i class="bi bi-shield-check text-success"></i>
                        </span>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <main class="container-fluid py-4 flex-grow-1 overflow-auto">
        {% block content %}{% endblock %}
    </main>

    <!-- Footer -->
    <footer class="bg-dark text-center py-2 mt-auto">
        <div class="container">
            <div id="footer-content">
                <p class="text-white mb-2">
                    Built with Flask & Python / powered by
                </p>
                <div id="logo-container">
<!--                    <span id="version-text">v1.0.0</span>-->
<!--                    <span id="powered-text">powered by</span>-->
                    <a href="https://www.swift4data.com" target="_blank">
                        <img src="/static/figs/s4d_logo.png" alt="Logo" id="logo">
                        <img src="/static/figs/s4d_text.png" alt="Logo text" id="logotext">
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- jQuery (optional, for convenience) -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    
    <!-- Custom JS -->
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>

    <script>
        // Check license status and update badge
        fetch('/api/license/status')
            .then(r => r.json())
            .then(data => {
                const badge = document.getElementById('licenseStatusBadge');
                if (!badge) return;
                if (data.activated) {
                    if (data.mode === 'offline_cached') {
                        badge.innerHTML = '<i class="bi bi-shield-exclamation text-warning"></i>';
                        badge.title = 'License: offline mode (' + data.grace_remaining_days + ' days remaining)';
                    } else {
                        badge.innerHTML = '<i class="bi bi-shield-check text-success"></i>';
                        badge.title = 'License: active';
                    }
                } else {
                    badge.innerHTML = '<i class="bi bi-shield-x text-secondary"></i> <small class="text-secondary">Demo</small>';
                    badge.title = 'Demo mode — click to activate license';
                    badge.onclick = function() { window.location.href = '/license'; };
                }
            })
            .catch(() => {});
    </script>
    
    {% block extra_js %}{% endblock %}
</body>
</html>
