<!DOCTYPE html>
<html lang="ru">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Workshop</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='workshop.css') }}">
    <script src="{{ url_for('static', filename='workshop.js') }}" defer></script>
</head>

<body>
    <div class="top-bar">
        <h1>Добро пожаловать в Workshop</h1>
    </div>

    <div class="main-container">
        <div class="cards-container">
            {% for map in maps_data %}
            <div class="card">
                <a href="/main?image_url={{ get_image_path(map[0]) }}&map_title={{ map[1] }}&{{ filters }}">
                    <img src="{{ get_image_path(map[0]) }}" alt="Map Image" width="200" height="110">
                </a>
                <img src="{{ get_star_image(map[2]) }}" alt="{{ map[2] }} stars" class="stars" width="81" height="14">
                <div class="card-title">{{ map[1] }}</div>
                <div class="description-popup">
                    <strong>{{ map[1] }}</strong>
                    <p>{{ map[3] }}</p>
                </div>
            </div>
            {% endfor %}
        </div>

        <div class="right-rectangle">
            <div class="sort-button-container">
                <button class="sort-button">Сортировать по дате</button>
            </div>
            <div class="game-modes">
                <div class="show-products-title">
                    Показать продукты, попадающие в каждую из выбранных категорий:
                </div>

                <div class="game-modes-title">РЕЖИМ ИГРЫ</div>

                {% for mode, label in {
                    "Classic": "Классический",
                    "Deathmatch": "Бой насмерть",
                    "Demolition": "Уничтожение объекта",
                    "Armsrace": "Гонка вооружений",
                    "Custom": "Пользовательский",
                    "Training": "Обучение",
                    "Co-op Strike": "Совместный налёт",
                    "Wingman": "Напарники",
                    "Flying Scoutsman": "Перелётные снайперы"
                }.items() %}
                <label class="game-mode">
                    <input type="checkbox" class="game-mode-checkbox" value="{{ mode }}" {% if mode in filters %}checked{% endif %}>
                    {{ label }}
                </label>
                {% endfor %}
            </div>
            <div class="search-container">
                <form method="get" action="/">
                    <div class="search-input-container">
                        <input type="text" id="search" class="search-input" name="search_title" placeholder="Поиск по названию" value="{{ request.args.get('search_title', '') }}">
                        <button class="search-button" type="submit">
                            <img src="/images/search-icon.png" alt="Поиск">
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <div id="sortModal" class="modal">
            <div class="modal-content">
                <span class="close-btn">&times;</span>
                <h2>Сортировать по дате</h2>
                <div class="modal-rectangle">
                    <span class="text-left">С</span>
                    <div class="first-rectangle">
                        <input type="date" class="date-input" />
                    </div>
                    <span class="text-center">ПО</span>
                    <div class="second-rectangle">
                        <input type="date" class="date-input" />
                    </div>
                </div>
                <button class="ok-button">ОК</button>
                <button class="cancel-button">Отмена</button>
            </div>
        </div>

        <div class="filter-stars">
            <div class="filter-title">
                <label>Фильтр по количеству звезд:</label>
            </div>
            <div class="stars-filter">
                <label><input type="checkbox" name="stars" value="1" {% if 'stars' in request.args and '1' in request.args.getlist('stars') %}checked{% endif %}> 1</label>
                <label><input type="checkbox" name="stars" value="2" {% if 'stars' in request.args and '2' in request.args.getlist('stars') %}checked{% endif %}> 2</label>
                <label><input type="checkbox" name="stars" value="3" {% if 'stars' in request.args and '3' in request.args.getlist('stars') %}checked{% endif %}> 3</label>
                <label><input type="checkbox" name="stars" value="4" {% if 'stars' in request.args and '4' in request.args.getlist('stars') %}checked{% endif %}> 4</label>
                <label><input type="checkbox" name="stars" value="5" {% if 'stars' in request.args and '5' in request.args.getlist('stars') %}checked{% endif %}> 5</label>
            </div>
        </div>

        <div class="pagination">
            {% if page > 1 %}
            <a class="pagebtn" href="/?page={{ page - 1 }}&{{ filters }}">&#60;</a>
            {% endif %}

            {% if page > 3 %}
            <a class="pagelink" href="/?page=1&{{ filters }}">1</a>
            <span class="pagination_space">...</span>
            {% endif %}

            {% for p in range(1, total_pages + 1) %}
            {% if p >= page - 1 and p <= page + 2 %}
            {% if p == page %}
            <span class="pagelink" style="color: #417A9B;">{{ p }}</span>
            {% else %}
            <a class="pagelink" href="/?page={{ p }}&{{ filters }}">{{ p }}</a>
            {% endif %}
            {% endif %}
            {% endfor %}

            {% if total_pages > 3 and page < total_pages - 2 %}
            <span class="pagination_space">...</span>
            <a class="pagelink" href="/?page={{ total_pages }}&{{ filters }}">{{ total_pages }}</a>
            {% endif %}

            {% if page < total_pages %}
            <a class="pagebtn" href="/?page={{ page + 1 }}&{{ filters }}">&#62;</a>
            {% endif %}
        </div>
    </div>
</body>

</html>
