<div class="contenedor">
  <h1>Comparar prótesis</h1>
  <div class="banner-alerta banner-alerta--informativa"><div>
    <strong>Esta comparación es informativa.</strong> La elección del implante corresponde a tu cirujano
    según tu caso. <a href="/metodologia">Cómo tratamos los datos</a>.
  </div></div>

  <% if (error) { %>
    <div class="aviso-flash aviso-flash--error"><%= error %></div>
  <% } %>

  <form method="get" action="/protesis/comparar" class="admin-panel" style="background:#fff">
    <p class="u-texto-suave">Elige hasta 3 prótesis de la misma articulación:</p>
    <div class="admin-form">
      <% for (let i=0; i<3; i++) { %>
      <div class="campo">
        <label for="sel<%= i %>">Prótesis <%= i+1 %></label>
        <select id="sel<%= i %>" name="ids" data-autocompletar>
          <option value="">—</option>
          <% catalogo.forEach(function(p){ %>
            <option value="<%= p.id %>" <%= ids[i] === p.id ? 'selected' : '' %>><%= p.nombre %> (<%= p.articulacion %>)</option>
          <% }) %>
        </select>
      </div>
      <% } %>
    </div>
    <button class="btn btn--secundario" type="submit">Comparar</button>
  </form>

  <% if (productos.length) { %>
  <div class="tabla-envoltorio u-mt-24">
  <table class="tabla-datos">
    <caption>Comparación lado a lado</caption>
    <thead><tr><th scope="col">Característica</th>
      <% productos.forEach(function(p){ %><th scope="col"><a href="/protesis/<%= p.slug %>"><%= p.nombre %></a></th><% }) %>
    </tr></thead>
    <tbody>
      <tr><th scope="row">Articulación</th><% productos.forEach(function(p){ %><td><%= p.articulacion %></td><% }) %></tr>
      <tr><th scope="row">Indicación</th><% productos.forEach(function(p){ %><td><%= p.indicacion || '—' %></td><% }) %></tr>
      <tr><th scope="row">Clase de riesgo</th><% productos.forEach(function(p){ %><td><%= p.clase_riesgo || '—' %></td><% }) %></tr>
      <tr><th scope="row">Año</th><% productos.forEach(function(p){ %><td><%= p.anio_lanzamiento || '—' %></td><% }) %></tr>
      <tr><th scope="row">Estado</th><% productos.forEach(function(p){ %><td><%= p.ciclo_vida || 'activo' %></td><% }) %></tr>
      <tr><th scope="row">Fijación</th><% productos.forEach(function(p){ const f=L.FIJACION[p.fijacion]; %><td><%= f ? f[0] : '—' %></td><% }) %></tr>
      <tr><th scope="row">Par de fricción</th><% productos.forEach(function(p){ %><td><%= p.par_friccion || '—' %></td><% }) %></tr>
      <tr><th scope="row">Compatibilidad RM</th><% productos.forEach(function(p){ %><td><%= L.RM[p.compat_rm] || 'Sin datos' %></td><% }) %></tr>
      <tr><th scope="row">Evidencia verificada</th><% productos.forEach(function(p){ %><td>
        <% if (p.evidencia) { %><%= p.evidencia.metrica || 'dato' %>: <%= p.evidencia.valor || '—' %>
          <% if (p.evidencia.seguimiento_anios) { %><br><span class="u-texto-suave"><%= p.evidencia.seguimiento_anios %> años · <%= p.evidencia.fuente_nombre %></span><% } %>
        <% } else { %><span class="u-texto-suave">en verificación</span><% } %>
      </td><% }) %></tr>
      <tr class="tabla-datos__fuente"><td colspan="<%= productos.length + 1 %>">Solo datos con verificación editorial. <a href="/metodologia">Metodología</a>.</td></tr>
    </tbody>
  </table>
  </div>
  <% } %>
</div>
<script src="/public/js/comparador.js" defer></script>
