{% extends 'base.html' %}
{% block content %}
<div class="toolbar">
  <div>
    <h1>{{ t('software.compare.title', 'Softwareinventuren vergleichen') }}</h1>
    <p class="muted">{{ t('software.compare.subtitle', 'Vergleich von {asset_a} und {asset_b}', asset_a=asset_a.name, asset_b=asset_b.name) }}</p>
  </div>
  <div class="toolbar-actions">
    <a class="button button-secondary" href="/assets/software-compare/export.xlsx?asset_a={{ asset_a.id }}&asset_b={{ asset_b.id }}&mode={{ mode }}">⇩ {{ t('software.compare.export', 'Als Excel herunterladen') }}</a>
    <a class="button button-secondary" href="/assets">{{ t('common.back', 'Zurück') }}</a>
  </div>
</div>
<section class="panel">
  <form method="get" action="/assets/software-compare" class="form-grid compact-form">
    <input type="hidden" name="asset_a" value="{{ asset_a.id }}">
    <input type="hidden" name="asset_b" value="{{ asset_b.id }}">
    <label>{{ t('software.compare.mode', 'Vergleichsmodus') }}
      <select name="mode" onchange="this.form.submit()">
        <option value="exact" {% if mode == 'exact' %}selected{% endif %}>{{ t('software.compare.mode.exact', 'Exakter Softwarename') }}</option>
        <option value="ignore_version" {% if mode == 'ignore_version' %}selected{% endif %}>{{ t('software.compare.mode.ignore_version', 'Versionen ignorieren') }}</option>
        <option value="ignore_version_year" {% if mode == 'ignore_version_year' %}selected{% endif %}>{{ t('software.compare.mode.ignore_version_year', 'Versionen und Jahreszahlen ignorieren') }}</option>
      </select>
    </label>
  </form>
  <p class="muted">{{ t('software.compare.mode_help', 'Originalnamen und Versionen bleiben sichtbar. Die Normalisierung wird nur für die Zuordnung verwendet.') }}</p>
  <div class="summary-cards compact-summary">
    <span class="badge">{{ t('software.compare.only_a', 'Nur auf {asset}', asset=asset_a.name) }}: {{ counts.only_a }}</span>
    <span class="badge">{{ t('software.compare.only_b', 'Nur auf {asset}', asset=asset_b.name) }}: {{ counts.only_b }}</span>
    <span class="badge">{{ t('software.compare.both', 'Auf beiden vorhanden') }}: {{ counts.both }}</span>
  </div>
  <div class="table-scroll management-table-scroll">
    <table class="data-table" id="software-comparison-table" data-storage-key="software-comparison-table">
      <thead><tr>
        <th>{{ t('software.compare.comparison_name', 'Vergleichsname') }}</th>
        <th>{{ t('software.platform', 'Plattform') }}</th>
        <th>{{ t('software.compare.status', 'Vergleichsstatus') }}</th>
        <th>{{ asset_a.name }} · {{ t('common.name', 'Name') }}</th>
        <th>{{ asset_a.name }} · {{ t('about.version', 'Version') }}</th>
        <th>{{ asset_a.name }} · {{ t('software.publisher', 'Hersteller') }}</th>
        <th>{{ asset_b.name }} · {{ t('common.name', 'Name') }}</th>
        <th>{{ asset_b.name }} · {{ t('about.version', 'Version') }}</th>
        <th>{{ asset_b.name }} · {{ t('software.publisher', 'Hersteller') }}</th>
      </tr></thead>
      <tbody>
      {% for row in rows %}
        <tr>
          <td>{{ row.comparison_name }}</td>
          <td>{{ t('software.platform.' ~ row.platform, row.platform) }}</td>
          <td><span class="job-status job-status-{% if row.status == 'both' %}success{% else %}pending{% endif %}">{% if row.status == 'both' %}{{ t('software.compare.both', 'Auf beiden vorhanden') }}{% elif row.status == 'only_a' %}{{ t('software.compare.only_a', 'Nur auf {asset}', asset=asset_a.name) }}{% else %}{{ t('software.compare.only_b', 'Nur auf {asset}', asset=asset_b.name) }}{% endif %}</span></td>
          <td>{{ row.a_names or '—' }}</td><td>{{ row.a_versions or '—' }}</td><td>{{ row.a_publishers or '—' }}</td>
          <td>{{ row.b_names or '—' }}</td><td>{{ row.b_versions or '—' }}</td><td>{{ row.b_publishers or '—' }}</td>
        </tr>
      {% else %}<tr><td colspan="9">{{ t('software.compare.empty', 'Für diese Assets sind keine Softwareinventuren vorhanden.') }}</td></tr>{% endfor %}
      </tbody>
    </table>
  </div>
</section>
{% endblock %}
