{% extends "base.html" %}
{% block content %}
<div class="max-w-4xl mx-auto">
  <div class="bg-white rounded-lg shadow-md overflow-hidden mb-8">
    <!-- Profile Header -->
    <div class="bg-irish-green text-white p-6">
      <div class="flex flex-col sm:flex-row items-center">
        <div class="w-24 h-24 rounded-full bg-white border-4 border-white overflow-hidden mb-4 sm:mb-0 sm:mr-6">
          {% if profile.picture %}
            <img src="{{ profile.picture }}" alt="Profile" class="w-full h-full object-cover">
          {% else %}
            <div class="w-full h-full bg-irish-green flex items-center justify-center text-white text-4xl">
              {{ profile.username[0]|upper }}
            </div>
          {% endif %}
        </div>
        <div class="text-center sm:text-left">
          <h1 class="text-2xl font-bold">{{ profile.username }}</h1>
          <p class="text-green-100">Member since {{ profile.created_at.strftime('%B %Y') }}</p>
          <p class="mt-2">
            {% if profile.is_admin %}
              <span class="bg-golden-ale text-black-stout text-xs px-2 py-1 rounded-full font-medium mr-1">Admin</span>
            {% endif %}
          </p>
        </div>
      </div>
    </div>
    
    <!-- Profile Content -->
    <div class="p-6">
      <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
        <!-- Left Column: Personal Info -->
        <div class="md:col-span-1">
          <h2 class="text-xl font-semibold text-irish-green mb-4">Profile Information</h2>
          
          <div class="space-y-4">
            <div class="bg-cream-white p-4 rounded-lg">
              <h3 class="text-sm font-medium text-gray-600 mb-1">Username</h3>
              <p class="font-medium">{{ profile.username }}</p>
            </div>
            
            {% if "email" in profile %}
            <div class="bg-cream-white p-4 rounded-lg">
              <h3 class="text-sm font-medium text-gray-600 mb-1">Email</h3>
              <p>{{ profile.email }}</p>
            </div>
            {% endif %}
            
            {% if "first_name" in profile and "last_name" in profile %}
            <div class="bg-cream-white p-4 rounded-lg">
              <h3 class="text-sm font-medium text-gray-600 mb-1">Full Name</h3>
              <p>{{ profile.first_name }} {{ profile.last_name }}</p>
            </div>
            {% elif "first_name" in profile %}
            <div class="bg-cream-white p-4 rounded-lg">
              <h3 class="text-sm font-medium text-gray-600 mb-1">First Name</h3>
              <p>{{ profile.first_name }}</p>
            </div>
            {% endif %}
            
            <div class="bg-cream-white p-4 rounded-lg">
              <h3 class="text-sm font-medium text-gray-600 mb-1">Account Type</h3>
              <p>{% if profile.is_admin %}Administrator{% else %}User{% endif %}</p>
            </div>
          </div>
        </div>
        
        <!-- Right Column: Stats & Teams -->
        <div class="md:col-span-2">
          {% if profile.can_view_points %}
          <div class="mb-6">
            <h2 class="text-xl font-semibold text-irish-green mb-4">Statistics</h2>
            <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
              <div class="bg-cream-white p-4 rounded-lg text-center">
                <p class="text-sm text-gray-600">Total Points</p>
                <p class="text-2xl font-bold text-irish-green">{{ total_points }}</p>
              </div>
            </div>
          </div>
          {% endif %}
          
          {% if profile.can_view_teams and teams %}
          <div class="mb-6">
            <h2 class="text-xl font-semibold text-irish-green mb-4">Teams</h2>
            <div class="space-y-4">
              {% for team in teams %}
              <div class="border rounded-lg overflow-hidden">
                <div class="bg-cream-white px-4 py-3 flex justify-between items-center">
                  <div class="font-medium">{{ team.name }}</div>
                  {% if team.is_captain %}
                  <span class="bg-golden-ale text-black-stout text-xs px-2 py-1 rounded-full">Captain</span>
                  {% else %}
                  <span class="bg-gray-200 text-gray-700 text-xs px-2 py-1 rounded-full">Member</span>
                  {% endif %}
                </div>
                <div class="px-4 py-3">
                  <a href="/teams/{{ team.id }}" class="text-irish-green hover:underline text-sm">View Team</a>
                </div>
              </div>
              {% endfor %}
            </div>
          </div>
          {% endif %}
          
          {% if profile.can_view_achievements %}
          <div class="mb-6">
            <h2 class="text-xl font-semibold text-irish-green mb-4">Achievements</h2>
            <p class="text-gray-500 italic">Achievements data will be shown here</p>
          </div>
          {% endif %}
          
          {% if profile.can_view_events %}
          <div>
            <h2 class="text-xl font-semibold text-irish-green mb-4">Recent Events</h2>
            <p class="text-gray-500 italic">Recent events will be shown here</p>
          </div>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}