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

{% block title %}{{ profile_user.username }}'s Profile - ThrillWiki{% endblock %}

{% block content %}
<div class="container px-4 mx-auto">
    <!-- Profile Header -->
    <div class="overflow-hidden bg-white rounded-lg shadow dark:bg-gray-800">
        <div class="p-6">
            <div class="flex items-center">
                {% if profile_user.profile.avatar %}
                <img src="{{ profile_user.profile.avatar.url }}"
                     alt="{{ profile_user.username }}"
                     class="object-cover w-24 h-24 rounded-full">
                {% else %}
                <div class="flex items-center justify-center w-24 h-24 text-white rounded-full bg-gradient-to-br from-primary to-secondary">
                    {{ profile_user.username.0|upper }}
                </div>
                {% endif %}
                <div class="ml-6">
                    <h1 class="text-2xl font-bold">
                        {{ profile_user.profile.display_name|default:profile_user.username }}
                    </h1>
                    {% if profile_user.profile.pronouns %}
                        <p class="text-gray-600 dark:text-gray-400">{{ profile_user.profile.pronouns }}</p>
                    {% endif %}
                    <div class="mt-2">
                        {% if profile_user.role != 'USER' %}
                            <span class="role-badge role-{{ profile_user.role|lower }}">
                                {{ profile_user.get_role_display }}
                            </span>
                        {% endif %}
                    </div>
                </div>
            </div>

            {% if profile_user.profile.bio %}
                <div class="mt-6">
                    <h2 class="mb-2 text-lg font-semibold">About Me</h2>
                    <p class="text-gray-600 dark:text-gray-400">{{ profile_user.profile.bio }}</p>
                </div>
            {% endif %}

            <!-- Social Links -->
            {% if profile_user.profile.twitter or profile_user.profile.instagram or profile_user.profile.youtube or profile_user.profile.discord %}
                <div class="flex mt-4 space-x-4">
                    {% if profile_user.profile.twitter %}
                        <a href="{{ profile_user.profile.twitter }}" target="_blank" rel="noopener noreferrer"
                           class="text-gray-600 dark:text-gray-400 hover:text-blue-500">
                            <i class="material-icons">link</i> Twitter
                        </a>
                    {% endif %}
                    {% if profile_user.profile.instagram %}
                        <a href="{{ profile_user.profile.instagram }}" target="_blank" rel="noopener noreferrer"
                           class="text-gray-600 dark:text-gray-400 hover:text-blue-500">
                            <i class="material-icons">link</i> Instagram
                        </a>
                    {% endif %}
                    {% if profile_user.profile.youtube %}
                        <a href="{{ profile_user.profile.youtube }}" target="_blank" rel="noopener noreferrer"
                           class="text-gray-600 dark:text-gray-400 hover:text-blue-500">
                            <i class="material-icons">link</i> YouTube
                        </a>
                    {% endif %}
                    {% if profile_user.profile.discord %}
                        <span class="text-gray-600 dark:text-gray-400">
                            <i class="material-icons">discord</i> {{ profile_user.profile.discord }}
                        </span>
                    {% endif %}
                </div>
            {% endif %}
        </div>
    </div>

    <!-- Statistics -->
    <div class="grid grid-cols-1 gap-4 mt-6 md:grid-cols-4">
        <div class="card">
            <div class="text-center card-body">
                <div class="stat-value">{{ profile_user.profile.coaster_credits }}</div>
                <div class="stat-label">Coaster Credits</div>
            </div>
        </div>
        <div class="card">
            <div class="text-center card-body">
                <div class="stat-value">{{ profile_user.profile.dark_ride_credits }}</div>
                <div class="stat-label">Dark Ride Credits</div>
            </div>
        </div>
        <div class="card">
            <div class="text-center card-body">
                <div class="stat-value">{{ profile_user.profile.flat_ride_credits }}</div>
                <div class="stat-label">Flat Ride Credits</div>
            </div>
        </div>
        <div class="card">
            <div class="text-center card-body">
                <div class="stat-value">{{ profile_user.profile.water_ride_credits }}</div>
                <div class="stat-label">Water Ride Credits</div>
            </div>
        </div>
    </div>

    <!-- Recent Activity -->
    <div class="grid grid-cols-1 gap-6 mt-6 md:grid-cols-2">
        <!-- Recent Reviews -->
        <div class="card">
            <div class="card-header">
                <h2 class="text-xl font-semibold">Recent Reviews</h2>
            </div>
            <div class="card-body">
                {% for review in park_reviews %}
                    <div class="mb-4 last:mb-0">
                        <div class="flex items-start justify-between">
                            <div>
                                <h3 class="font-medium">{{ review.title }}</h3>
                                <p class="text-sm text-gray-600 dark:text-gray-400">
                                    {{ review.park.name }}
                                </p>
                            </div>
                            <div class="flex items-center">
                                <span class="mr-1 text-yellow-400">★</span>
                                <span>{{ review.rating }}/10</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
                {% for review in ride_reviews %}
                    <div class="mb-4 last:mb-0">
                        <div class="flex items-start justify-between">
                            <div>
                                <h3 class="font-medium">{{ review.title }}</h3>
                                <p class="text-sm text-gray-600 dark:text-gray-400">
                                    {{ review.ride.name }}
                                </p>
                            </div>
                            <div class="flex items-center">
                                <span class="mr-1 text-yellow-400">★</span>
                                <span>{{ review.rating }}/10</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
                {% if not park_reviews and not ride_reviews %}
                    <p class="text-gray-500 dark:text-gray-400">No reviews yet.</p>
                {% endif %}
            </div>
        </div>

        <!-- Top Lists -->
        <div class="card">
            <div class="card-header">
                <h2 class="text-xl font-semibold">Top Lists</h2>
            </div>
            <div class="card-body">
                {% for list in top_lists %}
                    <div class="mb-4 last:mb-0">
                        <h3 class="font-medium">{{ list.title }}</h3>
                        <p class="text-sm text-gray-600 dark:text-gray-400">
                            {{ list.get_category_display }}
                        </p>
                    </div>
                {% empty %}
                    <p class="text-gray-500 dark:text-gray-400">No top lists created yet.</p>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
