{% load gnm %}
{% if request|is_coming_for == "unknown" %}
<div class="errornotice"><p>Erreur, origine de connexion inconnue.</p></div>
{% else %}
<p id="redirect">Redirection vers le serveur d’authentification en cours…</p>
{% endif %}
<div id="coming-for" data-is-coming-for="{{request|is_coming_for}}">
<div style="display: none">
<p id="oidc-p-{% firstof provider.slug provider.name|slugify %}">
  <a id="oidc-a-{% firstof provider.slug provider.name|slugify %}"
     href="{{ login_url }}">{{ provider.name }}</a>
</p>
</div>
</div>
<script>
$(function() {
  if ($('.block-password').is(':visible')) return;
  var is_coming_for = $('#coming-for').data('is-coming-for');
  var target = null;
  if ($('ul.messages').length) return;
  if (is_coming_for == 'frontoffice') {
    target = $('#oidc-a-cut');
  } else if (is_coming_for == 'backoffice') {
    target = $('#oidc-a-cut-agents');
  };
  if (target && target.length) {
    $('#redirect').show();
    target[0].click();
  } else {
    $('#redirect').hide();
    $('div#coming-for > div').show();
  }
});
</script>
