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

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

{% block content %}
<div class="container px-4 mx-auto">
    <!-- Manufacturer Header -->
    <div class="p-6 mb-6 bg-white rounded-lg shadow dark:bg-gray-800">
        <div class="flex flex-col items-start justify-between md:flex-row md:items-center">
            <div>
                <h1 class="mb-2 text-3xl font-bold text-gray-900 dark:text-white">{{ manufacturer.name }}</h1>
                {% if manufacturer.headquarters %}
                    <p class="text-gray-600 dark:text-gray-400">
                        <i class="mr-2 fas fa-map-marker-alt"></i>{{ manufacturer.headquarters }}
                    </p>
                {% endif %}
            </div>
            {% if manufacturer.website %}
                <a href="{{ manufacturer.website }}" target="_blank" rel="noopener noreferrer" 
                   class="mt-4 btn-secondary md:mt-0">
                    <i class="mr-2 fas fa-external-link-alt"></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 gap-6 mb-6 md:grid-cols-3">
        <div class="p-6 text-center bg-white rounded-lg shadow dark:bg-gray-800">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides.count }}
            </div>
            <div class="mt-1 text-gray-600 dark:text-gray-400">Total Rides</div>
        </div>
        
        <div class="p-6 text-center bg-white rounded-lg shadow dark:bg-gray-800">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides|filter:"type='ROLLER_COASTER'"|length }}
            </div>
            <div class="mt-1 text-gray-600 dark:text-gray-400">Roller Coasters</div>
        </div>
        
        <div class="p-6 text-center bg-white rounded-lg shadow dark:bg-gray-800">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides|regroup:"park"|length }}
            </div>
            <div class="mt-1 text-gray-600 dark:text-gray-400">Parks with Rides</div>
        </div>
    </div>

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