{% extends "admin/admin_base.html" %}

{% block admin_content %}
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="admin-toolbar">
                <h1 class="admin-toolbar__title"><i class="bi bi-puzzle-fill" aria-hidden="true"></i> Управление модулями</h1>
            </div>
            <div class="admin-card">
                <div class="card-header d-flex flex-wrap justify-content-between align-items-center gap-2">
                    <h5 class="mb-0">Модули</h5>
                    <div class="admin-toolbar__filters">
                        <input type="text" class="form-control form-control-sm" id="moduleSearch" placeholder="Поиск по имени, описанию..." style="max-width: 200px;">
                        <select class="form-select form-select-sm w-auto" id="typeFilter" onchange="refreshModules()" style="max-width: 160px;">
                            <option value="">Все типы</option>
                            <option value="db_driver">Драйвер БД</option>
                            <option value="sd_provider">Service Discovery</option>
                            <option value="protocol">Протокол</option>
                            <option value="integration">Интеграция</option>
                            <option value="auth">Аутентификация</option>
                            <option value="security">Безопасность</option>
                            <option value="functional">Функциональный</option>
                            <option value="crm">CRM</option>
                        </select>
                        <select class="form-select form-select-sm w-auto" id="enabledFilter" onchange="refreshModules()" style="max-width: 130px;">
                            <option value="">Статус</option>
                            <option value="true">Включён</option>
                            <option value="false">Отключён</option>
                        </select>
                        <select class="form-select form-select-sm w-auto" id="compatibleFilter" onchange="refreshModules()" style="max-width: 130px;">
                            <option value="">Совместимость</option>
                            <option value="true">Совместим</option>
                            <option value="false">Не совместим</option>
                        </select>
                        <select class="form-select form-select-sm w-auto" id="requiredFilter" onchange="refreshModules()" style="max-width: 120px;">
                            <option value="">Обязательность</option>
                            <option value="true">Обязательный</option>
                            <option value="false">Не обязательный</option>
                        </select>
                        <div class="form-check form-check-inline mb-0">
                            <input class="form-check-input" type="checkbox" id="includeAvailable" onchange="refreshModules()">
                            <label class="form-check-label small" for="includeAvailable">Показать доступные</label>
                        </div>
                        <button class="btn btn-primary btn-sm" onclick="refreshModules()">
                            <i class="bi bi-arrow-clockwise"></i> Обновить
                        </button>
                    </div>
                </div>
                <div class="card-body p-0">
                    <div class="admin-table-wrap">
                        <div id="modulesContainer">
                        <div class="text-center">
                            <div class="spinner-border text-primary" role="status">
                                <span class="visually-hidden">Загрузка...</span>
                            </div>
                        </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Модальное окно подробной информации о модуле -->
<div class="modal fade" id="infoModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Информация о модуле: <span id="infoModuleName"></span></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body" id="moduleInfoContainer">
                <div class="text-center"><div class="spinner-border text-primary"></div></div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block admin_scripts %}
<script src="{{ url_for('static', filename='js/modules.js') }}"></script>
{% endblock %}
