<?php $__env->startSection('main-content'); ?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>Manage Book</h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Tables</a></li>
            <li class="active">Simple</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- /.row -->
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">
                    <a id="activeAllStatus" url="<?php echo e(route('book.statusActive')); ?>" class="btn btn-danger btn-xm"><i class="fa fa-eye"></i></a>
                    <a id="deactiveAllStatus" url="<?php echo e(route('book.statusDeactive')); ?>" class="btn btn-danger btn-xm"><i class="fa fa-eye-slash"></i></a>
                    <a id="deleteAll" url="<?php echo e(route('book.deleteAll')); ?>" class="btn btn-danger btn-xm"><i class="fa fa-trash"></i></a>
                    <a href="/admin/book/create" class="btn btn-default btn-xm"><i class="fa fa-plus"></i></a>
                </h3>
                <div class="box-tools">
                    <div class="input-group input-group-sm" style="width: 250px;">
                        <input type="text" name="table_search" class="form-control pull-right" placeholder="Search">

                        <div class="input-group-btn">
                            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <?php if($books): ?>
            <div class="box-body">
                <table class="table table-bordered">
                    <thead style="background-color: #F8F8F8;">
                        <tr>
                            <th width="4%"><input type="checkbox" name="" id="checkAll"></th>
                            <th width="25%">Title</th>
                            <th width="15%">Author</th>
                            <th width="15%">Category</th>
                            <th width="20%">Book Image</th>
                            <th width="10%">Status</th>
                            <th width="10%">Manage</th>
                        </tr>
                    </thead>
                    <?php $__currentLoopData = $books; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $book): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><input type="checkbox" name="statusAll[]" value="<?php echo e($book->id); ?>" id="" class="checkSingle"></td>
                        <td><?php echo e($book->title); ?></td>
                        <td><?php echo e($book->publisher); ?></td>
                        <td><?php echo e($book->category_id); ?></td>
                        <td><?php echo e($book->book_img); ?></td>
                        <td>
                            <form name="status" method="post" action="/admin/book/<?php echo e($book->id); ?>/status" id="status">
                                <?php echo csrf_field(); ?>
                                <?php echo e(method_field('put')); ?>

                                <?php if($book->status=="DEACTIVE"): ?>
                                <button class="btn btn-danger btn-sm singleStatus"><i class="fa fa-thumbs-down"></i></button>
                                <?php else: ?>
                                <button class="btn btn-success btn-sm singleStatus"><i class="fa fa-thumbs-up"></i></button>
                                <?php endif; ?>
                            </form>
                        </td>
                        <td>
                            <form name="destroyBook" id="destroyBook" method="post" action="/admin/book/<?php echo e($book->id); ?>">
                                <?php echo e(method_field('delete')); ?>

                                <?php echo csrf_field(); ?>
                                <a href="/admin/book/<?php echo e($book->id); ?>/edit" class="btn btn-info btn-flat btn-sm"> <i class="fa fa-edit"></i></a>
                                <button class="btn btn-danger btn-flat btn-sm"> <i class="fa fa-trash-o"></i></button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                </table>
            </div>
            <!-- /.box-body -->
            <div class="box-footer clearfix">
                <div class="row">
                    <div class="col-sm-6">
                        <span style="display:block;font-size:15px;line-height:34px;margin:20px 0;">
                            Showing <?php echo e($books->firstItem()); ?> to <?php echo e($books->lastItem()); ?> of <?php echo e($books->total()); ?> entries</span>
                    </div>
                    <div class="col-sm-6 text-right">
                        <?php echo e($books->links()); ?>

                    </div>
                </div>
            </div>
            <?php else: ?>
            <div class="alert alert-danger">No record found</div>
            <?php endif; ?>
        </div>
        <!-- /.box-body -->
</div>


</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->

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

<?php $__env->startSection('ajax-scripts'); ?>
<script>
    $(document).ready(function() {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        // SINGLE STATUS UPDATE 
        $(".singleStatus").on('click', function(e) {
            e.preventDefault();
            var self = $(this);
            var url = self.closest('form').attr('action');

            $.ajax({
                    url: url,
                    type: 'PUT',
                })
                .done(function(data) {
                    self.html();
                    if (data == 'ACTIVE') {
                        self.closest('form').find('button').removeClass('btn-danger');
                        self.closest('form').find('button').addClass('btn-success');
                        self.html('<i class="fa fa-thumbs-up"></i>');
                    } else {
                        self.closest('form').find('button').removeClass('btn-success');
                        self.closest('form').find('button').addClass('btn-danger');
                        self.html('<i class="fa fa-thumbs-down"></i>');
                    }
                })
                .fail(function() {
                    alert("Opps! something went wrong");
                })
        });

        // ACTIVE ALL STATUS UPDATE.
        $("#activeAllStatus").on('click', function(e) {
            e.preventDefault();
            $('tbody').addClass('table-loader');
            var statusAllValue = [];

            $("input[name='statusAll[]']:checked").each(function() {
                statusAllValue.push($(this).val());
            });
            $.ajax({
                    url: $('#activeAllStatus').attr('url'),
                    type: 'GET',
                    data: {
                        statusAll: statusAllValue
                    },
                })
                .done(function(data) {
                    $.each(data, function(index, val) {

                        $("input[value='" + val.id + "']")
                            .closest('tr')
                            .find('.singleStatus')
                            .removeClass('btn-danger')
                            .addClass('btn-success')
                            .html('<i class="fa fa-thumbs-up"></i>');
                        $("input[name='statusAll[]']").attr('checked', false);
                        $("#checkAll").attr('checked', false);
                    });
                })
                .always(function() {
                    $('tbody').removeClass('table-loader');
                });
        });

        // DEACTIVE ALL STATUS UPDATE.

        $("#deactiveAllStatus").on('click', function(e) {
            e.preventDefault();
            $('tbody').addClass('table-loader');
            var statusAllValue = [];

            $("input[name='statusAll[]']:checked").each(function() {
                statusAllValue.push($(this).val());
            });
            $.ajax({
                    url: $('#deactiveAllStatus').attr('url'),
                    type: 'GET',
                    data: {
                        statusAll: statusAllValue
                    },
                })
                .done(function(data) {
                    $.each(data, function(index, val) {

                        $("input[value='" + val.id + "']")
                            .closest('tr')
                            .find('.singleStatus')
                            .removeClass('btn-success')
                            .addClass('btn-danger')
                            .html('<i class="fa fa-thumbs-down"></i>');
                        $("input[name='statusAll[]']").attr('checked', false);
                        $("#checkAll").attr('checked', false);
                    });
                })
                .always(function() {
                    $('tbody').removeClass('table-loader');
                });
        });

        // DELETE ALL RECORD.

        $("#deleteAll").on('click', function(e) {
            e.preventDefault();
            $('tbody').addClass('table-loader');

            var statusAllValue = [];

            $("input[name='statusAll[]']:checked").each(function() {
                statusAllValue.push($(this).val());
            });
            $.ajax({
                    url: $('#deleteAll').attr('url'),
                    type: 'GET',
                    data: {
                        statusAll: statusAllValue
                    },
                })
                .done(function(data) {
                    location.reload(true);
                })
                .always(function() {
                    $('tbody').removeClass('table-loader');
                });
        });




    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layout.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\mustafalaravel\resources\views/admin/book/index.blade.php ENDPATH**/ ?>