{% extends "cms/home.html" %}
{% load cms_tags danceschool_tags sekizai_tags static i18n %}

{% block content %}

  {% page_url 'directions' as directions_url %}
  {% page_url 'calendar' as calendar_url %}

  <div class="row">

    {# Display any warning or error messages associated with the previous form submission #}
    <div id="message-alerts">
      {% for message in messages %}
        <div class="alert {% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %}alert-danger{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %}alert-warning{% else %}alert-info{% endif %}">{{ message }}</div>
      {% endfor %}
    </div>

    <div class="col-md-12 top-col">
      {% block top %}
        {% static_placeholder 'registration_top' %}
      {% endblock %}
    </div>

    <div class="col-md-12 content-col">

      {% block coming_soon %}
        {% if not allSeries and not allEvents and not categorySeparateSeries and not categorySeparateEvents %}
          <h2>{% trans "More Classes and Events Coming Soon!" %}</h2>
          <p>{% blocktrans %}Our upcoming classes have not yet been posted, but don't worry, they will be posted here
            soon!  Check back soon for more information.{% endblocktrans %}</p>
          {% if calendar_url %}
            <p>{% blocktrans %}In the meantime, check out our <a href="{{ calendar_url }}">calendar</a> for more
              information about our past and current classes.</p>{% endblocktrans %}{% endif %}
        {% elif not allSeries and not categorySeparateSeries %}
          <h2>{% trans "More Classes Coming Soon!" %}</h2>
          <p>{% blocktrans %}Our upcoming classes have not yet been posted, but don't worry, they will be posted here
            soon!  Check back soon for more information.{% endblocktrans %}</p>
          {% if calendar_url %}
            <p>{% blocktrans %}In the meantime, check out our <a href="{{ calendar_url }}">calendar</a> for more
              information about our past and current classes.</p>{% endblocktrans %}{% endif %}
        {% endif %}
      {% endblock %}

      {% if allSeries or allEvents %}

        {% block registration_form %}
          <form id="classregform"
                name="input"
                action=""
                method="post">
            {% csrf_token %}
            {{ form.voucher_id }}

            {% block door_reg %}
              {% if perms.core.accept_door_payments %}
                <div class="alert alert-info"
                     role="alert">
                  <h4>{% trans "Is this a door/invoice registration?" %}<br />
                    <small>({% trans "to be filled out only by school staff" %})</small>
                  </h4>
                  <p>{% trans "This is a door/invoice registration" %} {{ form.payAtDoor }}</p>
                </div>
              {% endif %}
            {% endblock %}

            {% if regOpenEvents or regOpenSeries or categorySeparateSeries or categorySeparateEvents %}
                <input class="btn btn-success btn-lg float-right position-sticky sticky-top"
                       style="top: 0.5em"
                       type="submit"
                       value="{% trans 'Register now' %} &raquo;" />
            {% endif %}

            <div id="classes">
              <div id="validation" {% if form.non_field_errors %}class="alert alert-danger"{% endif %}>
                {{ form.non_field_errors }}
              </div>

              {# List of Category-separated Series #}
              {% block category_separate_series %}
                {% regroup categorySeparateSeries by category as category_separated_list %}

                {% for category_list in category_separated_list %}
                  {% if "core/registration/series_category_"|add:category_list.grouper.slug|add:".html"|template_exists %}
                    {% include "core/registration/series_category_"|add:category_list.grouper.slug|add:".html" %}
                  {% else %}
                    {% include "core/registration/series_category__default.html" %}
                  {% endif %}
                {% endfor %}
              {% endblock %}

              {# List of Category-separated Public Events #}
              {% block category_separate_events %}
                {% regroup categorySeparateEvents by category as category_separated_list %}

                {% for category_list in category_separated_list %}
                  {% if "core/registration/event_category_"|add:category_list.grouper.slug|add:".html"|template_exists %}
                    {% include "core/registration/event_category_"|add:category_list.grouper.slug|add:".html" %}
                  {% else %}
                    {% include "core/registration/event_category__default.html" %}
                  {% endif %}
                {% endfor %}
              {% endblock %}

              {# List of Class Series with Open Registration #}
              {% block reg_open_series %}
                {% if regOpenSeries %}
                  {% include "core/registration/event_group.html" with group_header='Register Now: Upcoming Class Series' group_section='Class Series' group=regOpenSeries %}
                {% endif %}

              {% endblock %}

              {# List of Upcoming Public Events with Open Registration #}
              {% block reg_open_events %}
                {% if regOpenEvents %}
                  {% include "core/registration/event_group.html" with group_header='Register Now: Upcoming Events' group_section='Events' group=regOpenEvents %}
                {% endif %}
              {% endblock %}

              {# List of Upcoming Public Events without/with closed Registration #}
              {% block reg_closed_events %}
                {% if regClosedEvents %}
                  {% include "core/registration/event_group.html" with group_header='Upcoming Events (No Registration Required)' group_section='Events' group=regClosedEvents %}
                {% endif %}
              {% endblock %}

              {# List of Ongoing Class Series with closed Registration #}
              {% block reg_closed_series %}
                {% if regClosedSeries %}
                  {% include "core/registration/event_group.html" with group_header='Ongoing Series (Registration Closed)' group_section='Class Series' group=regClosedSeries %}
                {% endif %}
              {% endblock %}

            </div>
          </form>
        {% endblock %}
      {% endif %}

    </div>
  </div>

  {% block content_js %}
    {% addtoblock "js" %}
      <script type="text/javascript"
              src="{% static 'ekko-lightbox/ekko-lightbox.min.js' %}"></script>
      <script type="text/javascript">
          $(document).delegate('*[data-toggle="lightbox"]', 'click', function (event) {
              event.preventDefault();
              $(this).ekkoLightbox();
          });
      </script>
    {% endaddtoblock %}

    {% addtoblock "js" %}
      <script type="text/javascript">
          $(document).ready(function () {
              $('.pricingPopover').popover();
          });
      </script>
    {% endaddtoblock %}

    {% addtoblock "js" %}
        {{ form.media }}
    {% endaddtoblock %}

    {% endblock %}

  {% endblock %}
