@extends('layouts.app')

@section('content')


<!-- Badge Logo -->
<!-- <div class="container">
    <div class="row justify-content-center">
        <div class="col">

            <img src='img/badge.gif' class="rounded mx-auto d-block img-fluid" alt='Badge' >
                <br>
        </div>
    </div>
</div> -->

<div class="container">
    <div class="row justify-content-start">
        <div class="col col-md-8">

            <h1>Daily Roster</h1>

        </div>
    </div>

    <div class="row justify-content-start mt-3">
        <div class="col col-md-8">
            <form method="POST" action="/user/psheet/date">
                @csrf

                <div class="form-group row">
                    <label for="calendar_date" class="col-md-2 col-form-label ">{{ __('Select Date') }}</label>

                    <div class="form-group col-md-4">
                        <input id="calendar_date" class="form-control" type="date" name="calendar_date" value={{ $daySelected }} required>

                        @error('date-in-position')
                            <span class="calendar_date" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                        @enderror
                    </div>
                    <div class="form-grup col-md-4">
                        <button type="submit" class="btn btn-primary">
                            {{ __('Submit') }}
                        </button>
                    </div>
                </div>
            </form>

        </div>

        @if ( $editable ?? ''  )
            <div class="col col-md-2"></div>
            <div class="col col-md-2">
                <button class="btn btn-primary float-right">Edit</button>
            </div>
        @endif
    </div>
</div>

<div class="container shadow">
    <div class="row border border-primary ">
        <div class="col col-md-12 p-2">
            <div class="table-responsive-md">
                @if ($noSpots ?? '')
                    <div class="alert alert-warning" role="alert">
                        {{ $noSpots }}
                    </div>
                @endif
                @foreach( $shifts as $shift )
                    <table class="table">
                        <thead class="thead-light">
                            <tr>
                                <th style="width: 8%" scope="col">{{ $shift }}</th>
                                <th style="width: 7%" scope="col">Unit #</th>
                                <th style="width: 9%" scope="col">Emgcy #</th>
                                <th style="width: 20%" scope="col">Name</th>
                                <th style="width: 7%" scope="col">Shift Start</th>
                                <th style="width: 7%" scope="col">Shift End</th>
                                <th style="width: 7%" scope="col">Zone</th>
                                <th style="width: 7%" scope="col">Specialties</th>
                                <th style="width: 7%" scope="col">Vehicle</th>
                            </tr>
                        </thead>

                        <tbody>
                            <!--Print all the officers in regular schedule-->
                            @foreach( $bids as $index => $bid)
                                @if($bid->spot->shift->name == $shift)
                                <tr>
                                    <td>{{ implode(', ', $bid->user->roles()->get()->pluck('name')->toArray()) }}</td>
                                    <td>{{ !empty($bid->user->officer) ? $bid->user->officer->unit_number:'' }}</td>
                                    <td>{{ !empty($bid->user->officer) ? $bid->user->officer->emergency_number:'' }}</td>
                                    <td>{{ !empty($bid->user) ? $bid->user->name:'' }}</td>
                                    <td>{{ $bid->spot->{$weekday.'_s'} }}</td>
                                    <td>{{ $bid->spot->{$weekday.'_e'} }}</td>
                                    <td>{{ !empty($bid->user->officer) ? $bid->user->officer->zone:'' }}</td>
                                    <td>{{ implode(', ', $bid->user->specialties()->get()->pluck('name')->toArray()) }}</td>
                                    <td>{{ !empty($bid->user->officer) ? $bid->user->officer->vehicle_number:'' }}</td>
                                </tr>
                                @endif
                            @endforeach

                            <!--Print officers with additional shift-->
                            @foreach($additionalShifts as $additionalShift)
                                @if($additionalShift->shift->name == $shift)
                                    <tr>
                                        <td>{{ implode(', ', $additionalShift->user->roles()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($additionalShift->user->officer) ? $additionalShift->user->officer->unit_number:'' }}</td>
                                        <td>{{ !empty($additionalShift->user->officer) ? $additionalShift->user->officer->emergency_number:'' }}</td>
                                        <td>{{ !empty($additionalShift->user) ? $additionalShift->user->name:'' }}</td>
                                        <td>{{ $additionalShift->start_time }}</td>
                                        <td>{{ $additionalShift->end_time }}</td>
                                        <td>{{ !empty($additionalShift->user->officer) ? $additionalShift->user->officer->zone:'' }}</td>
                                        <td>{{ implode(', ', $additionalShift->user->specialties()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($additionalShift->user->officer) ? $additionalShift->user->officer->vehicle_number:'' }}</td>
                                    </tr>
                                @endif
                            @endforeach

                            <!--Print all the officers RDOs-->
                            @foreach( $RDOs as $index => $rdo)
                                @if($rdo->spot->shift->name == $shift)
                                    <tr>
                                        <td>{{ implode(', ', $rdo->user->roles()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($rdo->user->officer) ? $rdo->user->officer->unit_number:'' }}</td>
                                        <td>{{ !empty($rdo->user->officer) ? $rdo->user->officer->emergency_number:'' }}</td>
                                        <td>{{ !empty($rdo->user) ? $rdo->user->name:'' }}</td>
                                        <td>RDO</td>
                                        <td>RDO</td>
                                        <td>{{ !empty($rdo->user->officer) ? $rdo->user->officer->zone:'' }}</td>
                                        <td>{{ implode(', ', $rdo->user->specialties()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($rdo->user->officer) ? $rdo->user->officer->vehicle_number:'' }}</td>
                                    </tr>
                                @endif
                            @endforeach

                            <!--Print officers with days off-->
                            @foreach($daysOff as $dayOff)
                                @if($dayOff->user->bids[0]->spot->shift->name == $shift)
                                    <tr>
                                        <td>{{ implode(', ', $dayOff->user->roles()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($dayOff->user->officer) ? $dayOff->user->officer->unit_number:'' }}</td>
                                        <td>{{ !empty($dayOff->user->officer) ? $dayOff->user->officer->emergency_number:'' }}</td>
                                        <td>{{ !empty($dayOff->user) ? $dayOff->user->name:'' }}</td>
                                        <td>{{ $dayOff->dayOffType->type }}</td>
                                        <td>{{ $dayOff->dayOffType->type }}</td>
                                        <td>{{ !empty($dayOff->user->officer) ? $dayOff->user->officer->zone:'' }}</td>
                                        <td>{{ implode(', ', $dayOff->user->specialties()->get()->pluck('name')->toArray()) }}</td>
                                        <td>{{ !empty($dayOff->user->officer) ? $dayOff->user->officer->vehicle_number:'' }}</td>
                                    </tr>
                                @endif
                            @endforeach
                        </tbody>
                    </table>
                @endforeach
            </div>
        </div>
    </div>
</div>
@endsection
