@extends('layouts.admin')

@section('title')

  Squadre

@stop

@section('content')

<div class="row">
  <div class="col-xs-12">
    <div class="col-md-3">
        <div class="form-group">
            <label for="season_id">Stagione:</label>
            <select name="season_id" class="form-control">
                <option value=""></option>
                @foreach($seasons as $key => $value)
                    <option value="{{ $key }}" {{ (isset($_GET["season_id"]) && $_GET["season_id"] == $key) ? 'selected' : '' }}>{{ $value }}</option>
                @endforeach
            </select>
        </div>
    </div>
    <div class="col-md-3">
        <div class="form-group">
            <label for="type">Tipologia:</label>
            <select name="type" class="form-control">
                <option value=""></option>
                <option value="nation" {{ (isset($_GET["type"]) && $_GET["type"] == 'nation') ? 'selected' : '' }}>Nazionale</option>
                <option value="region" {{ (isset($_GET["type"]) && $_GET["type"] == 'region') ? 'selected' : '' }}>Regionale</option>
            </select>
        </div>
    </div>
    <div class="col-md-3">
      <div class="form-group">
          <label for="category_id">Categoria:</label>
          <select name="category_id" class="form-control">
              <option value=""></option>
              @foreach($categories as $key => $value)
                  <option value="{{ $key }}" {{ (isset($_GET["category_id"]) && $_GET["category_id"] == $key) ? 'selected' : '' }}>{{ $value }}</option>
              @endforeach
          </select>
      </div>
    </div>
    <div class="col-md-3">
      <div class="form-group">
          <label for="group_id">Girone:</label>
          <select name="group_id" class="form-control">
              <option value=""></option>
              @foreach($groups as $key => $value)
                  <option value="{{ $key }}" {{ (isset($_GET["group_id"]) && $_GET["group_id"] == $key) ? 'selected' : '' }}>{{ $value }}</option>
              @endforeach
          </select>
      </div>
    </div>
  </div>
</div>

	   <div class="row">
        <div class="col-xs-12">
          <div class="box">

            <div class="box-body table-responsive no-padding">
              <table class="table table-striped table-hover">
                <tr>
                  <th>Nome</th>
                  <th>Punti penalità</th>
                  <th>Esclusa</th>
                  <th>Ritirata</th>
                  <th>Stagione</th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
                @foreach($teams as $team)
                	<tr>
                    <td>{{$team->name}}</td>
                    <td>{{$team->penality}}</td>
                    <td>{{$team->excluded ? 'Si' : ''}}</td>
                    <td>{{$team->day > 0 ? $team->day . " " . $team->type : ''}}</td>
                    <td>{{$team->season->name}}</td>
                    <td>
                        <a href="{{ route('teams.edit', array($team->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
                    </td>
                    <td>
                      @if(false)
                        <form class="form-inline" method="POST" action="{{ route('teams.destroy', $team->id) }}">
                            @csrf
                            @method('DELETE')
                            <button style="display:none" type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
                        </form>
                      @endif
                    </td>
                	</tr>
                @endforeach
              </table>
            </div>

          </div>

        </div>
        <div class="col-xs-2">
          <!--<a href="{{ route('teams.create') }}" class="btn btn-success">Aggiungi</a>-->
        </div>

      </div>
@stop

@section('extra_js')

    <script>

        $( document ).ready(function() {

            $('select[name="type"]').change(function() {
                var type = $('select[name="type"] option:selected').val();
                var season_id = $('select[name="season_id"] option:selected').val();
                document.location.href = '/admin/teams?type=' + type + "&season_id=" + season_id;
            });

            $('select[name="category_id"]').change(function() {
                var type = $('select[name="type"] option:selected').val();
                var category_id = $('select[name="category_id"] option:selected').val();
                var season_id = $('select[name="season_id"] option:selected').val();
                document.location.href = '/admin/teams?type=' + type + '&category_id=' + category_id + "&season_id=" + season_id;
            });

            $('select[name="group_id"]').change(function() {
              var season_id = $('select[name="season_id"] option:selected').val();
                var type = $('select[name="type"] option:selected').val();
                var category_id = $('select[name="category_id"] option:selected').val();
                var group_id = $('select[name="group_id"] option:selected').val();
                document.location.href = '/admin/teams?type=' + type + '&category_id=' + category_id + '&group_id=' + group_id + "&season_id=" + season_id;
            });

            $('select[name="season_id"]').change(function() {
              var season_id = $('select[name="season_id"] option:selected').val();
                var type = $('select[name="type"] option:selected').val();
                var category_id = $('select[name="category_id"] option:selected').val();
                var group_id = $('select[name="group_id"] option:selected').val();
                document.location.href = '/admin/teams?type=' + type + '&category_id=' + category_id + '&group_id=' + group_id + "&season_id=" + season_id;
            });

        });

    </script>

@stop
