<div class="card shadow h-100">
  <div class="card-header">
    <div class="row align-items-center">
      <div class="col-12 col-sm-4 h5 mb-2 text-center text-sm-start mb-sm-0">
        <Icon value="bi-terminal" />
        {% trans %}Secure Shell{% endtrans %}
      </div>
      <div class="col-12 col-sm-8 text-center text-sm-end">
        {% if user.username == username %}
          {% if not user.ssh_jumphosts_enabled %}
            {# Display a request button if SSH Jumphosts is not enabled. #}
            <button type="button"
                    class="btn btn-primary btn-sm mb-2 d-print-none ssp-show-modal mb-sm-0"
                    data-bs-toggle="modal"
                    data-bs-target="#modal-request-access"
                    data-resource="SSH Jumphost">{% trans %}Request Jumphost access{% endtrans %}</button>
          {% endif %}
          <button type="button"
                  class="btn btn-primary btn-sm mb-2 d-print-none ssp-show-modal mb-sm-0"
                  data-bs-toggle="modal"
                  data-bs-target="#modal-replace-ssh-key"
                  {% if user.ssh_key_status == user.SSH_DISABLED %}disabled{% endif %}>
            {{ _("Add SSH key") if user.ssh_key_status == user.SSH_UNSET else _("Replace SSH key") -}}
          </button>
        {% endif %}
        {% set clipboard_ssh -%}
          # {% trans %}Secure Shell{% endtrans +%}
          {% trans %}SSH{% endtrans %}: {{ user.ssh_key_status.label }}
          {% trans %}SSH Jumphosts{% endtrans %}: {{ user.ssh_jumphosts_enabled | join(", ") }}
          {% trans %}SSH Public Key{% endtrans %}: {{ user.ssh_key }}
          {% trans %}SSH Key Fingerprint{% endtrans %}: {{ user.ssh_key_fingerprint }}
        {% endset %}
        <CopyButton class="ms-1 mb-2 d-print-none mb-sm-0" text={{ clipboard_ssh }} label={{ _("Copy") }} />
      </div>
    </div>
  </div>
  {# Card body #}
  <div class="card-body">
    <!-- SSH -->
    <div class="row mb-2">
      <div class="col-4 ssp-label">
        <a target="_blank" href="{{ ssh_info_url }}" class="ssp-external">{% trans %}SSH{% endtrans %}</a>
      </div>
      <div class="col-8 ssp-hover-zone">
        <CopyButton class="ssp-hover-show" text={{ user.ssh_key_status.label }} />
        <EnabledBadge value={{ user.ssh_key_status }} />
      </div>
    </div>
    <!-- SSH Jumphosts -->
    <div class="row mb-2">
      <div class="col-4 ssp-label">{% trans %}SSH Jumphosts{% endtrans %}</div>
      <div class="col-8 ssp-hover-zone">
        {% for host in user.ssh_jumphosts_enabled %}
          <EnabledBadge value={{ host }} />
        {% else %}
          <EnabledBadge value={{ False }} />
        {% endfor %}
      </div>
    </div>
    <!-- SSH Public Key -->
    <div class="row mb-2 ssp-nerd-only">
      <div class="col-4 ssp-label">{% trans %}SSH Public Key{% endtrans %}</div>
      <div class="col-8 ssp-hover-zone">
        {% if user.ssh_key %}
          <CopyButton class="ssp-hover-show" text={{ user.ssh_key }} />
          <div class="text-truncate">{{ user.ssh_key }}</div>
        {% else %}
          &mdash;
        {% endif %}
      </div>
    </div>
    <!-- SSH Fingerprint -->
    <div class="row mb-2 ssp-nerd-only">
      <div class="col-4 ssp-label">
        <span class="ssp-tooltip"
              data-bs-toggle="tooltip"
              data-bs-placement="right"
              title="{{ _("A unique identifier of the SSH public key, computed using SHA256. Useful for verifying the integrity or authenticity of a key, especially when sharing or comparing keys across systems.") }}">
          {% trans %}SSH Key Fingerprint{% endtrans %}
        </span>
      </div>
      <div class="col-8 ssp-hover-zone">
        {% if user.ssh_key_fingerprint %}
          <CopyButton class="ssp-hover-show" text={{ user.ssh_key_fingerprint }} />
          <div class="text-truncate">{{ user.ssh_key_fingerprint }}</div>
        {% else %}
          &mdash;
        {% endif %}
      </div>
    </div>
  </div>
</div>
{# Modal dialog - Replace SSH Key #}
{% if user.username == username %}
  <form method="post" action="{{ url_for('dashboard', 'replace-ssh-key') }}">
    <Modal id="modal-replace-ssh-key" title={{ _("Upload SSH Key") }} submit={{ _("Upload SSH Key") }}>
    <p>
      {% trans %}You may store <b>only one SSH key</b> in your account. Submitting a new key will immediately remove and replace the previous one.{% endtrans %}
    </p>
    <p>
      {% trans %}To update your SSH key, paste your new public key below. Supported formats include OpenSSH and PuTTY public keys. Make sure there are no extra spaces or line breaks.{% endtrans %}
    </p>
    {% if replace_ssh_key_form.accepted_ssh_key_type %}
      <p>
        {% trans %}Only the following SSH key types are accepted: {% endtrans %}<b>{{ replace_ssh_key_form.accepted_ssh_key_type | join(", ") }}</b>
      </p>
    {% endif %}
    <Fields form={{ replace_ssh_key_form }} />
    <p>
      {% trans %}By submitting this form, your previous SSH key will be removed and replaced immediately. Ensure that you have access to the corresponding private key before proceeding.{% endtrans %}
    </p>
    </Modal>
  </form>
{% endif %}
