<?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"/>


    <style>

        /* Important part */
        #edit-hostel .modal-dialog{
            overflow-y: initial !important
        }
        #edit-hostel .modal-body{
            height: 800px;
            overflow-y: auto;
        }

        #add-hostel .modal-dialog{
            overflow-y: initial !important
        }
        #add-hostel .modal-body{
            height: 800px;
            overflow-y: auto;
        }

        .pac-container {
            z-index: 10052 !important;
        }

        #map {
            width: auto !important;
            height: 500px !important;
        }

        #map_edit {
            width: auto !important;
            height: 500px !important;
        }

        tfoot {
            display: table-header-group;
        }

        tfoot input {
            font-weight: normal !important;
        }

        tfoot select {
            font-weight: normal !important;
        }

        .dataTables_filter {
            display: none;
        }

        #orders-table_length {
            display: none;
        }

        .ws-nr {
            width: 100% !important;
        }

        /*.alert-danger .btn-danger {*/
        /*float: right;*/
        /*}*/

        /*.alert-danger span {*/
        /*line-height: 34px;*/
        /*}*/

        /*.alert-danger > div:after {*/
        /*clear: both;*/
        /*content: '';*/
        /*display: table;*/
        /*}*/
    </style>

<?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(session()->has('success_coupon')): ?>
        <?php echo session()->get('success_coupon'); ?>

    <?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; ?>
    <h1 class="page-title">
        Danh sách nhà
    </h1>


    <div class="row">
        <?php if(auth('backend')->user()->hasPermissionTo('add-hostel')): ?>
            <div class="col-md-12">
                <div class="text-center" style="margin-top: 15px; line-height: 34px">
                    
                    
                    
                    
                    

                    
                    
                    
                    

                    

                    <a href="#add-hostel" data-toggle="modal" class="btn btn-success" id="btn-add-hostel"
                       style="float: right">Thêm nhà</a>

                </div>
            </div>
        <?php endif; ?>
        <div class="col-md-12">
            <table class="table table-striped table-bordered table-hover" id="orders-table">
                <thead>
                <tr style="background-color: #5376B9; color: white">
                    <th>STT</th>
                    <th>Tên nhà</th>
                    <th>Số phòng</th>
                    <th>Số giường</th>
                    <th>Chỗ trống</th>
                    <th>Địa chỉ</th>
                    <th>Chủ sở hữu</th>
                    <th>CMTND</th>
                    <th>Số điện thoại</th>
                    <th>Email</th>
                    <th style="width: 10%;">Thao tác</th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th><input type="text" class="form-control"></th>
                    <th style="width: 10%;"></th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12" id="detail">
        </div>
    </div>

    <div class="modal fade bs-modal-lg" id="add-hostel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close2" data-dismiss="modal" aria-hidden="true"><span
                                aria-hidden="true" style="
    color: white;
">×</span></button>
                    <h4 class="modal-title">Thêm nhà</h4>
                </div>
                <div class="modal-body" id="add-hostel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-hostel">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="edit-hostel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Cập nhật nhà</h4>
                </div>
                <div class="modal-body" id="edit-hostel-content">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal" id="dismiss-modal">Hủy
                    </button>
                    <button type="button" class="btn green" id="btn-save-edit-hostel">Lưu</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>




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

<?php $__env->startPush('scripts'); ?>
<script src="/assets/global/plugins/dropzone/dropzone.min.js" type="text/javascript"></script>
<script src="/assets/pages/scripts/form-dropzone.min.js" type="text/javascript"></script>
<script src="/assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
<script src="/assets/global/plugins/jquery-validation/js/additional-methods.min.js" type="text/javascript"></script>
<script type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCydLs7dhJPuozABFQjJO-uk1PITW18oo8&libraries=places&region=vi&language=vi&sensor=false"></script>
<script type="text/javascript" src="/js/gmap.js"></script>

<script>
    $.validator.addMethod("greaterThan",
        function (value, element, param) {
            var $otherElement = $(param);
            return parseInt(value, 10) >= parseInt($otherElement.val(), 10);
        }
    );
</script>


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


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















