<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Результаты поиска: {{ query }}</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .search-info {
            background-color: #e9ecef;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        .back-link {
            display: inline-block;
            margin-bottom: 20px;
            color: #007bff;
            text-decoration: none;
        }
        .back-link:hover {
            text-decoration: underline;
        }
        .movies-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }
        .movie-card {
            border: 1px solid #ddd;
            border-radius: 8px;
            overflow: hidden;
            background: white;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        .movie-poster {
            width: 100%;
            height: 200px;
            background-color: #f0f0f0;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #666;
        }
        .movie-poster img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .movie-info {
            padding: 15px;
        }
        .movie-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 8px;
            color: #333;
        }
        .movie-year {
            color: #666;
            margin-bottom: 8px;
        }
        .movie-overview {
            font-size: 14px;
            color: #555;
            line-height: 1.4;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .movie-rating {
            background-color: #007bff;
            color: white;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: bold;
            display: inline-block;
            margin-top: 8px;
        }
        .movie-actions {
            margin-top: 10px;
        }
        .btn-torrent {
            background-color: #28a745;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            transition: background-color 0.3s ease;
        }
        .btn-torrent:hover {
            background-color: #1e7e34;
        }
        .no-results {
            text-align: center;
            color: #666;
            font-size: 18px;
            padding: 40px;
        }
    </style>
</head>
<body>
    <div class="container">
        <a href="/" class="back-link">← Назад к поиску</a>
        
        <h1>Результаты поиска: "{{ query }}"</h1>
        
        <div class="search-info">
            Найдено фильмов: <strong>{{ total_results }}</strong>
        </div>
        
        {% if movies %}
            <div class="movies-grid">
                {% for movie in movies %}
                <div class="movie-card">
                    <div class="movie-poster">
                        {% if movie.poster_path %}
                            <img src="https://image.tmdb.org/t/p/w300{{ movie.poster_path }}" alt="{{ movie.title }}">
                        {% else %}
                            <div>Нет изображения</div>
                        {% endif %}
                    </div>
                    <div class="movie-info">
                        <div class="movie-title">{{ movie.title }}</div>
                        <div class="movie-year">{{ movie.release_date[:4] if movie.release_date else 'Год неизвестен' }}</div>
                        <div class="movie-overview">{{ movie.overview or 'Описание недоступно' }}</div>
                        {% if movie.vote_average %}
                            <div class="movie-rating">⭐ {{ "%.1f"|format(movie.vote_average) }}</div>
                        {% endif %}
                        <div class="movie-actions">
                            <button onclick="searchTorrents('{{ movie.title }}', '{{ movie.release_date[:4] if movie.release_date else '' }}')" 
                                    class="btn-torrent">
                                🔍 Найти торренты
                            </button>
                        </div>
                    </div>
                </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="no-results">
                Фильмы не найдены. Попробуйте изменить поисковый запрос.
            </div>
        {% endif %}
    </div>

    <script>
        function searchTorrents(movieTitle, year) {
            // Переходим на страницу поиска торрентов
            const url = year ? 
                `/torrents/${encodeURIComponent(movieTitle)}?year=${year}` : 
                `/torrents/${encodeURIComponent(movieTitle)}`;
            window.location.href = url;
        }
    </script>
</body>
</html>
