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

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

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

    <h1><i class="fa fa-users"></i> Building Administration<?php /* <a href="/logout" class="btn btn-default pull-right">Logout</a> */ ?></h1>

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

    <?php if(Auth::user()->isAdmin()): ?>
    <a href="building/create" class="btn btn-success" style="margin-bottom: 8px;">Add Building</a>
    <?php endif; ?>

    <div class="table-responsive">
        <table class="table table-bordered table-striped">

            <thead>
                <tr>
                    <th>Address</th>
                    <th>Maximum Nights Allowed</th>
                    <th>Daily Reset</th>
                    <th></th>
                </tr>
            </thead>

            <tbody>
                <?php foreach($buildings as $building): ?>
                <tr>
                    <td><?php echo $building->address; ?></td>
                    <td><?php echo $building->max_nights; ?></td>
                    <td><?php echo $building->formatDailyReset(); ?></td>
                    <td>
                        <a href="building/<?php echo $building->id; ?>/tenant" class="btn btn-info pull-left" style="margin-right: 3px;">Tenants</a>
                        <?php if(Auth::user()->isAdmin()): ?>
                        <a href="building/<?php echo $building->id; ?>/edit" class="btn btn-info pull-left" style="margin-right: 3px;">Edit</a>
                        <button type="button" class="btn btn-danger" data-toggle="modal" style="margin-right: 3px"
                                data-target="#confirmDeleteModal"
                                data-id="<?php echo $building->id; ?>"
                                data-variable="<?php echo $building->address; ?>"
                                data-action="<?php echo url('building'); ?>">Delete</button>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <div class="modal fade" id="confirmDeleteModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="confirmDeleteLabel">Confirm Deletion</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            Do you wish to delete building <span id="confirmDeleteVariable"></span>?
                        </div>
                    </div>
                    <div class="modal-footer">
                        <?php echo Form::open(['method' => 'DELETE']); ?>

                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <?php echo Form::submit('Delete', ['class' => 'btn btn-danger']); ?>

                        <?php echo Form::close(); ?>

                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

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

<?php echo $__env->make('layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>