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

    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/bootstrap-editable/css/bootstrap-editable.css"
          rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/bootstrap-editable/inputs-ext/address/address.css" rel="stylesheet"
          type="text/css"/>
    <link href="/assets/global/plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css"/>
    <link href="/assets/global/plugins/select2/css/select2-bootstrap.min.css" rel="stylesheet" type="text/css"/>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <?php if(session()->has('error')): ?>
        <div class="alert alert-danger"><?php echo e(session()->get('error')); ?></div>
    <?php endif; ?>
    <?php if(session()->has('success')): ?>
        <div class="alert alert-success"><?php echo e(session()->get('success')); ?></div>
    <?php endif; ?>
    <?php if(count($errors) > 0): ?>
        <div class="alert alert-danger">
            <ul>
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    <?php endif; ?>
    <h3 class="inline">Quản lý danh sách phòng</h3>

    <div class="portlet-title">

    </div>
    <div class="row">
        <div class="portlet-body form">
            <div class="form-body">
                <div class="form-group">
                    <form action="#" class="mt-repeater form-horizontal">
                        <div data-repeater-list="group-a">
                            <div data-repeater-item="" class="mt-repeater-item">

                                <div class="mt-repeater-input">
                                    <label class="control-label">Chủ nhà</label>
                                    <br>
                                    <select name="owner_id" class="form-control select2" id="owner_id">
                                        <?php $owners = App\User::query()->where('type', App\User::OWNER)->has('hostels')->get() ?>
                                        <option value="">Tất cả</option>
                                        <?php $__currentLoopData = $owners; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $owner): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($owner->id); ?>"><?php echo e($owner->name_text); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    </select>
                                </div>
                                <div class="mt-repeater-input">
                                    <label class="control-label">Nhà</label>
                                    <br>
                                    <select name="hostel_id" class="form-control" id="hostel_id">

                                    </select>
                                </div>
                                <div class="mt-repeater-input">
                                    <label class="control-label">Trạng thái</label>
                                    <br>
                                    <select name="status" class="form-control" id="status">
                                        <option value="">Tất cả</option>
                                        <option value="reserved">Đang cọc</option>
                                        <option value="empty">Đang trống</option>
                                        <option value="soon">Sắp chuyển đi</option>
                                        <option value="stay">Đang ở</option>
                                    </select>
                                </div>

                                <div class="mt-repeater-input">
                                    <a href="javascript:;" onclick="getPostByAttr()" data-repeater-delete=""
                                       class="btn btn-danger mt-repeater-delete">
                                        <i class="fa fa-check"></i> Lọc</a>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <div class="row">
        <div class="col-md-12" style="margin-bottom: 12px">
            <a href="<?php echo e(url('admin/room/create')); ?>" class="btn btn-success">Thêm</a>
        </div>
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover" id="orders-table">
                <thead>
                <tr>
                    
                    <th>Tên phòng</th>
                    <th>Nhà</th>
                    <th>Chủ nhà</th>
                    <th>Tầng</th>
                    <th>Diện tích</th>
                    <th>Tiền phòng</th>
                    <th>Đặt cọc</th>
                    <th>Trạng thái</th>
                    <th>Người thuê hiện tại</th>
                    <th>Hành động</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12" id="detail">
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>

    <script src="/assets/global/plugins/bootstrap-wysihtml5/wysihtml5-0.3.0.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/moment.min.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/jquery.mockjax.js" type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-editable/bootstrap-editable/js/bootstrap-editable.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-editable/inputs-ext/address/address.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-editable/inputs-ext/wysihtml5/wysihtml5.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/bootstrap-typeahead/bootstrap3-typeahead.min.js"
            type="text/javascript"></script>
    <script src="/assets/global/plugins/select2/js/select2.full.min.js" type="text/javascript"></script>
    

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


<?php $__env->startPush('scripts'); ?>
    <script>
        var table;

        function getPostByAttr() {
            table.ajax.reload();
        }


        $(function () {
            table = $('#orders-table').DataTable({
                "bDestroy": true,
                processing: true,
                searching: true,
                "aaSorting": [],
                serverSide: true,
                ajax: {
                    url: '<?php echo url('admin/room/room.data'); ?>',
                    data: function (d) {
                        <?php if(request()->has('owner_id')): ?>
                            d.owner_id = '<?php echo e(request()->input('owner_id')); ?>';
                        <?php else: ?>
                            d.owner_id = $('#owner_id').val();
                        <?php endif; ?>

                                <?php if(request()->has('hostel_id')): ?>
                            d.hostel_id = '<?php echo e(request()->input('hostel_id')); ?>';
                        <?php else: ?>
                            d.hostel_id = $('#hostel_id').val();
                        <?php endif; ?>
                            d.is_empty = '<?php echo e(request()->input('is_empty')); ?>';
                            d.status = $('#status').val();
                    }
                },
                columns: [

                    {data: 'name', name: 'name', orderable: false},
                    {data: 'hostel_id', name: 'hostel_id', orderable: false},
                    {data: 'owner_id', name: 'owner_id', orderable: false},
                    {data: 'floor', name: 'floor'},
                    {data: 'size', name: 'size'},
                    {data: 'price', name: 'price'},
                    {data: 'deposit', name: 'deposit'},
                    {data: 'status', name: 'status'},
                    {data: 'current_renter', name: 'current_renter', orderable: false},
                    {data: 'action', name: 'action', orderable: false},
                ],
                initComplete: function () {
                    $('.editable').editable({
                        prepend: "Chưa chọn",
                        source: [{
                            value: 1,
                            text: 'Có'
                        }, {
                            value: 0,
                            text: 'Không'
                        }],
                    });
                }
            });
        });

        $(document).on('change', '#owner_id', function (e) {
            var id = $(this).val();
            $.ajax({
                url: '<?php echo e(url('get-hostel-by-owner')); ?>',
                type: 'get',
                data: {
                    'id': id,
                },
                dataType: 'html',
                success: function (response) {
                    $('#hostel_id').html(response);
                }
            });
        });

    </script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>