{% extends "base.html" %}
{% comment %}
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load i18n crispy_forms_tags %}

{% block content %}
<div class="card bg-white mb-3">
  <h3 class="card-header text-center">
    {{ title }}
  </h3>
  <div class="card-body" id="form">
    <form method="post">
      {% csrf_token %}
      {{ form | crispy }}
      <button class="btn btn-primary" type="submit">{% trans "Submit"%}</button>
    </form>
  </div>
</div>
{% endblock %}

{% block extrajavascript %}
    <script>
        $(document).ready(function () {
            function refreshTeams() {
                let buses = [];
                $("input[name='bus']:checked").each(function (ignored) {
                    buses.push($(this).parent().text().trim());
                });
                $("input[name='team']").each(function () {
                    let label = $(this).parent();
                    $(this).parent().addClass('d-none');
                    buses.forEach(function (bus) {
                        if (label.text().includes(bus))
                            label.removeClass('d-none');
                    });
                });
            }
    
            $("input[name='bus']").change(refreshTeams);
    
            refreshTeams();
        });
    </script>
{% endblock %}