{% extends "online/base.html" %}
{% block title %}Mis universos{% endblock %}
{% block content %}
<header>
  <p class="eyebrow">CUENTA DE {{ account.username|upper }}</p>
  <h1>Mis universos</h1>
  <p>Entra en un imperio existente o funda uno en un universo que admita jugadores.</p>
</header>
{% for item in announcements %}
  <aside class="notice notice-{{ 'error' if item.severity == 'critical' else item.severity }}" aria-labelledby="announcement-{{ item.id }}">
    <h2 id="announcement-{{ item.id }}">{{ item.title }}</h2><p>{{ item.body }}</p>
  </aside>
{% endfor %}
<section aria-labelledby="membership-title">
  <h2 id="membership-title">Imperios activos</h2>
  {% if memberships %}
  <div class="server-grid">
    {% for membership in memberships %}
    <article class="server-card">
      <h3>{{ membership.game_name }}</h3>
      <dl>
        <dt>Imperio</dt><dd>{{ membership.empire_name }}</dd>
        <dt>Comandante</dt><dd>{{ membership.commander }}</dd>
        <dt>Planetas</dt><dd>{{ membership.planet_count }}</dd>
        <dt>Puntuación</dt><dd>{{ membership.score|number }}</dd>
        <dt>Acceso</dt><dd>{{ membership.status }}</dd>
      </dl>
      {% if membership.status == "active" %}
      <form method="post" action="{{ url_for('online_enter_universe', game_id=membership.game_id) }}">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <button class="button button-primary" type="submit">Entrar en {{ membership.game_name }}</button>
      </form>
      {% endif %}
    </article>
    {% endfor %}
  </div>
  {% else %}<p>Todavía no diriges ningún imperio.</p>{% endif %}
</section>
<section aria-labelledby="available-title">
  <h2 id="available-title">Universos con plazas</h2>
  {% if available_universes %}
  <div class="server-grid">
    {% for universe in available_universes %}
    <article class="server-card">
      <h3>{{ universe.row.name }}</h3>
      <p>{{ universe.humans }} de {{ universe.slots }} plazas humanas ocupadas. Velocidad ×{{ universe.row.speed }}.</p>
      <form method="post" action="{{ url_for('online_join_universe', game_id=universe.row.id) }}" class="server-form">
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
        <label for="commander-{{ universe.row.id }}">Nombre del comandante</label>
        <input id="commander-{{ universe.row.id }}" name="commander" maxlength="30" required>
        <label for="empire-{{ universe.row.id }}">Nombre del imperio</label>
        <input id="empire-{{ universe.row.id }}" name="empire_name" maxlength="40" required>
        <button class="button button-primary" type="submit">Fundar imperio en {{ universe.row.name }}</button>
      </form>
    </article>
    {% endfor %}
  </div>
  {% else %}<p>No hay universos públicos con plazas en este momento.</p>{% endif %}
</section>
<section class="server-card" aria-labelledby="support-title">
  <h2 id="support-title">Soporte, seguridad y datos</h2>
  <p>Tienes {{ open_reports }} reportes abiertos.</p>
  <div class="server-actions">
    <a class="button" href="{{ url_for('online_reports') }}">Enviar o consultar reportes</a>
    <a class="button" href="{{ url_for('online_privacy') }}">Seguridad y privacidad</a>
    <a class="button" href="{{ url_for('online_purchases') }}">Historial de compras</a>
  </div>
</section>
{% endblock %}
