<!DOCTYPE html>
<html>
<head>
    <title>Капча</title>
    <style>
        body {
            margin: 0;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: #f5f5f5;
        }

        .container {
            width: 90%;
            max-width: 600px;
            padding: 20px;
        }

        .category-header {
            text-align: center;
            font-size: 24px;
            margin-bottom: 25px;
            color: #333;
        }

        .image-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            width: 100%;
            margin: 0 auto;
        }

        .image-item {
            position: relative;
            cursor: pointer;
            border-radius: 8px;
            overflow: hidden;
            transition: all 0.2s ease;
            aspect-ratio: 1/1;
            width: 100%;
            background: #fff;
            box-shadow: 0 2px 6px rgba(0,0,0,0.1);
        }

        .image-item:hover {
            transform: scale(1.03);
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }

        .image-item.selected {
            transform: scale(0.97);
            box-shadow: 0 0 0 3px #4CAF50;
        }

        .image-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        button {
            display: block;
            margin: 25px auto 0;
            padding: 12px 35px;
            font-size: 17px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: background 0.2s ease;
        }

        button:hover {
            background: #45a049;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="category-header">Select all the images with {{ category }}</h1>
        <form method="post">
            {% csrf_token %}
            <div class="image-grid">
                {% for url in image_urls %}
                    <div class="image-item" data-index="{{ forloop.counter0 }}">
                        <img src="{{ url }}" alt="изображение {{ forloop.counter }}">
                    </div>
                {% endfor %}
            </div>
            <input type="hidden" name="selected" id="selected" value="">
            <button type="submit">Check</button>
        </form>
    </div>

    <script>
        const selectedIndices = new Set();
        document.querySelectorAll('.image-item').forEach(item => {
            item.addEventListener('click', function() {
                const index = this.dataset.index;
                this.classList.toggle('selected');
                
                selectedIndices.has(index) 
                    ? selectedIndices.delete(index) 
                    : selectedIndices.add(index);
                
                document.getElementById('selected').value = Array.from(selectedIndices).join(',') || '';
            });
        });
    </script>
</body>
</html>