{% from "components/_tabs.html" import tabs_intro %}
<header class="page-heading"><p class="eyebrow">ARQUEOTECNOLOGÍA</p><h1>Museo y fabricación de artefactos</h1><p>Desmonta hallazgos, restaura piezas dañadas, completa recetas y comercia fragmentos. Cada operación modifica recursos persistentes.</p></header>
<div data-tab-scope="museum" data-tab-auto>
{{ tabs_intro('museum', 'Apartados del museo', 'Separa conjuntos, recetas, colección e intercambio de fragmentos.') }}
<section class="metric-grid" aria-label="Fragmentos disponibles">{% for key, label in FRAGMENT_NAMES.items() %}<article><span>{{ label }}</span><strong>{{ artifact_fragments.get(key,0) }}</strong><small>piezas</small></article>{% endfor %}</section>
<section class="panel" aria-labelledby="museum-sets-title"><h2 id="museum-sets-title">Conjuntos y bonificaciones moderadas</h2><div class="card-grid">{% for key, definition in MUSEUM_SET_BONUSES.items() %}{% set count = museum_collection_counts.get(key,0) %}<article class="tech-card"><div class="card-copy"><h3>{{ definition.name }}</h3><p>{{ definition.description }}</p><p>{{ count }} de 2 piezas expuestas. Estado: {{ 'bonificación activa' if count >= 2 else 'colección incompleta' }}.</p></div></article>{% endfor %}</div></section>
<section class="panel" aria-labelledby="recipes-title"><h2 id="recipes-title">Recetas conocidas</h2><div class="card-grid">{% for key, recipe in ARTIFACT_RECIPES.items() %}<article class="tech-card"><div class="card-copy"><h3>{{ recipe.name }}</h3><p>{{ recipe.lore }}</p><p><strong>Requiere:</strong> {% for fragment, amount in recipe.fragments.items() %}{{ amount }} {{ FRAGMENT_NAMES[fragment]|lower }}{% if not loop.last %}; {% endif %}{% endfor %}. <strong>Efecto:</strong> {{ recipe.effect_key }} +{{ (recipe.effect_value*100)|round(1) }} %.</p></div><form method="post" action="{{ url_for('artifact_craft_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="recipe_key" value="{{ key }}"><button class="button button-primary" type="submit">Fabricar y exponer</button></form></article>{% endfor %}</div></section>
<section class="panel" aria-labelledby="collection-title"><h2 id="collection-title">Colección</h2>{% if museum_artifacts %}<div class="card-grid">{% for artifact in museum_artifacts %}<article class="tech-card"><div class="card-copy"><h3>{{ artifact.name }}</h3><p>{{ artifact.lore }}</p><dl class="settings-list"><div><dt>Rareza</dt><dd>{{ artifact.rarity }}</dd></div><div><dt>Estado</dt><dd>{{ artifact.condition }} % · {{ 'restaurado' if artifact.restored else 'original' }}</dd></div><div><dt>Efecto</dt><dd>{{ artifact.effect_key }} +{{ (artifact.effect_value*100)|round(1) }} %</dd></div><div><dt>Museo</dt><dd>{{ artifact.collection_key or 'No expuesto' }}</dd></div></dl></div>
  {% if artifact.condition < 100 %}<form method="post" action="{{ url_for('artifact_restore_action') }}" class="inline-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="artifact_id" value="{{ artifact.id }}"><label>Especialista opcional<select name="agent_id"><option value="">Sin especialista</option>{% for agent in restoration_agents %}<option value="{{ agent.id }}">{{ agent.name }} · nivel {{ agent.level }}</option>{% endfor %}</select></label><button class="button" type="submit">Restaurar por 2 fragmentos antiguos</button></form>{% endif %}
  <form method="post" action="{{ url_for('artifact_museum_action') }}" class="inline-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="artifact_id" value="{{ artifact.id }}"><label>Colección<input name="collection_key" value="{{ artifact.collection_key or 'civilizaciones' }}" maxlength="40"></label><button class="button" type="submit">{{ 'Retirar del museo' if artifact.collection_key else 'Exponer' }}</button></form>
  {% if not artifact.collection_key %}<form method="post" action="{{ url_for('artifact_dismantle_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="artifact_id" value="{{ artifact.id }}"><button class="button button-danger" type="submit">Desmontar en fragmentos</button></form>{% endif %}
</article>{% endfor %}</div>{% else %}<p class="empty-state">No posees artefactos.</p>{% endif %}</section>
<section class="panel" aria-labelledby="fragment-market-title"><h2 id="fragment-market-title">Intercambio de fragmentos</h2>
  <form method="post" action="{{ url_for('fragment_publish_action') }}" class="inline-form"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><label>Tipo<select name="fragment_key">{% for key, label in FRAGMENT_NAMES.items() %}<option value="{{ key }}">{{ label }}</option>{% endfor %}</select></label><label>Cantidad<input name="amount" type="number" min="1" max="1000" value="1"></label><label>Precio total en créditos<input name="price" type="number" min="1" max="1000000" value="100"></label><button class="button button-primary" type="submit">Publicar oferta</button></form>
  {% if fragment_orders %}<div class="table-wrap"><table><caption>Fragmentos en depósito disponibles para compra.</caption><thead><tr><th scope="col">Vendedor</th><th scope="col">Piezas</th><th scope="col">Precio</th><th scope="col">Acción</th></tr></thead><tbody>{% for order in fragment_orders %}<tr><th scope="row">{{ order.seller_name }}{% if order.empire_id == empire.id %} (tú){% endif %}</th><td>{{ order.amount }} {{ FRAGMENT_NAMES[order.fragment_key]|lower }}</td><td>{{ order.price|number }} créditos</td><td>{% if order.empire_id != empire.id %}<form method="post" action="{{ url_for('fragment_buy_action') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}"><input type="hidden" name="order_id" value="{{ order.id }}"><button class="button" type="submit">Comprar</button></form>{% else %}Oferta propia{% endif %}</td></tr>{% endfor %}</tbody></table></div>{% else %}<p class="empty-state">No hay ofertas abiertas.</p>{% endif %}
</section>
</div>
