{% extends "base.html" %}

<!-- Заголовок страницы -->
{% block title %}
Настройки системы
{% endblock %}

<!-- Блок шапки -->
{% block head %}
{% endblock %}

<!-- Блок тела -->
{% block body %}
<div class="container mt-4">
    <h1 class="mb-4">Настройки системы</h1>

    <!-- Сообщения об успехе/ошибке -->
    <div id="alertContainer"></div>

    <div class="accordion" id="settingsAccordion">

        <!-- Блок пароля -->
        <div class="accordion-item">
            <h2 class="accordion-header">
                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
                    data-bs-target="#passwordSection">
                    <div class="d-flex align-items-center w-100">
                        <span class="me-3">Пароль администратора</span>
                        <span id="passwordStatus" class="badge bg-secondary">Не настроен</span>
                    </div>
                </button>
            </h2>
            <div id="passwordSection" class="accordion-collapse collapse" data-bs-parent="#settingsAccordion">
                <div class="accordion-body">
                    <form id="passwordForm">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="currentPassword" class="form-label">Текущий пароль</label>
                                <input type="password" class="form-control" id="currentPassword" required>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="newPassword" class="form-label">Новый пароль</label>
                                <input type="password" class="form-control" id="newPassword" required>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="confirmPassword" class="form-label">Подтверждение пароля</label>
                                <input type="password" class="form-control" id="confirmPassword" required>
                            </div>
                        </div>
                        <button type="submit" class="btn btn-danger">Сменить пароль</button>
                        <small class="text-muted d-block mt-2">После смены пароля произойдет автоматический выход из
                            системы</small>
                    </form>
                </div>
            </div>
        </div>

        <!-- Блок Медодс -->
        <div class="accordion-item">
            <h2 class="accordion-header">
                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
                    data-bs-target="#medodsSection">
                    <div class="d-flex align-items-center w-100">
                        <span class="me-3">Интеграция с Медодс</span>
                        <span id="medodsStatus" class="badge bg-secondary">Не настроен</span>
                    </div>
                </button>
            </h2>
            <div id="medodsSection" class="accordion-collapse collapse" data-bs-parent="#settingsAccordion">
                <div class="accordion-body">
                    <form id="medodsForm">
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label for="medodsHost" class="form-label">Host API (без 'https://' или
                                    'http://')</label>
                                <input type="text" class="form-control" id="medodsHost" placeholder="api.medods.ru">
                            </div>
                            <div class="col-md-6">
                                <label for="medodsPort" class="form-label">Port</label>
                                <input type="number" class="form-control" id="medodsPort" placeholder="443" min="1"
                                    max="65535">
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="medodsCsvFile" class="form-label">CSV файл с учетными данными:
                                <span id="medodsApiKeyStatus" class="badge bg-secondary">нет</span>
                            </label>
                            <input class="form-control" type="file" id="medodsCsvFile" accept=".csv">
                            <div class="form-text">
                                Загрузите CSV файл, содержащий identity и secretKey
                            </div>
                        </div>

                        <div class="d-flex gap-2">
                            <button type="button" id="testMedodsBtn" class="btn btn-outline-primary" disabled>
                                Проверить соединение
                            </button>
                            <button type="submit" id="saveMedodsBtn" class="btn btn-primary" disabled>
                                Сохранить настройки
                            </button>
                            <button type="button" id="cancelMedodsBtn" class="btn btn-outline-secondary" disabled>
                                Отменить изменения
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Блок N3Health -->
        <div class="accordion-item">
            <h2 class="accordion-header">
                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
                    data-bs-target="#n3healthSection">
                    <div class="d-flex align-items-center w-100">
                        <span class="me-3">Интеграция с N3Health</span>
                        <span id="n3healthStatus" class="badge bg-secondary">Не настроен</span>
                    </div>
                </button>
            </h2>
            <div id="n3healthSection" class="accordion-collapse collapse" data-bs-parent="#settingsAccordion">
                <div class="accordion-body">
                    <form id="n3healthForm">
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="n3healthHost" class="form-label">Host API</label>
                                <input type="text" class="form-control" id="n3healthHost"
                                    placeholder="Вида: https://b2b-demo.n3health.ru/sep/api">
                            </div>
                            <div class="col-md-6 mb-3">
                                <label for="n3healthAuthorization" class="form-label">Authorization (Токен доступа
                                    СЭП)</label>
                                <input type="text" class="form-control" id="n3healthAuthorization"
                                    placeholder="Вида: 44556afd-0e84-b847-2322-75999668f590">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label for="n3healthXIdLpu" class="form-label">idLPU (Идентификатор МО)</label>
                                <input type="text" class="form-control" id="n3healthXIdLpu"
                                    placeholder="Вида: 0453937e-fad5-402d-aacb-3ce6df2bf6fe">
                            </div>
                        </div>

                        <div class="d-flex gap-2">
                            <button type="button" id="testN3HealthBtn" class="btn btn-outline-primary" disabled>
                                Проверить соединение
                            </button>
                            <button type="submit" id="saveN3HealthBtn" class="btn btn-primary" disabled>
                                Сохранить настройки
                            </button>
                            <button type="button" id="cancelN3HealthBtn" class="btn btn-outline-secondary" disabled>
                                Отменить изменения
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </div>
</div>
{% endblock %}

<!-- Блок скриптов -->
{% block scripts %}
<script src="{{ url_for('static', path='js/settings.js') }}"></script>
{% endblock %}