<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Synthetic Data Kit{% endblock %}</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
    
    <!-- Custom CSS -->
    <style>
        .navbar-brand img {
            height: 30px;
            margin-right: 8px;
        }
        .json-viewer {
            min-height: 400px;
        }
        pre {
            white-space: pre-wrap;
            word-wrap: break-word;
            background-color: #f8f9fa;
            padding: 15px;
            border-radius: 5px;
        }
        .qa-pair {
            margin-bottom: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 15px;
        }
        .qa-pair .question {
            font-weight: bold;
            color: #007bff;
        }
        .qa-pair .answer {
            margin-top: 10px;
        }
        .qa-pair .reasoning {
            margin-top: 10px;
            font-style: italic;
            background-color: #f8f9fa;
            padding: 10px;
            border-radius: 5px;
        }
    </style>
    
    {% block extra_head %}{% endblock %}
</head>
<body>
    <!-- Loading Overlay -->
    <div id="loading-overlay" class="position-fixed w-100 h-100 d-none" style="background-color: rgba(0,0,0,0.5); z-index: 9999; top: 0; left: 0;">
      <div class="d-flex justify-content-center align-items-center h-100">
        <div class="text-center text-white">
          <div class="spinner-border text-primary mb-3" role="status" style="width: 3rem; height: 3rem;">
            <span class="visually-hidden">Loading...</span>
          </div>
          <h5 id="loading-message">Processing... Please wait</h5>
          <p class="small">This may take a minute or two depending on the model size and task</p>
        </div>
      </div>
    </div>
    
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">
                Synthetic Data Kit
            </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">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('ingest') }}">Ingest Document</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('create') }}">Create Content</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('curate') }}">Curate QA Pairs</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('files') }}">File Browser</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('upload') }}">Upload File</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container">
        <!-- Flash messages -->
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        <!-- Main content -->
        {% block content %}{% endblock %}
    </div>

    <footer class="mt-5 py-3 bg-light">
        <div class="container text-center">
            <p class="mb-0">Synthetic Data Kit Web Interface</p>
        </div>
    </footer>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- Custom scripts -->
    {% block scripts %}{% endblock %}
  
  <!-- Common JavaScript for loading indicator -->
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // Get all forms with class 'loading-form'
      const forms = document.querySelectorAll('form.loading-form');
      const loadingOverlay = document.getElementById('loading-overlay');
      const loadingMessage = document.getElementById('loading-message');
      
      // Add submit event listener to each form
      forms.forEach(function(form) {
        form.addEventListener('submit', function(e) {
          // Get custom loading message if specified
          const customMessage = form.getAttribute('data-loading-message');
          if (customMessage) {
            loadingMessage.textContent = customMessage;
          } else {
            loadingMessage.textContent = 'Processing... Please wait';
          }
          
          // Show loading overlay
          loadingOverlay.classList.remove('d-none');
        });
      });
    });
  </script>
</body>
</html>
