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

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

{% block content %}
<div class="container mx-auto px-4">
    <!-- Park Header -->
    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 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">{{ park.name }}</h1>
                <p class="text-gray-600 dark:text-gray-300">
                    <i class="fas fa-map-marker-alt mr-2"></i>{{ park.location }}
                </p>
            </div>
            <div class="mt-4 md:mt-0 flex gap-2">
                {% if park.website %}
                    <a href="{{ park.website }}" target="_blank" rel="noopener noreferrer" 
                       class="btn-secondary">
                        <i class="fas fa-external-link-alt mr-2"></i>Visit Website
                    </a>
                {% endif %}
                {% if user.is_authenticated %}
                    <button class="btn-secondary">
                        <i class="fas fa-edit mr-2"></i>Edit
                    </button>
                {% endif %}
            </div>
        </div>
        
        <div class="flex flex-wrap gap-2 mt-4">
            <span class="status-badge {% if park.status == 'OPERATING' %}status-operating
                       {% elif park.status == 'CLOSED_TEMP' or park.status == 'CLOSED_PERM' %}status-closed
                       {% elif park.status == 'UNDER_CONSTRUCTION' %}status-construction{% endif %}">
                {{ park.get_status_display }}
            </span>
            {% if park.average_rating %}
                <span class="status-badge bg-yellow-100 text-yellow-800 dark:bg-yellow-400/30 dark:text-yellow-200 dark:ring-1 dark:ring-yellow-400/30">
                    <i class="fas fa-star text-yellow-500 dark:text-yellow-300 mr-1"></i>
                    {{ park.average_rating|floatformat:1 }}/10
                </span>
            {% endif %}
        </div>
    </div>

    <!-- Park Stats -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 text-center transform transition-transform hover:-translate-y-1">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ rides.count }}
            </div>
            <div class="text-gray-600 dark:text-gray-300 mt-1">Total Attractions</div>
        </div>
        
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 text-center transform transition-transform hover:-translate-y-1">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {% with roller_coasters=rides|dictsortreversed:"category"|slice:":RC" %}
                    {{ roller_coasters|length }}
                {% endwith %}
            </div>
            <div class="text-gray-600 dark:text-gray-300 mt-1">Roller Coasters</div>
        </div>
        
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 text-center transform transition-transform hover:-translate-y-1">
            <div class="text-3xl font-bold text-blue-600 dark:text-blue-400">
                {{ areas.count }}
            </div>
            <div class="text-gray-600 dark:text-gray-300 mt-1">Areas</div>
        </div>
    </div>

    <!-- Main Content Grid -->
    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Left Column - Description and Areas -->
        <div class="lg:col-span-2">
            {% if park.description %}
                <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 mb-6">
                    <h2 class="text-2xl font-bold mb-4 text-gray-900 dark:text-white">About</h2>
                    <div class="text-gray-700 dark:text-gray-300">
                        {{ park.description|linebreaks }}
                    </div>
                </div>
            {% endif %}

            <!-- Park Areas -->
            {% if areas %}
                <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 mb-6">
                    <h2 class="text-2xl font-bold mb-4 text-gray-900 dark:text-white">Areas</h2>
                    <div class="grid gap-4">
                        {% for area in areas %}
                            <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                                <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">{{ area.name }}</h3>
                                {% if area.description %}
                                    <p class="text-gray-600 dark:text-gray-300 mb-2">
                                        {{ area.description }}
                                    </p>
                                {% endif %}
                                <div class="text-sm text-gray-500 dark:text-gray-400">
                                    {{ area.rides.count }} attractions
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>
            {% endif %}

            <!-- Rides List -->
            <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6">
                <h2 class="text-2xl font-bold mb-4 text-gray-900 dark:text-white">Attractions</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    {% for ride in rides %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <h3 class="text-lg font-semibold mb-2">
                                <a href="{% url 'rides:ride_detail' park.slug ride.slug %}" 
                                   class="text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300">
                                    {{ ride.name }}
                                </a>
                            </h3>
                            <div class="flex flex-wrap gap-2 mb-2">
                                <span class="status-badge bg-blue-100 text-blue-800 dark:bg-blue-400/30 dark:text-blue-200 dark:ring-1 dark:ring-blue-400/30">
                                    {{ ride.get_category_display }}
                                </span>
                                <span class="status-badge {% if ride.status == 'OPERATING' %}status-operating
                                    {% elif ride.status == 'CLOSED_TEMP' or ride.status == 'CLOSED_PERM' %}status-closed
                                    {% else %}status-construction{% endif %}">
                                    {{ ride.get_status_display }}
                                </span>
                            </div>
                            {% if ride.coaster_stats %}
                                <div class="text-sm text-gray-600 dark:text-gray-400 space-y-1">
                                    {% if ride.coaster_stats.height_ft %}
                                        <div>Height: {{ ride.coaster_stats.height_ft }}ft</div>
                                    {% endif %}
                                    {% if ride.coaster_stats.speed_mph %}
                                        <div>Speed: {{ ride.coaster_stats.speed_mph }}mph</div>
                                    {% endif %}
                                </div>
                            {% endif %}
                        </div>
                    {% empty %}
                        <div class="col-span-2 text-center py-8">
                            <p class="text-gray-500 dark:text-gray-400">No attractions found.</p>
                        </div>
                    {% endfor %}
                </div>
            </div>
        </div>

        <!-- Right Column - Quick Facts -->
        <div>
            <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6 mb-6">
                <h2 class="text-2xl font-bold mb-4 text-gray-900 dark:text-white">Quick Facts</h2>
                <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 gap-4">
                    {% if park.owner %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                                <i class="fas fa-building text-blue-500 dark:text-blue-400 w-5"></i>
                                <span class="ml-2">Operator</span>
                            </dt>
                            <dd class="text-gray-900 dark:text-white font-medium">
                                <a href="{% url 'companies:company_detail' park.owner.slug %}" 
                                   class="text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300">
                                    {{ park.owner.name }}
                                </a>
                            </dd>
                        </div>
                    {% endif %}
                    <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                        <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                            <i class="fas fa-globe text-blue-500 dark:text-blue-400 w-5"></i>
                            <span class="ml-2">Country</span>
                        </dt>
                        <dd class="text-gray-900 dark:text-white font-medium">
                            {{ park.get_country_name }}
                        </dd>
                    </div>
                    {% if park.opening_date %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                                <i class="fas fa-calendar-alt text-blue-500 dark:text-blue-400 w-5"></i>
                                <span class="ml-2">Opening Date</span>
                            </dt>
                            <dd class="text-gray-900 dark:text-white font-medium">
                                {{ park.opening_date }}
                            </dd>
                        </div>
                    {% endif %}
                    {% if park.closing_date %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                                <i class="fas fa-calendar-times text-blue-500 dark:text-blue-400 w-5"></i>
                                <span class="ml-2">Closing Date</span>
                            </dt>
                            <dd class="text-gray-900 dark:text-white font-medium">
                                {{ park.closing_date }}
                            </dd>
                        </div>
                    {% endif %}
                    {% if park.operating_season %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                                <i class="fas fa-clock text-blue-500 dark:text-blue-400 w-5"></i>
                                <span class="ml-2">Operating Season</span>
                            </dt>
                            <dd class="text-gray-900 dark:text-white font-medium">
                                {{ park.operating_season }}
                            </dd>
                        </div>
                    {% endif %}
                    {% if park.size_acres %}
                        <div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 transform transition-transform hover:-translate-y-1">
                            <dt class="flex items-center text-gray-600 dark:text-gray-300 mb-1">
                                <i class="fas fa-ruler-combined text-blue-500 dark:text-blue-400 w-5"></i>
                                <span class="ml-2">Size</span>
                            </dt>
                            <dd class="text-gray-900 dark:text-white font-medium">
                                {{ park.size_acres }} acres
                            </dd>
                        </div>
                    {% endif %}
                </div>
            </div>

            {% if park.photos.exists %}
                <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6">
                    <h2 class="text-2xl font-bold mb-4 text-gray-900 dark:text-white">Photos</h2>
                    <div class="grid grid-cols-2 gap-2">
                        {% for photo in park.photos.all %}
                            <div class="aspect-w-16 aspect-h-9">
                                <img src="{{ photo.image.url }}" 
                                     alt="{{ photo.caption|default:park.name }}"
                                     class="object-cover rounded-lg">
                            </div>
                        {% endfor %}
                    </div>
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
