@extends('layouts.modal.schedule.show')

@section('content')

    <div class="row">
        <div class="col-md-6">
        Du <strong>{{$event->date_begin}}</strong> au <strong>{{$event->date_end}}</strong><br>
        <small>{{$event->location}}  </small>
        </div>
        <div class="col-md-6 text-right">
            @if ($event->is_mandatory)
                <span class="badge badge-pill badge-warning">Obligatoire</span>
            @else
                <span class="badge badge-pill badge-info">Optionnel</span>
            @endif
            @if (is_int($event->type))
                <span class="badge badge-pill badge-default">{{$event->type}}</span>
            @else
            <span class="badge badge-pill" style="background-color: {{\App\ComplementaryActivity::find($event->type)->calendar_color}}">{{\App\ComplementaryActivity::find($event->type)->name}}</span>
            @endif
        </div>
    </div>
    <div class="row mt-4">
        <div class="col-md-12">
            {!!$event->desc!!}
        </div>
    </div>
    @if (!$event->courses->isEmpty())
        <div class="row mt-4">
            <div class="col-md-12">
                <h4 class="title text-center">Horaire</h4>
                <div class="row d-none d-md-flex">
                    <div class="col-md-2 m-3"></div>
                    @for ($p = 1; $p <= \App\Config::getData('admin_periode_nb'); $p++)
                        <div class="col-md m-3">
                            Période {{$p}} <small>{{\App\Config::all()->where('name','admin_periode_begin')->first()->data[$p]}} à {{\App\Config::all()->where('name','admin_periode_end')->first()->data[$p]}} </small>    
                        </div>
                    @endfor
                </div>
                @for ($l = 1; $l <= \App\Config::getData('admin_level_in_schedule_nb'); $l++)
                    <div class="row">
                        <div class="col-md-2 m-3">
                            Niveau {{$l}}
                        </div>
                        @for ($p = 1; $p <= \App\Config::getData('admin_periode_nb'); $p++)
                            <div class="col-md m-3">
                                @foreach ($event->courses as $course)
                                    @if ($course->periode == $p && $course->level == $l)
                                        <div class="row">
                                            <div class="col-sm-6 my-2">
                                                {{$course->name}}
                                            </div>
                                            <div class="col-sm-6 my-2 text-sm-right">
                                                @if(\App\User::find($course->user_id))
                                                 {{\App\User::find($course->user_id)->fullname()}}
                                                @else
                                                    Utilisateur Inconnu
                                                @endif
                                            </div>
                                            <div class="col-sm-6 my-2">
                                                {{$course->ocom}}
                                            </div>
                                            <div class="col-sm-6 my-2 text-sm-right">
                                                {{$course->location}}                                    
                                            </div>
                                            <div class="col-sm-12">
                                                <a class="btn btn-primary btn-sm btn-block" data-toggle="collapse" href="#collapse{{$l.$p}}" aria-expanded="false" aria-controls="collapse{{$l.$p}}">Réservation de materiel</a>
                                                <div class="collapse" id="collapse{{$l.$p}}">
                                                    <div class="m-3">
                                                        @if (!$course->bookings->isEmpty())
                                                            <div class="row">
                                                                <div class="col-sm-8 p-2">
                                                                    <strong>Item</strong> 
                                                                </div>
                                                                <div class="col-sm-4 text-right p-2">
                                                                    <strong>Quantité</strong> 
                                                                </div>
                                                                <hr>
                                                                @foreach ($course->bookings as $booking)
                                                                    <div class="col-sm-8 p-2">
                                                                        <a href="/admin/item/{{$booking->item->id}}">{{$booking->item->name}}</a> 
                                                                    </div>
                                                                    <div class="col-sm-4 text-right p-2">
                                                                        {{$booking->amount}}
                                                                    </div>
                                                                @endforeach
                                                            </div>
                                                        @else
                                                            <p class="text-center">
                                                               <strong>Aucune réservation</strong>
                                                            </p>
                                                        @endif
                                                        <hr>
                                                        <a class="btn btn-primary btn-sm btn-block mt-2" href="/admin/booking/course/{{$course->id}}" role="button">Modifier les réservation</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        @endif
                                @endforeach
                            </div>
                        @endfor
                    </div>
                @endfor
            </div>
        </div>
    @endif
@endsection