{% load djblets_utils i18n rbadmintags %}


{# Account link succeeded, with form errors #}
{% if form.errors and form.hosting_account_linked %}
<div class="rb-c-alert -is-success">
 <div class="rb-c-alert__content">
  <h3 class="rb-c-alert__heading">{% trans "Account successfully linked." %}</h3>
  <p>
{%  blocktrans %}
   Your hosting account was successfully linked. You will not need to
   link it again when fixing the remaining errors.
{%  endblocktrans %}
  </p>
 </div>
</div>
{% endif %}


{# Host identity confirmation #}
{% with form.hostkeyerror as hostkeyerror %}
{% with form.certerror as certerror %}
{% with form.certerror.certificate as certificate %}
{%  if hostkeyerror or certerror %}
<div class="confirmation rb-c-alert -is-warning">
 <div class="rb-c-alert__content">
{%   with error_parts=hostkeyerror|default:certerror|split_error_title_text %}
  <h3 class="rb-c-alert__heading">{{error_parts.0}}</h3>
{%    if error_parts.1 %}
  {{error_parts.1|paragraphs}}
{%    endif %}
{%   endwith %}

{%  if hostkeyerror %}
{%   if hostkeyerror.key %}
  <p>RSA key fingerprint is {{hostkeyerror.key}}.</p>
{%   endif %}
{%   if hostkeyerror.expected_key %}
  <p>Expected fingerprint is {{hostkeyerror.expected_key}}.</p>
{%   endif %}
{%  elif certerror %}
{%   if certificate.failures %}
  <p>{% trans "There were errors validating this certificate:" %}</p>
  <ul>
{%    for failure in certificate.failures %}
   <li>{{failure}}</li>
{%    endfor %}
  </ul>
{%   endif %}
  <h3 class="rb-c-alert__heading">{% trans "Certificate information:" %}</h3>
  <dl class="rb-c-admin-cert">
{%   if certificate.hostname %}
   <div class="rb-c-admin-cert__field">
    <dt class="rb-c-admin-cert__field-name">{% trans "Hostname:" %}</dt>
    <dd class="rb-c-admin-cert__field-value">{{certificate.hostname}}</dd>
   </div>
{%   endif %}
{%   if certificate.valid_from %}
   <div class="rb-c-admin-cert__field">
    <dt class="rb-c-admin-cert__field-name">{% trans "Valid:" %}</dt>
    <dd class="rb-c-admin-cert__field-value">
{%    blocktrans with certificate.valid_from as valid_from and certificate.valid_until as valid_until %}
     from {{valid_from}} until {{valid_until}}
{%    endblocktrans %}
    </div>
   </dd>
{%   endif %}
{%   if certificate.issuer %}
   <div class="rb-c-admin-cert__field">
    <dt class="rb-c-admin-cert__field-name">{% trans "Issuer:" %}</dt>
    <dd class="rb-c-admin-cert__field-value">{{certificate.issuer}}</dd>
   </div>
{%   endif %}
   <div class="rb-c-admin-cert__field">
    <dt class="rb-c-admin-cert__field-name">{% trans "Fingerprint:" %}</dt>
    <dd class="rb-c-admin-cert__field-value">{{certificate.fingerprint}}</dd>
   </div>
  </dl>
{%  endif %}

  <p>
{%  blocktrans %}
   Do you trust this host, or do you want to go back and edit the
   repository information?
{%  endblocktrans %}
  </p>
  <div>
   <input type="submit" name="trust_host" value="{% trans "I trust this host" %}" />
   <input type="submit" name="reedit_repository" value="{% trans "Re-edit repository" %}" />
  </div>
 </div>
</div>
{%  endif %}
{% endwith %}
{% endwith %}
{% endwith %}


{# Missing SSH key #}
{% with form.userkeyerror as userkeyerror %}
{%  if userkeyerror %}
<div class="rb-c-alert -is-error">
 <div class="rb-c-alert__content">
  <p>
{%   blocktrans %}
   This repository requires a valid SSH public key. You can
   <a href="{{ssh_settings_url}}" target="ssh_settings">create or upload a
   new SSH key</a>, add it to the server, and then try again.
{%   endblocktrans %}
  </p>
  <p>
{%   blocktrans %}
   Note that replacing an existing key may impact other repositories.
{%   endblocktrans %}
  </p>
 </div>
</div>
{%  endif %}
{% endwith %}
