{% from "_macros.html" import icon %}
{#
  What looking at a host found.

  Everything here came from the far side and is escaped accordingly. The
  fingerprint especially: it is the one string a person is being asked to
  compare against something they know, so it is shown plainly and never
  reformatted.
#}
{% if error %}
<div class="alert alert--error">{{ icon("warning", "icon--sm") }} <span>{{ error }}</span></div>
{% endif %}

{% if offer %}
<div class="card" style="margin-top: var(--sp-4)">
  <h3 class="card__title">
    {{ "This host's key has changed" if offer.changed else "Is this the machine you meant?" }}
  </h3>
  <p class="field__hint">
    {% if offer.changed %}
      Accept only if you know why it changed — a rebuilt container will do this,
      and so will something pretending to be your machine.
    {% else %}
      Compare this with what the host reports for itself. On the machine, that
      is <code>ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub</code>.
    {% endif %}
  </p>

  <pre class="tool-result__text">{{ offer.fingerprint }}</pre>

  <div class="btn-row">
    <button class="btn btn--primary" type="button"
            hx-post="/api/agents/{{ profile.id }}/accept"
            hx-target="#check-result"
            hx-confirm="Accept this fingerprint and pin it? Every future connection will be checked against it."
            data-confirm-label="Accept"
            data-confirm-danger="{{ 'true' if offer.changed else 'false' }}">
      {{ icon("check", "icon--sm") }} Accept and pin
    </button>
    {% if profile.verified %}
    <button class="btn" type="button"
            hx-post="/api/agents/{{ profile.id }}/forget"
            hx-target="#check-result">
      Forget the old key
    </button>
    {% endif %}
  </div>
</div>
{% endif %}

{% if accepted %}
<div class="alert alert--success">
  {{ icon("check", "icon--sm") }}
  <span>Pinned <code>{{ accepted }}</code>. Check again to log in.</span>
</div>
{% endif %}

{% if forgotten %}
<div class="alert">
  {{ icon("warning", "icon--sm") }}
  <span>Key forgotten. Check again to see the new one.</span>
</div>
{% endif %}

{% if found %}
<div class="alert alert--success">
  {{ icon("check", "icon--sm") }}
  <span>Connected{% if found.system %} to {{ found.system }}{% endif %}.</span>
</div>
<p class="field__hint">What it said:</p>
<pre class="tool-result__text">{{ found.output }}</pre>
{% endif %}
