<?php $__env->startSection('title'); ?><?php echo app('translator')->get('quickadmin.user-management.title'); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('customCss'); ?>
<meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
<link rel="stylesheet" href="<?php echo e(asset('admintheme/assets/css/printView-datatable.css')); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('main-content'); ?>
<style type="text/css">
    .cart_filter_box {
        border-bottom: 1px solid #e5e9f2;
        padding-bottom: 4px;
    }
</style>
<div class="card MainBox">
    <div class="mainHeading">
        <h4> <?php echo app('translator')->get('quickadmin.user-management.title'); ?></h4>
        <div class="">                            
            <div class="top_both_btn">
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('staff_create')): ?>
                <button type="button" title="New Staff" class="btn addRecordBtn sm_btn addBtn" data-href="<?php echo e(route('staff.create')); ?>">
                    <i class="fas fa-plus"></i> <?php echo app('translator')->get('quickadmin.users.fields.new_shift'); ?>
                </button>
                <?php endif; ?>

                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('staff_print')): ?>
                <a href="<?php echo e(route('staff.print')); ?>" title="Print" class="btn addRecordBtn addBtn" id="print-button"><?php if (isset($component)) { $__componentOriginal4fc2bce81e6643975498c1caac0c8935 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal4fc2bce81e6643975498c1caac0c8935 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.svg-icon','data' => ['icon' => 'print']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('svg-icon'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => 'print']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $attributes = $__attributesOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__attributesOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal4fc2bce81e6643975498c1caac0c8935)): ?>
<?php $component = $__componentOriginal4fc2bce81e6643975498c1caac0c8935; ?>
<?php unset($__componentOriginal4fc2bce81e6643975498c1caac0c8935); ?>
<?php endif; ?><?php echo app('translator')->get('quickadmin.print'); ?></a>
                <?php endif; ?>
            </div>                            
        </div>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive fixed_Search">
            <?php echo e($dataTable->table(['class' => 'table dt-responsive', 'style' => 'width:100%;','id'=>'dataaTable'])); ?>

        </div>
    </div>
</div>
<div class="popup_render_div"></div>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('customJS'); ?>
<?php echo $dataTable->scripts(); ?>

<script src="<?php echo e(asset('admintheme/assets/bundles/datatables/datatables.min.js')); ?>"></script>
<script src="<?php echo e(asset('admintheme/assets/bundles/datatables/DataTables-1.10.16/js/dataTables.bootstrap4.min.js')); ?>"></script>
<script src="<?php echo e(asset('admintheme/assets/bundles/jquery-ui/jquery-ui.min.js')); ?>"></script>
<!-- Page Specific JS File -->
<script src="<?php echo e(asset('admintheme/assets/js/page/datatables.js')); ?>"></script>


<script>
    $(document).ready(function() {
        var DataaTable = $('#dataaTable').DataTable();
        $('#print-button').printPage();
        // Page show from top when page changes
        $(document).on('draw.dt', '#dataaTable', function(e) {
            e.preventDefault();
            $('html, body').animate({
                scrollTop: 0
            }, 'fast');
        });

        $(document).on('click', '.addRecordBtn', function() {
            // $('#preloader').css('display', 'flex');
            var hrefUrl = $(this).attr('data-href');
            $.ajax({
                type: 'get',
                url: hrefUrl,
                dataType: 'json',
                beforeSend: function () {
                    showLoader();
                },
                success: function(response) {
                    //$('#preloader').css('display', 'none');
                    if (response.success) {
                        $('.popup_render_div').html(response.htmlView);
                        $('#centerModal').modal('show');
                    }
                },
                complete: function () {
                    hideLoader();
                },
                error: function() {
                    hideLoader();
                }
            });
        });

        $("body").on("click", ".edit-users-btn", function() {
            var hrefUrl = $(this).attr('data-href');
            $.ajax({
                type: 'get',
                url: hrefUrl,
                dataType: 'json',
                beforeSend: function () {
                    showLoader();
                },
                success: function(response) {
                    //$('#preloader').css('display', 'none');
                    if (response.success) {
                        console.log('success');
                        $('.popup_render_div').html(response.htmlView);
                        $('#editModal').modal('show');
                    }
                },
                complete: function () {
                    hideLoader();
                },
            });
        });

        $("body").on("click", ".edit-password-btn", function() {
            var hrefUrl = $(this).attr('data-href');
            $.ajax({
                type: 'get',
                url: hrefUrl,
                dataType: 'json',
                beforeSend: function () {
                    showLoader();
                },
                success: function(response) {
                    //$('#preloader').css('display', 'none');
                    if (response.success) {
                        console.log('success');
                        $('.popup_render_div').html(response.htmlView);
                        $('#passwordModal').modal('show');
                    }
                },
                complete: function () {
                    hideLoader();
                },
            });
        });


        $(document).on('submit', '#AddForm', function(e) {
            e.preventDefault();

            $("#AddForm button[type=submit]").prop('disabled', true);
            $(".error").remove();
            $(".is-invalid").removeClass('is-invalid');
            var formData = $(this).serialize();
            var formAction = $(this).attr('action');
            $.ajax({
                url: '<?php echo e(route("staff.store")); ?>',
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: formData,
                success: function(response) {
                    $('#centerModal').modal('hide');
                    var alertType = response['alert-type'];
                    var message = response['message'];
                    var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                    showToaster(title, alertType, message);
                    $('#AddForm')[0].reset();
                    // location.reload();
                    DataaTable.ajax.reload();
                    $("#AddForm button[type=submit]").prop('disabled', false);
                },
                error: function(xhr) {
                    var errors = xhr.responseJSON.errors;
                    for (const elementId in errors) {
                        $("#" + elementId).addClass('is-invalid');
                        var errorHtml = '<div><span class="error text-danger">' + errors[elementId] + '</span></';
                        $(errorHtml).insertAfter($("#" + elementId).parent());
                    }
                    $("#AddForm button[type=submit]").prop('disabled', false);
                }
            });
        });


        $(document).on('submit', '#EditForm', function(e) {
            e.preventDefault();
            $("#EditForm button[type=submit]").prop('disabled', true);
            $(".error").remove();
            $(".is-invalid").removeClass('is-invalid');
            var formData = $(this).serialize();
            var formAction = $(this).attr('action');
            console.log(formAction);

            $.ajax({
                url: formAction,
                type: 'PUT',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: formData,
                success: function(response) {
                    $('#editModal').modal('hide');
                    var alertType = response['alert-type'];
                    var message = response['message'];
                    var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                    showToaster(title, alertType, message);
                    $('#EditForm')[0].reset();
                    //location.reload();
                    DataaTable.ajax.reload();
                    $("#EditForm button[type=submit]").prop('disabled', false);
                },
                error: function(xhr) {
                    var errors = xhr.responseJSON.errors;
                    console.log(xhr.responseJSON);

                    for (const elementId in errors) {
                        $("#EditForm #" + elementId).addClass('is-invalid');
                        var errorHtml = '<div><span class="error text-danger">' + errors[elementId] + '</span></';
                        $(errorHtml).insertAfter($("#EditForm #" + elementId).parent());
                    }
                    $("#EditForm button[type=submit]").prop('disabled', false);
                }
            });
        });

        $(document).on('submit', '#EditPasswordForm', function(e) {
            e.preventDefault();
            $("#EditPasswordForm button[type=submit]").prop('disabled', true);
            $(".error").remove();
            $(".is-invalid").removeClass('is-invalid');
            var formData = $(this).serialize();
            var formAction = $(this).attr('action');
            console.log(formAction);

            $.ajax({
                url: formAction,
                type: 'PUT',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: formData,
                success: function(response) {
                    $('#passwordModal').modal('hide');
                    var alertType = response['alert-type'];
                    var message = response['message'];
                    var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                    showToaster(title, alertType, message);
                    $('#EditPasswordForm')[0].reset();
                    //location.reload();
                    DataaTable.ajax.reload();
                    $("#EditPasswordForm button[type=submit]").prop('disabled', false);
                },
                error: function(xhr) {
                    var errors = xhr.responseJSON.errors;
                    console.log(xhr.responseJSON);

                    for (const elementId in errors) {
                        $("#EditPasswordForm #" + elementId).addClass('is-invalid');
                        var errorHtml = '<div><span class="error text-danger">' + errors[elementId] + '</span></';
                        $(errorHtml).insertAfter($("#EditPasswordForm #" + elementId).parent());
                    }
                    $("#EditPasswordForm button[type=submit]").prop('disabled', false);
                }
            });
        });

        $(document).on('submit', '.deleteForm', function(e) {
            e.preventDefault();
            var formAction = $(this).attr('action');
            swal({
                title: "<?php echo e(trans('messages.deletetitle')); ?>",
                text: "<?php echo e(trans('messages.areYouSure')); ?>",
                icon: 'warning',
                buttons: {
                    confirm: 'Yes, delete it',
                    cancel: 'No, cancel',
                },
                dangerMode: true,
            }).then((willDelete) => {
                if (willDelete) {
                    // If the user confirms, send the DELETE request
                    $.ajax({
                        url: formAction,
                        type: 'DELETE',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        success: function(response) {
                            var alertType = response['alert-type'];
                            var message = response['message'];
                            var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                            showToaster(title, alertType, message);
                            DataaTable.ajax.reload();
                        },
                        error: function(xhr) {
                            // Handle error response
                            swal("<?php echo e(trans('quickadmin.users.users')); ?>", 'Something Went Wrong!', 'error');
                        }
                    });
                }
            });
        });

        // rejoin or restore
        $(document).on('click', '.rejoin-users-btn', function(e) {
            e.preventDefault();
            console.log(2);
            var formAction = $(this).data('href');
            swal({
                title: "<?php echo e(trans('messages.rejointitle')); ?>",
                text: "<?php echo e(trans('messages.areYouSurerejoin')); ?>",
                icon: 'warning',
                buttons: {
                    confirm: 'Yes, Rejoin Staff',
                    cancel: 'No, cancel',
                },
                dangerMode: true,
            }).then((willDelete) => {
                if (willDelete) {
                    $.ajax({
                        url: formAction,
                        type: 'PATCH',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        success: function(response) {
                            var alertType = response['alert-type'];
                            var message = response['message'];
                            var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                            showToaster(title, alertType, message);
                            DataaTable.ajax.reload();
                            // location.reload();
                        },
                        error: function(xhr) {
                            // Handle error response
                            swal("<?php echo e(trans('quickadmin.order.invoice')); ?>", 'Something Went Wrong!', 'error');
                        }
                    });
                }
            });
        });

        // active inactive user
        // rejoin or restore
        $(document).on('click', '.active_inactive_user', function(e) {
            e.preventDefault();
            var active_inactive = $(this).data('active_inactive');
            var _id = $(this).data('id');
            var active_inactive_msg = "<?php echo e(trans('messages.are_you_sure_change_status')); ?>";
            if (active_inactive == "Inactive") {
                var active_inactive_msg = "<?php echo e(trans('messages.are_you_sure_change_instatus')); ?>";
            }
            swal({
                title: "<?php echo e(trans('messages.are_you_sure')); ?>",
                text: active_inactive_msg,
                icon: 'warning',
                buttons: {
                    confirm: 'Yes',
                    cancel: 'No',
                },
                dangerMode: true,
            }).then((willDelete) => {
                if (willDelete) {
                    $.ajax({                        
                        type: 'POST',
                        url: "<?php echo e(route('user_status_change')); ?>",
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        data: {
                            active_inactive: active_inactive,
                            _id: _id
                        },
                        success: function(response) {
                            var alertType = response['alert-type'];
                            var message = 'Status Successfully changed';
                            var title = "<?php echo e(trans('quickadmin.users.users')); ?>";
                            showToaster(title, alertType, message);
                            DataaTable.ajax.reload();
                        },
                        error: function(xhr) {
                            swal("<?php echo e(trans('quickadmin.users.users')); ?>", 'Something Went Wrong!', 'error');
                        }
                    });
                }
            });
        });
        // active inactive user

        $(document).on('keypress', '#name', function(event) {
            var keyCode = event.keyCode || event.which;
            var inputValue = $(this).val();
            if (keyCode === 32) {
                if (inputValue.slice(-1) === ' ') {
                    event.preventDefault();
                }
            }
        });

    });

    function ChangeEyeIcon(em, id) {
        em.toggleClass("fa-eye fa-eye-slash");
        var input = $("#" + id);
        if (input.attr("type") === "password") {
            input.attr("type", "text");
        } else {
            input.attr("type", "password");
        }
    }
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/hipldemo2/public_html/billing-software.hipl-staging2.com/resources/views/admin/staff/index.blade.php ENDPATH**/ ?>