<?php echo $__env->make('admin/partial/header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.1/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.3/css/select.dataTables.min.css">
<style>
    .dataTables_scrollHeadInner {
        width: auto !important;
    }

    .btn-icon {
        background: #fff;
    }

    .btn-icon .bx {
        font-size: 20px;
    }

    .btn .bx {
        vertical-align: middle;
        font-size: 20px;
    }

    .dropdown-menu {
        padding: 0.25rem 0;
    }

    .dropdown-item {
        padding: 0.5rem 1rem;
    }

    .throwout {
        position: absolute !important;
        right: 2000px !important;
    }

    .wide {
        width: 12.1% !important;
    }

</style>
<!-- start page container -->
<div class="page-container">
    <div class="loading" style="display:none;">Loading&#8230;</div>
    <!-- start sidebar menu -->
    <?php echo $__env->make('admin/partial/nav', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <!-- end sidebar menu -->
    <!-- start page content -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="page-bar">
                <div class="page-title-breadcrumb">
                    <div class=" pull-left">
                        <div class="page-title">Staff List</div>
                    </div>
                    <?php echo $__env->make('admin/partial/sub', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                    <!-- <ol class="breadcrumb page-breadcrumb pull-right">
                                <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="index.html">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                                </li>
                                <li class="active">All Staff</li>
                            </ol> -->
                </div>
            </div>


            <center><img id="gif" src="https://createwebsite.net/wp-content/uploads/2015/09/Display-Loading.gif"
                    width="25%" class="gif"></center>

            <div class="row">
                <div class="col-md-12">
                    <div class="card card-topline-purple throwout" id="cardwrappers">
                        <div class="card-body ">

                            <div id="example3_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4">

                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="dataTables_scroll">

                                            <div class="dataTables_scrollBody"
                                                style="position: relative; overflow: auto; width: 100%;">
                                                <table id="staff_multitable" class="display full-width dataTable"
                                                    role="grid" aria-describedby="example3_info" style="width: 909px;">
                                                    <thead>
                                                        <tr role="row" style="height: 0px;">
                                                            <th class="sorting_asc" id="thisth"
                                                                aria-controls="example3" style=""
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                Staff id
                                                            </th>
                                                            <th class="sorting_asc" id="thisth"
                                                                aria-controls="example3" style=""
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                Hirer Name
                                                            </th>
                                                            <th class="sorting_asc" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                First Name
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 2: activate to sort column ascending">
                                                                Last Name
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 3: activate to sort column ascending">
                                                                Phone Number
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 4: activate to sort column ascending">
                                                                Email
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Employee Number
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Status
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Options
                                                            </th>

                                                        </tr>
                                                    </thead>
                                                    <tbody>

                                                        <?php $__currentLoopData = $allstaff; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $staff): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                            <?php $query = DB::table('agencies')
                                                                ->where('id', $staff->agency_id)
                                                                ->first(); ?>
                                                            <tr role="row" class="odd">
                                                                <td><?php echo e($staff->id); ?></td>
                                                                <?php if($query): ?>
                                                                    <td><?php echo e($query->company_re_name); ?></td>
                                                                <?php else: ?>
                                                                    <td>N/A</td>
                                                                <?php endif; ?>
                                                                <td><?php echo e($staff->first_name); ?></td>
                                                                <td><?php echo e($staff->last_name); ?></td>
                                                                <td><?php echo e($staff->phone_no); ?></td>
                                                                <td><?php echo e($staff->email); ?></td>
                                                                <td><?php echo e($staff->emp_no); ?></td>
                                                                <td>

                                                                    <?php if($staff->status == 1): ?>
                                                                        <span style="color:green">
                                                                            Active
                                                                        </span>
                                                                    <?php else: ?>
                                                                        <span style="color:red">
                                                                            Not active
                                                                        </span>
                                                                    <?php endif; ?>

                                                                </td>
                                                                <td>

                                                                    <div class="dropdown">

                                                                        <button class="btn btn-sm btn-icon"
                                                                            type="button" id="dropdownMenuButton2"
                                                                            data-toggle="dropdown" aria-haspopup="true"
                                                                            aria-expanded="false">
                                                                            <i class="fa fa-ellipsis-h"
                                                                                data-toggle="tooltip"
                                                                                data-placement="top"
                                                                                title="Actions"></i>
                                                                        </button>
                                                                        <div class="dropdown-menu"
                                                                            aria-labelledby="dropdownMenuButton2">
                                                                            <a href="<?php echo e(url('editstaff')); ?>/<?php echo e(Crypt::encrypt($staff->id)); ?>"
                                                                                class="dropdown-item">
                                                                                <i class="fa fa-pencil mr-2"></i>Edit
                                                                            </a>
                                                                            <a href="#" id="<?php echo e($staff->id); ?>"
                                                                                onclick="Delete(this.id)"
                                                                                class="dropdown-item">
                                                                                <i class="fa fa-trash-o mr-2"></i>
                                                                                Delete
                                                                            </a>
                                                                            <?php if($staff->status == 1): ?>
                                                                                <a href="<?php echo e(url('deactivatestaff')); ?>/<?php echo e(Crypt::encrypt($staff->id)); ?>"
                                                                                    class="dropdown-item">
                                                                                    <i
                                                                                        class="fa fa-ban mr-2"></i>Deactivate
                                                                                </a>
                                                                            <?php else: ?>
                                                                                <a href="<?php echo e(url('activatestaff')); ?>/<?php echo e(Crypt::encrypt($staff->id)); ?>"
                                                                                    class="dropdown-item">
                                                                                    <i
                                                                                        class="fa fa-check mr-2"></i>Activate
                                                                                </a>
                                                                            <?php endif; ?>

                                                                </td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </tbody>
                                                    <tfoot>
                                                        <tr style="height: 0px;">
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 158.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 1</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 164.028px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 2</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 166.25px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 3</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 4</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 5</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 6</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 7</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 8</div>
                                                            </th>
                                                            <th rowspan="1" colspan="1"
                                                                style="padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px; width: 168.472px;">
                                                                <div class="dataTables_sizing"
                                                                    style="height:0;overflow:hidden;">Column 9</div>
                                                            </th>
                                                        </tr>
                                                    </tfoot>

                                                </table>
                                            </div>

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

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

        </div>

    </div>
    <!-- end page content -->

</div>
<!-- end page container -->

<?php echo $__env->make('admin/partial/footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var myTable = $('#staff_multitable').DataTable({
            // "serverSide": true,
            // "ajax":{
            //          "url": "<?php echo e(url('datatable_allstaff')); ?>",
            //          "dataType": "json",
            //          "type": "POST",
            //          "data":{ _token: "<?php echo e(csrf_token()); ?>"}
            //        },
            // "columns": [
            //     { "data": "id" },
            //     { "data": "hirer_name" },
            //     { "data": "first_name" },
            //     { "data": "last_name" },
            //     { "data": "phone_no" },
            //     { "data": "email" },
            //     { "data": "emp_no" },
            //     { "data": "status" },
            // ],
            processing: true,
            language: {
                processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i>Processing...'
            },
            select: {
                style: 'multi'
            }
        });

        // add button
        $('#add').click(function() {
            window.location.href = '<?php echo route('addstaff'); ?>';
        });

        // edit button
        $('#edit').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention",
                    text: "Please first select an item to edit it!",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            if (myTable.rows({
                    selected: true
                }).count() > 1) {
                return swal("Please only select one item to edit!");
            }
            if (myTable.rows({
                    selected: true
                }).count() == 1) {
                var id = myTable.rows({
                    selected: true
                }).data()[0][0];

                $.ajax({
                    type: "GET",
                    url: 'CryptedHash/' + id,
                    success: function(hash) {
                        window.location.href = 'editstaff/' + hash;
                    },
                    error: function(err) {
                        window.location.reload();
                    }
                });

            }

        });


        // delete button
        $('#delete').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an item to delete",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            swal({
                    title: "Are you sure?",
                    text: "Once deleted, you will not be able to recover this record!",
                    icon: "warning",
                    buttons: true,
                    dangerMode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $('.loading').show();
                        const ID = [];
                        const selectedRows = myTable.rows({
                            selected: true
                        }).data().toArray();
                        for (var i = 0; i < selectedRows.length; i++) {
                            ID.push(Number(selectedRows[i][0]));
                        }
                        $.ajax({
                            type: "POST",
                            url: 'Deletestaffbulk',
                            data: {
                                ids: ID,
                                _token: "<?php echo e(csrf_token()); ?>"
                            },
                            success: function(data) {
                                if (data.status == 200) {
                                    window.location.reload();
                                }
                            }
                        });
                    } else {
                        swal("Your Data is safe!");
                    }
                });
        });
        // delete button
        $('#activate').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an record to activate",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            $('.loading').show();
            const ID = [];
            const selectedRows = myTable.rows({
                selected: true
            }).data().toArray();
            for (var i = 0; i < selectedRows.length; i++) {
                ID.push(Number(selectedRows[i][0]));
            }
            // console.log("ID");
            // console.log(ID);
            $.ajax({
                type: "POST",
                url: 'activatestaffbulk',
                data: {
                    ids: ID,
                    _token: "<?php echo e(csrf_token()); ?>"
                },
                success: function(data) {
                    if (data.status == 200) {
                        window.location.reload();
                    }
                }
            });
        });
        // delete button
        $('#suspend').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an record to suspend",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            $('.loading').show();
            const ID = [];
            const selectedRows = myTable.rows({
                selected: true
            }).data().toArray();
            for (var i = 0; i < selectedRows.length; i++) {
                ID.push(Number(selectedRows[i][0]));
            }
            $.ajax({
                type: "POST",
                url: 'deactivatestaffbulk',
                data: {
                    ids: ID,
                    _token: "<?php echo e(csrf_token()); ?>"
                },
                success: function(data) {
                    if (data.status == 200) {
                        window.location.reload();
                    }
                }
            });
        });

        // select all button
        $('#selectAll').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() > 0) {
                return;
            }

            myTable.rows().select();
        });

        // deselect all button
        $('#deselectAll').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return;
            }

            myTable.rows().deselect();
        });



    });

    function Delete(ID) {
        swal({
                title: "Are you sure?",
                text: "Once deleted, you will not be able to recover this record!",
                icon: "warning",
                buttons: true,
                dangerMode: true,
            })
            .then((willDelete) => {
                if (willDelete) {
                    window.location.href = '<?php echo url('Deletestaff'); ?>/' + ID;
                } else {
                    swal("Your Data is safe!");
                }
            });

    }
</script>
<script>
    // $('#tbody').toggleClass('hide');
    $("#cardwrappers").ready(() => {
        $('#gif').toggle();
        $('#cardwrappers').toggleClass('throwout');
        $('#thisth').toggleClass('wide');

    })
</script>
