<?php $__env->startSection('title'); ?> Admin Dashboard <?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<div class="col-lg-10 col-lg-offset-1">

    <h1><i class="fa fa-users"></i> Admin Dashboard</h1>

    <?php if(Session::has('success')): ?>
    <div class='alert alert-success'><?php echo Session::get('success'); ?></div>
    <?php endif; ?>

    <?php if($buildings->isEmpty()): ?>
    <h3>No Buildings</h3>
    <?php else: ?>
    <?php foreach($buildings as $building): ?>
    <h3><?php echo $building->address; ?></h3>
    <div class="table-responsive">
        <table class="table table-bordered table-striped">

            <thead>
                <tr>
                    <th>License Plate</th>
                    <th>Make</th>
                    <th>Model
                    <th>Colour</th>
                    <th>Start Date</th>
                    <th>End Date</th>
                    <th>Apartment</th>
                    <th>Date/Time Added</th>
                </tr>
            </thead>

            <tbody>
            <?php
                $daily_time = new Carbon\Carbon($building->daily_reset, 'America/Toronto');
                $cur_time = Carbon\Carbon::now('America/Toronto');

                // Check whether the daily reset time is passed
                if ($cur_time->lt($daily_time)) {
                    $parking_requests = ParkingRequest::where('building_id', '=', $building->id)
                        ->where('start_date', '<=', date('Y-m-d'))
                        ->where('end_date', '>=', date('Y-m-d'))
                        ->get();
                } else {
                    $parking_requests = ParkingRequest::where('building_id', '=', $building->id)
                        ->where('start_date', '<=', date('Y-m-d'))
                        ->where('end_date', '>', date('Y-m-d'))
                        ->get();
                }
            ?>
            <?php $__empty_1 = true; foreach($parking_requests->sortByDesc('created_at') as $p): $__empty_1 = false; ?>
                <tr>
                    <td><?php echo $p->car->license_plate; ?></td>
                    <td><?php echo $p->car->make; ?></td>
                    <td><?php echo $p->car->model; ?></td>
                    <td><?php echo $p->car->colour; ?></td>
                    <td><?php echo $p->start_date; ?></td>
                    <td><?php echo $p->end_date; ?></td>
                    <td><?php echo $p->tenant->apartment; ?></td>
                    <td><?php echo $p->created_at->format('F d, Y h:ia'); ?></td>
                </tr>
                <?php if(!empty($p->comments)): ?>
                <tr>
                    <td colspan="12">
                        <div>
                            <dt>Comments</dt>
                            <dd><?php echo $p->comments; ?></dd>
                        </div>
                    </td>
                </tr>
                <?php endif; ?>
            <?php endforeach; if ($__empty_1): ?>
                <tr><td colspan="12">No parking requests</td></tr>
            <?php endif; ?>
            </tbody>

        </table>
    </div>
    <?php endforeach; ?>
    <?php endif; ?>

</div>

<?php $__env->stopSection(); ?>