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

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

{% block content %}
<div class="container mx-auto px-4">
    <!-- Company 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">{{ company.name }}</h1>
                {% if company.headquarters %}
                    <p class="text-gray-600 dark:text-gray-400">
                        <i class="fas fa-map-marker-alt mr-2"></i>{{ company.headquarters }}
                    </p>
                {% endif %}
            </div>
            {% if company.website %}
                <a href="{{ company.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 company.description %}
            <div class="mt-6 prose dark:prose-invert max-w-none">
                {{ company.description|linebreaks }}
            </div>
        {% endif %}
    </div>

    <!-- Company 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">
                {{ parks.count }}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Theme Parks</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">
                {{ parks|length }}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Active Parks</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">
                {% with total_rides=0 %}
                    {% for park in parks %}
                        {% with total_rides=total_rides|add:park.rides.count %}{% endwith %}
                    {% endfor %}
                    {{ total_rides }}
                {% endwith %}
            </div>
            <div class="text-gray-600 dark:text-gray-400 mt-1">Total Attractions</div>
        </div>
    </div>

    <!-- Parks 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">Theme Parks</h2>
        
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            {% for park in parks %}
                <div class="bg-gray-50 dark:bg-gray-700 rounded-lg overflow-hidden">
                    {% if park.photos.exists %}
                        <img src="{{ park.photos.first.image.url }}" 
                             alt="{{ park.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 'parks:park_detail' park.slug %}" 
                               class="text-blue-600 dark:text-blue-400 hover:underline">
                                {{ park.name }}
                            </a>
                        </h3>
                        <p class="text-gray-600 dark:text-gray-400 mb-2">{{ park.location }}</p>
                        <div class="flex justify-between items-center">
                            <span class="text-sm text-gray-500 dark:text-gray-400">
                                {{ park.rides.count }} attractions
                            </span>
                            {% if park.average_rating %}
                                <div class="flex items-center">
                                    <span class="text-yellow-400 mr-1">★</span>
                                    <span class="text-gray-600 dark:text-gray-400">
                                        {{ park.average_rating|floatformat:1 }}/10
                                    </span>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% empty %}
                <div class="col-span-full text-center py-8">
                    <p class="text-gray-500 dark:text-gray-400">No parks found for this company.</p>
                </div>
            {% endfor %}
        </div>
    </div>
</div>
{% endblock %}
