{% from "components/_tabs.html" import tabs_intro %}
<header class="page-heading"><p class="eyebrow">RED DE ABASTECIMIENTO</p><h1>Logística imperial</h1><p>Construye depósitos, conecta mundos propios y mueve reservas mediante convoyes reales con capacidad, duración y riesgo.</p></header>
<div data-tab-scope="logistics" data-tab-auto>
{{ tabs_intro('logistics', 'Apartados de logística', 'Gestiona depósitos, rutas y convoyes en pasos separados pero conectados.') }}
<section class="panel" aria-labelledby="depots-title"><h2 id="depots-title">Depósitos planetarios</h2><div class="card-grid">{% for own_planet in planets %}{% set depot = logistics_depots.get(own_planet.id) %}<article class="tech-card"><div class="card-copy"><h3>{{ own_planet.alias or own_planet.name }}</h3><p>{% if depot %}Nivel {{ depot.level }} · capacidad {{ depot.capacity|number }}{% else %}Sin depósito{% endif %}</p></div><form method="post" action="{{ url_for('logistics_depot_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="planet_id" value="{{ own_planet.id }}"><button class="button" type="submit">{{ 'Ampliar depósito' if depot else 'Construir depósito' }}</button></form></article>{% endfor %}</div></section>
<section class="panel" aria-labelledby="routes-title"><h2 id="routes-title">Rutas</h2><form method="post" action="{{ url_for('logistics_route_action') }}" class="inline-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><label>Nombre<input name="name" maxlength="60" value="Corredor interior"></label><label>Origen<select name="origin_planet_id">{% for own_planet in planets %}<option value="{{ own_planet.id }}">{{ own_planet.alias or own_planet.name }}</option>{% endfor %}</select></label><label>Destino<select name="target_planet_id">{% for own_planet in planets %}<option value="{{ own_planet.id }}">{{ own_planet.alias or own_planet.name }}</option>{% endfor %}</select></label><button class="button button-primary" type="submit">Crear ruta</button></form>
{% if logistics_routes %}<div class="table-wrap"><table><caption>Conexiones logísticas y sus límites reales.</caption><thead><tr><th scope="col">Ruta</th><th scope="col">Trayecto</th><th scope="col">Capacidad</th><th scope="col">Riesgo</th><th scope="col">Estado</th></tr></thead><tbody>{% for route in logistics_routes %}<tr><th scope="row">{{ route.name }}</th><td>{{ route.origin_name }} → {{ route.target_name }}</td><td>{{ route.capacity|number }}</td><td>{{ (route.risk*100)|round(1) }} %</td><td><form method="post" action="{{ url_for('logistics_route_toggle_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="route_id" value="{{ route.id }}"><button class="button" type="submit">{{ 'Desactivar' if route.active else 'Activar' }}; ahora {{ 'activa' if route.active else 'inactiva' }}</button></form></td></tr>{% endfor %}</tbody></table></div>{% else %}<p class="empty-state">No hay rutas. Ambos extremos necesitan un depósito.</p>{% endif %}</section>
<section class="panel" aria-labelledby="convoys-title"><h2 id="convoys-title">Reservar y enviar recursos</h2><p>El sistema reparte la cantidad entre rutas activas que terminen en el destino, sin crear recursos ni superar reservas o capacidad.</p><form method="post" action="{{ url_for('logistics_convoy_action') }}" class="stacked-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><label>Destino<select name="target_planet_id">{% for own_planet in planets %}<option value="{{ own_planet.id }}">{{ own_planet.alias or own_planet.name }}</option>{% endfor %}</select></label><label>Recurso<select name="resource"><option value="metal">Metal</option><option value="crystal">Cristal</option><option value="deuterium">Deuterio</option><option value="food">Alimento</option></select></label><label>Cantidad<input name="amount" type="number" min="1" max="10000000" value="1000"></label><label>Finalidad<input name="purpose" maxlength="80" value="reserva estratégica"></label><button class="button button-primary" type="submit">Enviar convoyes</button></form>
{% if logistics_convoys %}<ol class="activity-list">{% for convoy in logistics_convoys %}<li><div><strong>{{ convoy.origin_name }} → {{ convoy.target_name }}</strong><span>{{ convoy.purpose }} · {{ convoy.cargo_json|from_json }} · {{ convoy.result_text or 'en tránsito' }}</span></div><span>{{ convoy.status }}{% if convoy.status == 'in_transit' %} · <time class="countdown" data-end="{{ convoy.arrives_at }}">{{ (convoy.arrives_at-now)|duration }}</time>{% endif %}</span></li>{% endfor %}</ol>{% else %}<p class="empty-state">No hay convoyes registrados.</p>{% endif %}</section>
</div>
