<!DOCTYPE html>
<html>
<head>
  <link href="favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
  <script src="{{ urlsoftware }}/resources/dist/{{ resource('main.js') }}"></script>
  {% if enable_debug_bar %}{{ debug_bar_head|raw }}{% endif %}
</head>
<body>
  {% if training.modalità == "edit" or training.modalità == "add" %}
  <form method="post">
    <div class="container">
      <label><b>{{ 'Training day'|t }}</b></label>
      <div class="input-group">
        <input aria-label="Date picker" placeholder="DD/MM/YYY" autocomplete="off" name="date" data-provide="datepicker"
          value="{{ values.date }}" type="text" class="form-control">
        <div class="input-group-addon">
          <span class="glyphicon glyphicon-th"></span>
        </div>
      </div>
      <br>
      <br>
      <label><b>{{ 'Name'|t }}</b></label>
      <input id="name" type="text" name="name" placeholder="1° training" required value="{{ values.name }}">
      <br>
      <br>
      <label for="timePicker1"><b>{{ 'Start time'|t }}</b></label>
      <input id="timePicker1" type="time" name="start_time" required value="{{ values.beginning }}">
      <br>
      <br>
      <label for="timePicker2"><b>{{ 'End time'|t }}</b></label>
      <input id="timePicker2" type="time" name="end_time" required value="{{ values.end }}">
      <br>
      <br>
      <label><b>{{ 'Chief'|t }}</b></label>
      <br>
      {% for user in training.crew %}
      <div {{ user.name == "test" ? "style='display: none'" : "" }} class="form-check">
        <input aria-label="{{ username(user.id) }}" class="form-check-input chief chief-{{ user.id }}"
          style="transform: scale(1.4); -webkit-transform: scale(1.4);" type="checkbox" name='chief[]'
          value='{{ user.id }}'>
        <label class="form-check-label" for="chief-{{ user.id }}">
          {{ username(user.id) }}
        </label>
      </div>
      {% endfor %}
      <script>
        $('.chief').on('change', function () {
          $('input[name="' + this.name + '"]').not(this).prop('checked', false);
        });
      </script>
      <br>
      <label><b>{{ 'Crew'|t }}</b></label>
      <br>
      {% for user in training.crew %}
      <div {{ user.name == "test" ? "style='display: none'" : "" }} class="form-check">
        <input aria-label="{{ username(user.id) }}" class="form-check-input crew crew-{{ user.id }}"
          style="transform: scale(1.4); -webkit-transform: scale(1.4);" type="checkbox" name='crew[]'
          value='{{ user.id }}'>
        <label class="form-check-label" for="crew-{{ user.id }}">
          {{ username(user.id) }}
        </label>
      </div>
      {% endfor %}
      <br>
      {% if option('use_location_picker') %}
      <label><b>{{ 'Training place'|t }}</b></label>
      <div id="map"></div>
      <div id="search">
        <input type="text" name="addr" value="" id="addr" size="10" />
        <button type="button" onclick="addrSearch('{{ 'Search results'|t }}', '{{ 'No results found'|t }}');"
          class="btn btn-primary">{{ 'Search'|t }}</button>
        <div id="results"></div>
      </div>
      <input type="hidden" name="place" value="" />
      <script src="{{ urlsoftware }}/resources/dist/{{ resource('maps.js') }}" onload="loadMap();"></script>
      {% else %}
      <label><b>{{ 'Training place'|t }}</b></label>
      <input type="text" name="place" required value="{{ values.place }}">
      {% endif %}
      <br>
      <br>
      <label><b>{{ 'Others notes (ex. others infos)'|t }}</b></label><br>
      <textarea name='notes'></textarea>
      <br>
      <br>
      <input id="modalità" type="hidden" value="{{ training.modalità }}" name="mod"></input>
      <input id="id" type="hidden" value="{{ training.id }}" name="id"></input>
      <input id="token" type="hidden" value="{{ training.token }}" name="token"></input>
      <button type="submit">{{ 'Submit'|t }}</button>
    </div>
  </form>
  <script>
    {% if training.modalità == "edit" %}
    $.each('{{ values.chief|striptags|e("js") }}'.split(','), function (index, value) {
      $('.chief-' + value).prop('checked', true);
    });
    $.each('{{ values.crew|striptags|e("js") }}'.split(','), function (index, value) {
      $('.crew-' + value).prop('checked', true);
    });
    $('#notes').val('{{ values.notes|e("js") }}');
    {% endif %}
  </script>
  {% endif %}
  {% if training.modalità == "delete" %}
  <div style="margin: 0 auto; text-align: center">
    <p>{{ 'Are you sure you want to delete the training?'|t }}</p>
    <form method="post">
      <input id="modalità" type="hidden" value="delete" name="mod"></input>
      <input id="token" type="hidden" value="{{ training.token }}" name="token"></input>
      <input id="id" type="hidden" value="{{ training.id }}" name="id"></input>
      <input id="increment" type="hidden" value="{{ increment }}" name="increment"></input>
      <button id="remove" type="submit">{{ 'Submit'|t }}</button>
    </form>
    <script>
      $('form').submit(function () {
        return confirm("{{ 'The action cannot be canceled. Are you sure you want to continue?'|t }}");
      });
    </script>
  </div>
  {% endif %}
  {% if enable_debug_bar %}{{ debug_bar|raw }}{% endif %}
</body>
</html>