{% extends "base.html" %}
{% load i18n %}

{% block title %}{% trans 'Register' %}{% endblock %}
{% block header %}{% trans 'Register' %}{% endblock %}
{% block byline %}{% trans 'Please fill in your registration details' %}{% endblock %}

{% block login_status %}
    {% if DEBUG_REGISTER_STATUS %}
        {{ block.super }}
    {% endif %}
{% endblock %}

{% block extra_css %}
<style>
.wait {
    display: block;
    text-align: center;
    font-size: 5em;
}
.hidden {
    display: none;
}
.spinner-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: white;
}
.spinner {
    display: block;
    position: relative;
    left: 50%;
    top: 50%;
    width: 150px;
    height: 150px;
    margin: -75px 0 0 -75px;
    border: 10px transparent solid;
    border-top-color:black;
    border-radius: 50%;
    border-bottom: 10px transparent solid;
    z-index: 1500;

    /* Animation stuff below */
    -webkit-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
}
.spinner:after {
    content: "";
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    border: 10px transparent solid;
    border-top-color:black;
    border-radius: 50%;

    /* Animation stuff below */
    -webkit-animation: spin 3s linear infinite;
    animation: spin 3s linear infinite;
}

@-webkit-keyframes spin {
    0%   {
        -webkit-transform: rotate(0deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(0deg);  /* IE 9 */
        transform: rotate(0deg);  /* Firefox 16+, IE 10+, Opera */
    }
    100% {
        -webkit-transform: rotate(360deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(360deg);  /* IE 9 */
        transform: rotate(360deg);  /* Firefox 16+, IE 10+, Opera */
    }
}
@keyframes spin {
    0%   {
        -webkit-transform: rotate(0deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(0deg);  /* IE 9 */
        transform: rotate(0deg);  /* Firefox 16+, IE 10+, Opera */
    }
    100% {
        -webkit-transform: rotate(360deg);  /* Chrome, Opera 15+, Safari 3.1+ */
        -ms-transform: rotate(360deg);  /* IE 9 */
        transform: rotate(360deg);  /* Firefox 16+, IE 10+, Opera */
    }
}
</style>
{% endblock extra_css %}

{% block content %}
<form id="register-form" method="post" action=".">
    {% csrf_token %}
    {{ form.as_p }}
    {% if is_billing %}
    <input type="submit" value="{% trans 'Billing >>' %}" />
    {% else %}
    <input type="submit" value="{% trans 'Register >>' %}" />
    {% endif %}
</form>
<div id="spinner-wrap" class="hidden">
    <div class="spinner"></div>
    <p class="wait">Please wait ...</p>
</div>
{% endblock %}

{% block extra_js %}
<script>
const frm = document.getElementById('register-form'),
      spin = document.getElementById('spinner-wrap');

frm.addEventListener('submit', enable_spinner);

function enable_spinner() {
    spin.setAttribute('class', 'spinner-wrapper');
}
  const reg_opts = {{ reg_opts|safe }}
  function update_desc() {
      let desc = document.getElementById('id_description');
      const form = document.forms[0]
      const bundle_r = form.elements['bundle_choice']
      const bundle_v = bundle_r.value
      const period_r = form.elements['period_choice']
      const period_v = period_r.value
      desc.value = reg_opts[bundle_v][period_v]['desc'];
  }
</script>
{% endblock extra_js %}
