{% extends 'base/base.html' %}
{% load static %}

{% block title %}{{ manufacturer.name }} - ThrillWiki{% endblock %}

{% block content %}
<div class="container mx-auto px-4">
    <!-- Manufacturer Header -->
    <div class="bg-white dark:bg-gray-800 shadow rounded-lg p-6 mb-6">
        <div class="flex flex-col md:flex-row justify-between items-start md:items-center">
            <div>
                <h1 class="text-3xl font-bold text-gray-900 dark:text-white mb-2">{{ manufacturer.name }}</h1>
                {% if manufacturer.headquarters %}
                    <p class="text-gray-600 dark:text-gray-400">
                        <i class="fas fa-map-marker-alt mr-2"></i>{{ manufacturer.headquarters }}
                    </p>
                {% endif %}
            </div>
            {% if manufacturer.website %}
                <a href="{{ manufacturer.website }}" target="_blank" rel="noopener noreferrer" 
                   class="btn-secondary mt-4 md:mt-0">
                    <i class="fas fa-external-link-alt mr-2"></i>Visit Website
                </a>
            {% endif %}
        </div>
        
        {% if manufacturer.description %}
            <div class="mt-6 prose dark:prose-invert max-w-none">
                {{ manufacturer.description|linebreaks }}
            </div>
        {% endif %}
    </div>

    <!-- Manufacturer Stats -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
        <div class="bg-white dark:bg-gray-800 shadow rounded-lg p-6 text-center">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides.count }}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Total Rides</div>
        </div>
        
        <div class="bg-white dark:bg-gray-800 shadow rounded-lg p-6 text-center">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides|filter:"type='ROLLER_COASTER'"|length }}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Roller Coasters</div>
        </div>
        
        <div class="bg-white dark:bg-gray-800 shadow rounded-lg p-6 text-center">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides|regroup:"park"|length }}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Parks with Rides</div>
        </div>
    </div>

    <!-- Rides List -->
    <div class="bg-white dark:bg-gray-800 shadow rounded-lg p-6">
        <h2 class="text-2xl font-bold text-gray-900 dark:text-white mb-6">Rides</h2>
        
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {% for ride in rides %}
                <div class="bg-gray-50 dark:bg-gray-700 rounded-lg overflow-hidden">
                    {% if ride.photos.exists %}
                        <img src="{{ ride.photos.first.image.url }}" 
                             alt="{{ ride.name }}"
                             class="w-full h-48 object-cover">
                    {% else %}
                        <div class="w-full h-48 bg-gray-200 dark:bg-gray-600 flex items-center justify-center">
                            <span class="text-gray-400">No image available</span>
                        </div>
                    {% endif %}
                    
                    <div class="p-4">
                        <h3 class="text-lg font-semibold mb-2">
                            <a href="{% url 'rides:ride_detail' ride.park.slug ride.slug %}" 
                               class="text-blue-600 dark:text-blue-400 hover:underline">
                                {{ ride.name }}
                            </a>
                        </h3>
                        <p class="text-gray-600 dark:text-gray-400 mb-2">
                            at <a href="{% url 'parks:park_detail' ride.park.slug %}" 
                                 class="hover:underline">{{ ride.park.name }}</a>
                        </p>
                        
                        {% if ride.coaster_stats %}
                            <div class="mt-2 space-y-1">
                                {% if ride.coaster_stats.height %}
                                    <div class="text-sm text-gray-500 dark:text-gray-400">
                                        Height: {{ ride.coaster_stats.height }}ft
                                    </div>
                                {% endif %}
                                {% if ride.coaster_stats.speed %}
                                    <div class="text-sm text-gray-500 dark:text-gray-400">
                                        Speed: {{ ride.coaster_stats.speed }}mph
                                    </div>
                                {% endif %}
                                {% if ride.coaster_stats.length %}
                                    <div class="text-sm text-gray-500 dark:text-gray-400">
                                        Length: {{ ride.coaster_stats.length }}ft
                                    </div>
                                {% endif %}
                            </div>
                        {% endif %}
                        
                        {% if ride.average_rating %}
                            <div class="mt-2 flex items-center">
                                <span class="text-yellow-400 mr-1">★</span>
                                <span class="text-gray-600 dark:text-gray-400">
                                    {{ ride.average_rating|floatformat:1 }}/10
                                </span>
                            </div>
                        {% endif %}
                    </div>
                </div>
            {% empty %}
                <div class="col-span-full text-center py-8">
                    <p class="text-gray-500 dark:text-gray-400">No rides found for this manufacturer.</p>
                </div>
            {% endfor %}
        </div>
    </div>
</div>
{% endblock %}