<script>

    var map;
    var table;
    var cur_lat = null;
    var cur_lng = null;

    function geo_input() {
        var input = document.getElementById('query_place');
        var autocomplete = new google.maps.places.Autocomplete(input, {
            types: ["geocode"],
            componentRestrictions: {country: "vn"}
        });

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            var place = autocomplete.getPlace();
            var lat_place = place.geometry.location.lat();
            var lng_place = place.geometry.location.lng();
            $('#lat').val(lat_place);
            $('#lng').val(lng_place);
            map.setCenter(lat_place, lng_place)
        });
    }

    function geo_input_edit() {
        var input = document.getElementById('query_place_edit');
        var autocomplete = new google.maps.places.Autocomplete(input, {
            types: ["geocode"],
            componentRestrictions: {country: "vn"}
        });

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            var place = autocomplete.getPlace();
            var lat_place = place.geometry.location.lat();
            var lng_place = place.geometry.location.lng();
            $('#lat-e').val(lat_place);
            $('#lng-e').val(lng_place);
            map.setCenter(lat_place, lng_place)
        });
    }
    $(document).ready(function () {


    });

    //    $(document).on('change', '.add-image-hostel', function(e) {
    //        alert('123');
    //       $('.fileinput-exists').css({
    //           'width' : '48%'
    //       });
    //
    //      $('.btn-file').css({
    //          'width' : '100%'
    //      });
    //
    //
    //    });


    $("#add-hostel").on("shown.bs.modal", function (e) {
        $.ajax({
            url: '<?php echo e(url('admin2/hostel/create')); ?>',
            type: 'get',
            dataType: 'json',
            beforeSend: function () {
                $('#add-hostel-content').addClass('ht-on-loading');
            },
            success: function (response) {
                $('#add-hostel-content').removeClass('ht-on-loading').html(response.data);
                geo_input();
                $('.nav-tabs').tab();

                $('.nav-tabs a').on('shown.bs.tab', function (event) {
                    //   map.refresh();

                    var lat = 21.0277644;
                    var lng = 105.8341598;

                    <?php if(!empty(auth('backend')->user()->province_id)): ?>
                            <?php $item = \App\Components\Functions::getProvinceName(auth('backend')->user()->province_id);

                            ?>
                            <?php endif; ?>
                            <?php if(!empty(auth('backend')->user()->district_id)): ?>
                            <?php $item = \App\Components\Functions::getDistrictName(auth('backend')->user()->district_id);

                            ?>
                            <?php endif; ?>

                            <?php if(!empty($item) && !empty($item->lat) && !empty($item->lng)): ?>

                        lat = parseFloat('<?php echo e($item->lat); ?>');
                    lng = parseFloat('<?php echo e($item->lng); ?>');

                    <?php endif; ?>

                    if (cur_lat != null && cur_lng != null) {
                        lat = cur_lat;
                        lng = cur_lng;
                    }
                    map = new GMaps({
                        div: '#map',
                        lat: lat,
                        lng: lng,
                        center_changed: function () {
                            var lat = map.getCenter().lat();
                            var lng = map.getCenter().lng();
                            $('#lat').val(lat);
                            $('#lng').val(lng);
                            cur_lat = lat;
                            cur_lng = lng;
                        }
                    });

                    $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
                    //do something onclick
                        .click(function () {
                            var that = $(this);
                            if (!that.data('win')) {
                                that.data('win', new google.maps.InfoWindow({
                                    content: 'Vị trí được chọn'
                                }));
                                that.data('win').bindTo('position', map.map, 'center');
                            }
                            that.data('win').open(map.map);
                        });
                });


                //  google.maps.event.trigger(map.map, 'resize');

                $('.select2').select2();
                $('.ckeditor').ckeditor();
            }
        });


    });


    $(document).on('click', '.btn-delete-amenity', function (e) {
        e.preventDefault();
        $(this).parent().parent().parent().remove();
    });

    $(document).on('click', '#btn-add-amenity-hostel', function (e) {

        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-user-amenity')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#user_amenities').append(response.data);
            }
        });
    });


    $(document).on('click', '#btn-add-policy-edit-hostel', function (e) {

        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-user-policy')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#user_policies').append(response.data);
            }
        });
    });

    $(document).on('click', '#btn-add-amenity-edit-hostel', function (e) {

        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-user-amenity')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#user_amenities').append(response.data);
            }
        });
    });

    $(document).on('click', '.btn-edit-hostel', function (e) {
        cur_lat = null;
        cur_lng = null;

        e.preventDefault();

        hostelId = $(this).attr('data-hostel');

        $.ajax({
            url: '<?php echo e(url('admin2/hostel/edit')); ?>' + '/' + hostelId,
            type: 'get',
            dataType: 'json',
            beforeSend: function () {
                $('#edit-hostel-content').addClass('ht-on-loading');
                $('#add-hostel-content').html('');
            },
            success: function (response) {
                $('#edit-hostel-content').removeClass('ht-on-loading').html(response.data);
                $('.nav-tabs').tab();
                $('.select2').select2();

                var lat = 21.0277644;
                var lng = 105.8341598;

                if (response.lat && response.lng) {
                    lat = response.lat;
                    lng = response.lng;
                }
                map = new GMaps({
                    div: '#map_edit',
                    lat: lat,
                    lng: lng
                });
                map.addMarker({
                    lat: lat,
                    lng: lng,
                    draggable: true,
                    dragend: function (event) {
                        var lat = event.latLng.lat();
                        var lng = event.latLng.lng();
                        $('#lat').val(lat);
                        $('#lng').val(lng);
                    },
                });


                $('.nav-tabs a').on('shown.bs.tab', function (event) {

                    var lat = 21.0277644;
                    var lng = 105.8341598;


                    if (response.lat && response.lng) {
                        lat = response.lat;
                        lng = response.lng;
                    }
                    if (cur_lat != null && cur_lng != null) {
                        lat = cur_lat;
                        lng = cur_lng;
                    }
                    map.refresh();
                    map = new GMaps({
                        div: '#map_edit',
                        lat: lat,
                        lng: lng,
                        center_changed: function () {
                            var lat = map.getCenter().lat();
                            var lng = map.getCenter().lng();
                            $('#lat-e').val(lat);
                            $('#lng-e').val(lng);
                        }
                    });


                    $('<div/>').addClass('centerMarker').appendTo(map.getDiv())
                    //do something onclick
                        .click(function () {
                            var that = $(this);
                            if (!that.data('win')) {
                                that.data('win', new google.maps.InfoWindow({
                                    content: 'Vị trí được chọn'
                                }));
                                that.data('win').bindTo('position', map.map, 'center');
                            }
                            that.data('win').open(map.map);
                        });
                });
                $('.ckeditor').ckeditor();
                geo_input_edit();
            }
        });

    });


    $(document).on('click', '#btn-add-amenity-edit-hostel', function (e) {

        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-user-amenity')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#user_edit_amenities').append(response.data);
            }
        });
    });

    $(document).on('click', '#btn-add-policy-hostel', function (e) {

        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-user-policy')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#user_policies').append(response.data);
            }
        });
    });

    $('#btn-save-edit-hostel').click(function (e) {
        e.preventDefault();

        var formStatus = $('#form-edit-hostel').validate({
            errorElement: "span",
            errorClass: "help-block help-block-error",

            highlight: function (e) {
                $(e).closest(".form-group").addClass("has-error")
            },
            unhighlight: function (e) {
                $(e).closest(".form-group").removeClass("has-error")
            },
            success: function (e) {
                e.closest(".form-group").removeClass("has-error")
            },
            rules: {
                'type': "required",
                'name': "required",
                //  'amenities[]': "required",
                'type_rent': {
                    required: true,
                    number: true
                },
                'address': {
                    required: true,
                },
                'province_id': {
                    required: true,
                },
                'district_id': {
                    required: true,
                },
                'ward_id': {
                    required: true,
                },
                'owner_name': {
                    required: true,
                },
                'owner_id_number': {
                    required: true,
                },
                'owner_phone': {
                    required: true,
                },
                'owner_email': {
                    email: true,
                },
                'date_ew': {
                    required: true,
                },
                'date_money': {
                    required: true,
                    //greaterThan: '#edit-hostel-date-ew'
                },
            },
            messages: {
                'type': "Không được bỏ trống Loại nhà",
                'name': "Không được bỏ trống tên",
                'type_rent': "Không được bỏ trống loại cho thuê",
                'address': "Không được bỏ trống địa chỉ",
                'province_id': "Không được bỏ trống tỉnh / thành phố",
                'district_id': "Không được bỏ trống quận / huyện",
                'ward_id': "Không được bỏ trống phường / xã",
                'owner_name': "Không được bỏ trống tên chủ sở hữu",
                'owner_id_number': "Không được bỏ trống cmnd chủ sở hữu",
                'owner_phone': "Không được bỏ trống SDT chủ sở hữu",

                'owner_email': {
                    "email": "Email phải đúng định dạng"
                },
                'date_ew': "Không được bỏ trống ngày chốt điện nước",
                'date_money': {
                    required: "Không được bỏ trống ngày chốt sổ, tính phí",
                    //greaterThan: "Ngày chốt sổ phải lớn hơn ngày chốt điện nước"
                }
                // 'amenities[]': "Không được bỏ trống tiện ích"
            }
        }).form();

        if (formStatus) {
            var data = new FormData($('#form-edit-hostel')[0]);

            var ck = $('#form-edit-hostel').find('[name="desc"]').val();
            data.append('desc', ck);

            $.ajax({
                url: '<?php echo e(url('admin2/hostel/edit')); ?>' + '/' + hostelId,
                type: 'post',
                data: data,
                dataType: 'json',
                processData: false,
                contentType: false,
                beforeSend: function () {
                    $('#edit-hostel-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#edit-hostel-content').removeClass('ht-on-loading');

                    if (response.status == 1) {
                        table.ajax.reload(null, false);
                        swal('Thành công', 'Thông tin được lưu thành công', 'success');
                        $('#edit-hostel').modal('hide');
                    } else if (response.status == 0) {
                        swal('Thông báo', response.message, 'warning');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                }
            });
        }
    });

    $('#btn-save-hostel').click(function (e) {
        e.preventDefault();

        var formStatus = $('#form-add-hostel').validate({
            errorElement: "span",
            errorClass: "help-block help-block-error",

            highlight: function (e) {
                $(e).closest(".form-group").addClass("has-error")
            },
            unhighlight: function (e) {
                $(e).closest(".form-group").removeClass("has-error")
            },
            success: function (e) {
                e.closest(".form-group").removeClass("has-error")
            },
            rules: {
                'type': "required",
                'name': "required",
                //  'amenities[]': "required",
                'type_rent': {
                    required: true,
                    number: true
                },
                'address': {
                    required: true,
                },
                'province_id': {
                    required: true,
                },
                'district_id': {
                    required: true,
                },
                'ward_id': {
                    required: true,
                },
                'owner_name': {
                    required: true,
                },
                'owner_id_number': {
                    required: true,
                },
                'owner_phone': {
                    required: true,
                },
                'owner_email': {
                    required: true,
                    email: true
                },
                'date_ew': {
                    required: true,
                },
                'date_money': {
                    required: true,
                    //greaterThan: "#add-hostel-date-ew"
                }
            },
            messages: {
                'type': "Không được bỏ trống Loại nhà",
                'name': "Không được bỏ trống tên",
                'type_rent': "Không được bỏ trống loại cho thuê",
                'address': "Không được bỏ trống địa chỉ",
                'province_id': "Không được bỏ trống tỉnh / thành phố",
                'district_id': "Không được bỏ trống quận / huyện",
                'ward_id': "Không được bỏ trống phường / xã",
                'owner_name': "Không được bỏ trống tên chủ sở hữu",
                'owner_id_number': "Không được bỏ trống cmnd chủ sở hữu",
                'owner_phone': "Không được bỏ trống SDT chủ sở hữu",

                'owner_email': {
                    required: "Không được bỏ trống email chủ sở hữu",
                    email: "Email phải đúng định dạng"
                },
                'date_ew': "Không được bỏ trống ngày chốt điện nước",
                'date_money': {
                    required: "Không được bỏ trống ngày chốt sổ, tính phí",
                   // greaterThan: "Ngày chốt sổ phải lớn hơn hoặc bằng ngày chốt điện nước"
                }
                // 'amenities[]': "Không được bỏ trống tiện ích"
            }
        }).form();

        if (formStatus) {
            var data = new FormData($('#form-add-hostel')[0]);
            var ck = $('#form-add-hostel').find('[name="desc"]').val();
            data.append('desc', ck);
            $.ajax({
                url: '<?php echo e(url('admin2/hostel/create')); ?>',
                type: 'post',
                data: data,
                dataType: 'json',
                processData: false,
                contentType: false,
                beforeSend: function () {
                    $('#add-hostel-content').addClass('ht-on-loading');
                },
                success: function (response) {
                    $('#add-hostel-content').removeClass('ht-on-loading');

                    if (response.status == 1) {
                        swal('Thành công', 'nhà của bạn đã được lưu lại', 'success');
                        $('#add-hostel').modal('hide');

                    } else if (response.status == 0) {
                        swal('Thông báo', response.message, 'warning');
                    } else if (response.status == 2) {
                        swal('Thông báo', response.message, 'info');
                    }
                    table.ajax.reload();

                    $.ajax({
                        url: '<?php echo e(url('admin2/hostel/get-remain-hostel')); ?>',
                        type: 'get',
                        success: function (response) {
                            if (response.status == 1) {
                                $('#report').text(response.message);
                            }
                        }
                    });
                }
            });
        }
    });

    $(document).on('click', '#btn-get-current-position', function (e) {
        GMaps.geolocate({
            success: function (position) {
                map.setCenter(position.coords.latitude, position.coords.longitude);
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat').val(lat);
//                        $('#lng').val(lng);
//                    },
//                });
                $('#lat').val(position.coords.latitude);
                $('#lng').val(position.coords.longitude);
            },
            error: function (error) {
                map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat').val(lat);
//                        $('#lng').val(lng);
//                    },
//                });
            },
            not_supported: function () {
                map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat').val(lat);
//                        $('#lng').val(lng);
//                    },
//                });
            },
        });
    });

    $(document).on('click', '#btn-get-current-position-edit', function (e) {
        GMaps.geolocate({
            success: function (position) {
                map.setCenter(position.coords.latitude, position.coords.longitude);
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
                $('#lat-e').val(position.coords.latitude);
                $('#lng-e').val(position.coords.longitude);
            },
            error: function (error) {
                map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
            },
            not_supported: function () {
                map.setCenter('21.028511', '105.804817');
//                map.addMarker({
//                    lat: position.coords.latitude,
//                    lng: position.coords.longitude,
//                    draggable: true,
//                    dragend: function (event) {
//                        var lat = event.latLng.lat();
//                        var lng = event.latLng.lng();
//                        $('#lat-e').val(lat);
//                        $('#lng-e').val(lng);
//                    },
//                });
            },
        });
    });

    function getPostByAttr() {
        var startTime = $('#start_time').val();
        var endTime = $('#end_time').val();
        var timeRange = $('#time_range').val();


        table = $('#orders-table').DataTable({
            "bDestroy": true,
            processing: true,
            //  serverSide: true,
            "aaSorting": [],
            searching: true,
            ajax: {
                url: '<?php echo url('admin2/hostel/hostel.data'); ?>',
                data: {
                    start_time: startTime,
                    end_time: endTime,
                    time_range: timeRange,
                }
            },
            columns: [
//               {data: 'DT_Row_Index', name: 'DT_Row_Index'},
                {data: 'name', name: 'name'},
                {data: 'number_rooms', name: 'number_rooms'},
                {data: 'number_beds', name: 'number_beds'},
                {data: 'number_empty_rooms', name: 'number_empty_rooms', 'orderable': false, 'searchable': false},
                {data: 'address', name: 'address'},
                {data: 'owner_name', name: 'owner_name'},
                {data: 'owner_id_number', name: 'owner_id_number'},
                {data: 'owner_phone', name: 'owner_phone'},
                {data: 'owner_email', name: 'owner_email'},
                {data: 'action', name: 'action', 'orderable': false},
            ]
        });
    }

    $(function () {

        $('#orders-table tfoot th').each(function (index) {
            if (index != 0 && index != 9) {
                $(this).html('<input type="text" class="form-control" />');
            }
        });
        table = $('#orders-table').DataTable({
            "bDestroy": true,
            processing: true,
            searching: true,
            "aaSorting": [],
            serverSide: true,
            ajax: {
                url: '<?php echo url('admin2/hostel/hostel.data'); ?>',
            },
            columns: [

                {data: 'DT_Row_Index', name: 'DT_Row_Index', orderable: false, searchable: false},
                {data: 'name', name: 'name'},
                {data: 'number_rooms', name: 'number_rooms'},
                {data: 'number_beds', name: 'number_beds'},
                {data: 'number_empty_rooms', name: 'number_empty_rooms'},
                {data: 'address', name: 'address'},
                {data: 'owner_name', name: 'owner_name'},
                {data: 'owner_id_number', name: 'owner_id_number'},
                {data: 'owner_phone', name: 'owner_phone'},
                {data: 'owner_email', name: 'owner_email'},
                {data: 'action', name: 'action', 'orderable': false, searchable: false},
            ],
        });


        table.columns().every(function (index) {
            if (index !== 0) {
                var that = this;
                $('input', this.footer()).on('keyup change', function () {
                    if (that.search() !== this.value) {
                        that
                            .search(this.value)
                            .draw();
                    }
                });
            }
        });

    });

    function getCoor(id, type) {
        $.ajax({
            url: '<?php echo e(url('get-location-coor')); ?>',
            type: 'get',
            data: {
                'id': id,
                'type': type
            },
            dataType: 'json',
            success: function (response) {
                if (map) {
                    map.setCenter(
                        response.lat,
                        response.lng
                    );
                }

                cur_lat = response.lat;
                cur_lng = response.lng;

            }
        });
    }

    $(document).on('change', '#province_id', function (e) {
        var id = $(this).val();
        $.ajax({
            url: '<?php echo e(url('get-sub-location')); ?>',
            type: 'get',
            data: {
                'id': $(this).val(),
                'type': 'province',
            },
            dataType: 'html',
            success: function (response) {
                $('#district_id').html(response);
                $('#ward_id').html('');
                getCoor(id, 'province');


            }
        });
    });

    $(document).on('change', '#district_id', function (e) {
        var id = $(this).val();
        $.ajax({
            url: '<?php echo e(url('get-sub-location')); ?>',
            type: 'get',
            data: {
                'id': $(this).val(),
                'type': 'district'
            },
            dataType: 'html',
            success: function (response) {
                $('#ward_id').html(response);
                getCoor(id, 'district');
            }
        });
    });

    //    $(document).on('change', '#ward_id', function (e) {
    //        var id = $(this).val();
    //        getCoor(id, 'ward');
    //    });

    $(document).on('click', '#btn-add-image-hostel', function (e) {
        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-image-room')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#hostel_images').append(response.data);
                $('.dropzone').dropzone({
                    url: '<?php echo e(url('admin2/room/upload-image')); ?>',
                    dictDefaultMessage: "",
                    dictMaxFilesExceeded: 'Bạn chỉ được tải lên 1 file',
                    init: function () {
                        this.on("success", function (file, response) {
                            var name = string_to_slug(file.name);
                            $('#room_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                        }).on("addedfile", function (e) {
                            var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                t = this;
                            n.addEventListener("click", function (n) {
                                n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                            }), e.previewElement.appendChild(n)
                        }).on("removedfile", function (file) {
                            var name = string_to_slug(file.name);
                            $('#' + name).remove();
                        })


                    },
                    acceptedFiles: 'image/*',
                    maxFiles: 1,
                    headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                });
            }
        });

    });

    $(document).on('click', '#btn-add-edit-image-hostel', function (e) {
        e.preventDefault();
        $.ajax({
            url: '<?php echo e(url('admin2/room/create-image-room')); ?>',
            type: 'get',
            dataType: 'json',
            success: function (response) {
                $('#hostel_images_list').append(response.data);
                $('.dropzone').dropzone({
                    url: '<?php echo e(url('admin2/room/upload-image')); ?>',
                    dictDefaultMessage: "",
                    dictMaxFilesExceeded: 'Bạn chỉ được tải lên 1 file',
                    init: function () {
                        this.on("success", function (file, response) {
                            var name = string_to_slug(file.name);
                            $('#room_images').append('<input type="hidden" id="' + name + '" name="images[]" value="' + response.data + '" />')
                        }).on("addedfile", function (e) {
                            var n = Dropzone.createElement("<a href='javascript:;'' class='btn red btn-sm btn-block'>Xóa</a>"),
                                t = this;
                            n.addEventListener("click", function (n) {
                                n.preventDefault(), n.stopPropagation(), t.removeFile(e);

                            }), e.previewElement.appendChild(n)
                        }).on("removedfile", function (file) {
                            var name = string_to_slug(file.name);
                            $('#' + name).remove();
                        })


                    },
                    acceptedFiles: 'image/*',
                    maxFiles: 1,
                    headers: {'X-CSRF-Token': '<?php echo e(csrf_token()); ?>'}

                });
            }
        });

    });

    $(document).on('click', '.btn-delete-hostel-image', function (e) {
        var that = this;

        e.preventDefault();

        var id = $(this).attr('data-id');

        bootbox.confirm({
            message: "Bạn có chắc chắn muốn xóa",
            buttons: {
                confirm: {
                    label: 'Có',
                    className: 'btn-success'
                },
                cancel: {
                    label: 'Không',
                    className: 'btn-danger'
                }
            },


            callback: function (result) {
                if (result == true) {
                    $.ajax({
                        url: '<?php echo e(url('admin2/hostel/delete-image')); ?>',
                        type: 'post',
                        data: {
                            id: id
                        },
                        dataType: 'json',
                        success: function (response) {
                            swal('Xóa thành công', '', 'success');
                            // $('#hostel_images_list').html(response.data);
                            $(that).parent().remove();
                        }
                    });
                }
            }
        });

    });


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