<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Django-Chain Examples{% endblock %}</title>

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">

    <style>
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            border-radius: 0.5rem;
            margin: 0.2rem 0;
        }
        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }
        .main-content {
            background-color: #f8f9fa;
            min-height: 100vh;
        }
        .card {
            border: none;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            border-radius: 0.75rem;
        }
        .card-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 0.75rem 0.75rem 0 0 !important;
        }
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .btn-primary:hover {
            background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
        }
        .status-success { color: #28a745; }
        .status-error { color: #dc3545; }
        .status-processing { color: #ffc107; }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- Sidebar -->
            <nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="position-sticky pt-3">
                    <div class="text-center mb-4">
                        <h4 class="text-white">
                            <i class="fas fa-link me-2"></i>Django-Chain
                        </h4>
                        <small class="text-light">Comprehensive Examples</small>
                    </div>

                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'dashboard' %}active{% endif %}"
                               href="{% url 'example:dashboard' %}">
                                <i class="fas fa-tachometer-alt me-2"></i>Dashboard
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'prompt_examples' %}active{% endif %}"
                               href="{% url 'example:prompt_examples' %}">
                                <i class="fas fa-comments me-2"></i>Prompts
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'workflow_examples' %}active{% endif %}"
                               href="{% url 'example:workflow_examples' %}">
                                <i class="fas fa-project-diagram me-2"></i>Workflows
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'chat_demo' %}active{% endif %}"
                               href="{% url 'example:chat_demo' %}">
                                <i class="fas fa-comment-dots me-2"></i>Chat Demo
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'vector_demo' %}active{% endif %}"
                               href="{% url 'example:vector_demo' %}">
                                <i class="fas fa-database me-2"></i>Vector Store
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'llm_test' %}active{% endif %}"
                               href="{% url 'example:llm_test' %}">
                                <i class="fas fa-cogs me-2"></i>LLM Testing
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'interaction_logs' %}active{% endif %}"
                               href="{% url 'example:interaction_logs' %}">
                                <i class="fas fa-list-alt me-2"></i>Interaction Logs
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'custom_workflow' %}active{% endif %}"
                               href="{% url 'example:custom_workflow' %}">
                                <i class="fas fa-code me-2"></i>Custom Workflows
                            </a>
                        </li>

                        <hr class="text-light">

                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'example:api_overview' %}" target="_blank">
                                <i class="fas fa-code me-2"></i>API Docs
                            </a>
                        </li>

                        <li class="nav-item">
                            <a class="nav-link" href="/admin/" target="_blank">
                                <i class="fas fa-user-shield me-2"></i>Django Admin
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- Main content -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
                <div class="pt-3 pb-2 mb-3">
                    {% block content %}
                    {% endblock %}
                </div>
            </main>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

    <script>
        // Common utility functions
        function showAlert(message, type = 'info') {
            const alertDiv = `
                <div class="alert alert-${type} alert-dismissible fade show" role="alert">
                    ${message}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            `;
            $('#alerts').html(alertDiv);

            // Auto-dismiss after 5 seconds
            setTimeout(() => {
                $('.alert').alert('close');
            }, 5000);
        }

        function makeApiCall(url, method = 'GET', data = null) {
            const config = {
                url: url,
                method: method,
                headers: {
                    'Content-Type': 'application/json',
                },
            };

            if (data) {
                config.data = JSON.stringify(data);
            }

            return $.ajax(config);
        }

        // Global error handler for AJAX requests
        $(document).ajaxError(function(event, xhr, settings, thrownError) {
            let errorMessage = 'An error occurred';
            try {
                const response = JSON.parse(xhr.responseText);
                errorMessage = response.message || response.error || errorMessage;
            } catch (e) {
                errorMessage = xhr.statusText || errorMessage;
            }
            showAlert(errorMessage, 'danger');
        });
    </script>

    {% block extra_js %}
    {% endblock %}
</body>
</html>
