@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">
            {!! Form::label('season_id', 'Stagione:') !!}
            {!! Form::select('season_id', [''=>''] + $seasons,  isset($_GET["season_id"]) ? $_GET["season_id"] : null, ['class' => 'form-control']) !!}
        </div>                
    </div>
    <div class="col-md-3">
        <div class="form-group">
            {!! Form::label('type', 'Tipologia:') !!}
            {!! Form::select('type', ['' => '', 'nation' => 'Nazionale', 'region' => 'Regionale'] , isset($_GET["type"]) ? $_GET["type"] : null, array('class' => 'form-control')) !!}
        </div>                
    </div>
    <div class="col-md-3">
      <div class="form-group">
          {!! Form::label('category_id', 'Categoria:') !!}
          {!! Form::select('category_id', [''=>''] + $categories,  isset($_GET["category_id"]) ? $_GET["category_id"] : null, ['class' => 'form-control']) !!}
      </div>                
    </div>
    <div class="col-md-3">
      <div class="form-group">
          {!! Form::label('group_id', 'Girone:') !!}
          {!! Form::select('group_id', [''=>''] + $groups, isset($_GET["group_id"]) ? $_GET["group_id"] : null, ['class' => 'form-control']) !!}
      </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::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('teams.destroy', $team->id))) !!}
                            <button style="display:none" type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
                        {!! Form::close() !!}
                      @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