{% extends 'base.html' %}

{% block content %}
<div class="row justify-content-center my-5">
    <div class="col-lg-10">
        <h1 class="mb-4">Данные запроса</h1>

        <div class="data-card mb-4">
            <h3>Форма авторизации</h3>
            <form method="POST" action="{{ url_for('request_data') }}" class="login-form">
                <div class="mb-3">
                    <label for="login" class="form-label">Логин</label>
                    <input type="text" class="form-control" id="login" name="login" placeholder="Введите логин">
                </div>
                <div class="mb-3">
                    <label for="password" class="form-label">Пароль</label>
                    <input type="password" class="form-control" id="password" name="password" placeholder="Введите пароль">
                </div>
                <button type="submit" class="btn btn-primary">Войти</button>
            </form>

            {% if form_data %}
            <div class="mt-4">
                <h4>Отправленные данные формы</h4>
                <table class="data-table">
                    <thead>
                        <tr>
                            <th>Параметр</th>
                            <th>Значение</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>login</td>
                            <td>{{ form_data.login }}</td>
                        </tr>
                        <tr>
                            <td>password</td>
                            <td>{{ form_data.password }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            {% endif %}
        </div>

        <div class="data-card mb-4">
            <h3>Параметры URL (request.args)</h3>
            {% if url_params %}
            <table class="data-table">
                <thead>
                    <tr>
                        <th>Параметр</th>
                        <th>Значение</th>
                    </tr>
                </thead>
                <tbody>
                    {% for key, value in url_params.items() %}
                    <tr>
                        <td>{{ key }}</td>
                        <td>{{ value }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <p class="text-muted-custom">Нет параметров URL. Попробуйте добавить параметры в адресную строку, например: <code>?fname=Egor&lname=Deev&age=21</code></p>
            {% endif %}
        </div>

        <div class="data-card mb-4">
            <h3>Заголовки запроса (request.headers)</h3>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>Заголовок</th>
                        <th>Значение</th>
                    </tr>
                </thead>
                <tbody>
                    {% for key, value in headers %}
                    <tr>
                        <td>{{ key }}</td>
                        <td class="header-value">{{ value }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <div class="data-card mb-4">
            <h3>Cookie (request.cookies)</h3>
            {% if cookies %}
            <table class="data-table">
                <thead>
                    <tr>
                        <th>Имя</th>
                        <th>Значение</th>
                    </tr>
                </thead>
                <tbody>
                    {% for key, value in cookies.items() %}
                    <tr>
                        <td>{{ key }}</td>
                        <td>{{ value }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <p class="text-muted-custom">Нет cookie в текущем запросе.</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
