@extends('layouts.frontend')

@section('content')
<style>
    .table {
            border-top-style: ridge;
            border-bottom-style: ridge;
            border-left-style: ridge;
            border-right-style: ridge;
            border-color: #989894;
            border-width: 1px;
          }

    .table td {
        border-right: solid 1px #989894;
        border-bottom: 1px solid#989894;
    }

    .table th {
        border-right: solid 1px #989894;
        border-bottom: 1px solid#989894;
    }

</style>

@php
if(!isset($_GET["day"]) && $d != '')
{
    $_GET["day"] = $d . " ";
    $_GET["type"] = $t;
}

if (isset($_GET["day"]))
{
    $sel = $_GET["day"] . $_GET["type"];
}
@endphp

<div class="container">
    <div class="row">

        <div class="col-sm-12" style="margin-top:30px;">

            <div class="title-section" style="margin-bottom:10!important;">
                    <h1 style="width: 90%"><span>{{$c->category->name}}{{isset($c->group) ? ' - ' . $c->group->name : ''}}</span></h1>
                    <span style="margin-top:-30px;float:right"><a style="color:red" href="/calendario/{{$c->category->name}}{{isset($c->group) ? '-' . $c->group->name : ''}}/{{$c->id}}?all=1">CALENDARIO COMPLETO</a></span>
                </div>
            </div>

            <h3 style="margin-top:30px;">Andata</h3>
            <span style="margin-top:-45px;float:right;margin-right:15px;"><a style="color:red;" href="/archivio">ARCHIVIO STATISTICO</a></span>
            <div class="row" style="margin-top:20px";>
                <div class="col-sm-12">
                    @foreach($games as $idx => $g)
                        @if(strtoupper(trim($g[0]->type)) == 'ANDATA')
                            <a class="box-day" href="/calendario/{{$c->category->name}}{{isset($c->group) ? '-' . $c->group->name : ''}}/{{$c->id}}?day={{str_replace('ANDATA', '', str_replace('RITORNO', '', $idx))}}&type=ANDATA" style="{{$idx == $sel ? 'background-color:red;color:white' : 'color:black'}};padding:10px;border:1px solid black;font-weight:bold;">{{str_replace('ANDATA', '', str_replace('RITORNO', '', $idx))}}&ordf;</a>
                        @endif
                    @endforeach
                </div>
            </div>
            <h3>Ritorno</h3>
            <div class="row" style="margin-top:20px";>
                <div class="col-sm-12">
                    @foreach($games as $idx => $g)
                        @if(strtoupper(trim($g[0]->type)) == 'RITORNO')
                            <a class="box-day" href="/calendario/{{$c->category->name}}{{isset($c->group) ? '-' . $c->group->name : ''}}/{{$c->id}}?day={{str_replace('ANDATA', '', str_replace('RITORNO', '', $idx))}}&type=RITORNO" style="{{$idx == $sel ? 'background-color:red;color:white' : 'color:black'}};padding:10px;border:1px solid black;font-weight:bold;">{{str_replace('ANDATA', '', str_replace('RITORNO', '', $idx))}}&ordf;</a>
                        @endif
                    @endforeach
                </div>
            </div>
            @if(isset($_GET["all"]))
                @foreach($games as $idx => $g)
                <h3>{{$idx}}</h3>
                    <div class="row" style="margin-top:50px";>
                        <div class="col-sm-12">
                        <table class="table calendari">
                            <tr style="background-color:#434343;color:white">
                            <th>Data</th>
                            <th colspan="2">Partita</th>
                            <th>Risultato</th>
                            </tr>
                            @foreach($g as $idx => $gg)
                            <tr style="background-color:{{$idx % 2 == 0 ? '#e5eae4' : '#d2b272'}}">
                                <td>{{date("d/m/Y", strtotime($gg->date))}}</td>
                                <td>{!!$gg->getHomeTeam()->name!!}</td>
                                <td>{!!$gg->getAwayTeam()->name!!}</td>
                                <td>{!!$gg->getResult()!!}</td>
                            </tr>
                            @endforeach
                        </table>
                        </div>
                    </div>
                @endforeach
            @else
                @if(isset($_GET["day"]))

                    <div class="row" style="margin-top:50px";>
                        <div class="col-sm-12">
                        <table class="table calendari">
                            <tr style="background-color:#434343;color:white">
                            <th>Data</th>
                            <th colspan="2">Partita</th>
                            <th>Risultato</th>
                            </tr>
                            @foreach($games[$_GET["day"] . $_GET["type"]] as $idx => $gg)
                            <tr style="background-color:{{$idx % 2 == 0 ? '#e5eae4' : '#d2b272'}}">
                                <td>{{date("d/m/Y", strtotime($gg->date))}}</td>
                                <td>{!!$gg->getHomeTeam()->name!!}</td>
                                <td>{!!$gg->getAwayTeam()->name!!}</td>
                                <td>{!!$gg->getResult()!!}</td>
                            </tr>
                            @endforeach
                        </table>
                        </div>
                    </div>
                @endif
            @endif


            <div class="row" style="margin-top:50px";>
                <div class="col-sm-12">
                    <table class="table calendari">
                        <tr style="background-color:#434343;color:white">
                          <th>Squadra</th>
                          <th style="width:50px;">Punti</th>
                          <th style="width:50px;">PG</th>
                          <th style="width:50px;">V</th>
                          <th style="width:50px;">N</th>
                          <th style="width:50px;">P</th>
                          <th style="width:50px;">GF</th>
                          <th style="width:50px;">GS</th>
                          <th style="width:50px;">DR</th>
                        </tr>
                        @foreach($aRates as $idx => $r)
                        <tr style="background-color:{{$idx % 2 == 0 ? '#e5eae4' : '#d2b272'}}">
                            <td>{{$r["team"]}}</td>
                            <td>{{$r["POINTS"]}}</td>
                            <td>{{$r["PG"]}}</td>
                            <td>{{$r["V"]}}</td>
                            <td>{{$r["N"]}}</td>
                            <td>{{$r["P"]}}</td>
                            <td>{{$r["GF"]}}</td>
                            <td>{{$r["GS"]}}</td>
                            <td>{{$r["DR"]}}</td>
                          </tr>
                        @endforeach
                      </table>
                </div>
            </div>
            @foreach($aRates as $idx => $r)
                @if($r["penality"] != '')
                    {{$r["penality"]}}<br>
                @endif
            @endforeach

        </div>

    </div>
</div>

@stop
