<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-md-12 p-3">
            <div class="card card-outline card-primary">
                <div class="card-header">
                    Subscribed Clients
                </div>

                <div class="card-body">
                    <table class="table w-100 table-striped" id="subscribers_table">
                        <thead class="bg-gradient-primary">
                            <th>S/N</th>
                            <th>Email Address</th>
                            <th>Joined Date</th>
                            <th>Status</th>
                            <th>Action</th>     
                        </thead>

                        <tbody>
                            <?php $__currentLoopData = $subscribers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <tr>
                                    <td><?php echo e($loop->index+1); ?></td>
                                    <td><?php echo e($item->email); ?></td>
                                    <td><?php echo e(Carbon\Carbon::parse($item->created_at)->format('d-m-Y H:i:s')); ?></td>
                                    <td><?php echo e($item->status); ?></td>
                                    <td>
                                        <?php if($item->status == "unchecked" || $item->status == "blocked"): ?>
                                            <button class="approve btn btn-sm bg-gradient-primary" id="<?php echo e($item->id); ?>"><i class="fas fa-fw fa-check-circle"></i></button>&nbsp;&nbsp;
                                        <?php else: ?>
                                            <button class="disabled btn btn-sm bg-gradient-primary" id="<?php echo e($item->id); ?>"><i class="fas fa-fw fa-check-circle"></i></button>&nbsp;&nbsp;
                                        <?php endif; ?>

                                        <?php if($item->status == "active"): ?>
                                            <button class="block btn btn-sm bg-gradient-warning" id="<?php echo e($item->id); ?>"><i class="fas fa-fw fa-ban"></i></button>&nbsp;&nbsp;
                                        <?php else: ?>
                                            <button class="disabled btn btn-sm bg-gradient-warning" id="<?php echo e($item->id); ?>"><i class="fas fa-fw fa-ban"></i></button>&nbsp;&nbsp;
                                        <?php endif; ?>
                                        <button class="delete btn btn-sm bg-gradient-danger" id="<?php echo e($item->id); ?>"><i class="fas fa-fw fa-trash"></i></button>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                   
                </div>
            </div>
        </div>
    </div>

    <script>
        $("document").ready(function(){
            //datatables
            $('#subscribers_table').DataTable({
                responsive:true,
                processing:true,
                serverSide:false,
                stateSave: true,

                order: [
                    [0,'asc'],
                ],
            })

            //approve
            $(document).on('click', '.approve', function (event) {
                event.preventDefault();
                var approve_id = $(this).attr('id');

                Swal.fire({
                    title: "Are you sure?",
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonText: 'Yes, approve it!',
                    cancelButtonText: "No, Don't"

                }).then((approve) => {
                    if (approve.value) {

                        $.ajax({
                            url: "/subscribed/approve/" + approve_id,
                            success: function (data) {

                                //alerting
                                if(data.success){
                                        var result = data.success;
                                        Swal.fire({
                                        title: 'Approved!',
                                        text: result,
                                        icon: 'success',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    });

                                     //refreshing page
                                    setTimeout(function () {
                                        window.location = "<?php echo e(url('subscribed')); ?>";
                                    }, 2000);
                                }

                                if(data.errors){
                                    var result = data.success;
                                        Swal.fire({
                                        title: 'Info!',
                                        text: result,
                                        icon: 'warning',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    }); 
                                }
    
                            }

                        });

                    } else if (result.dismiss === Swal.DismissReason.cancel) {
                        Swal.fire({
                            title: 'Information!',
                            text: 'Email is not Approved.',
                            type: 'info',
                            icon: 'info',
                            timer: 2000,
                            showCancelButton: false,
                            showConfirmButton: false,
                        })
                    }
                })

            });

            //deletion
            $(document).on('click', '.delete', function (event) {
                event.preventDefault();
                var delete_id = $(this).attr('id');

                Swal.fire({
                    title: "Are you sure?",
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonText: 'Yes, delete it!',
                    cancelButtonText: 'No, keep it'

                }).then((result) => {
                    if (result.value) {

                        $.ajax({
                            url: "/subscribed/destroy/" + delete_id,
                            success: function (data) {

                                if(data.success){
                                     //alerting
                                     var result =data.success;
                                    Swal.fire({
                                        title: 'Deleted!',
                                        text: result,
                                        icon: 'success',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    });

                                     //refreshing page
                                    setTimeout(function () {
                                        window.location = "<?php echo e(url('subscribed')); ?>";
                                    }, 2000);
                                }

                                if(data.errors){

                                    var result = data.errors;
                                    Swal.fire({
                                        title: 'Notification!',
                                        text: result,
                                        icon: 'warning',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    });
                                }
                            }

                        });

                    } else if (result.dismiss === Swal.DismissReason.cancel) {
                        Swal.fire({
                            title: 'Information!',
                            text: 'User Data is Safe.',
                            icon: 'info',
                            timer: 2000,
                            showCancelButton: false,
                            showConfirmButton: false,
                        })
                    }
                })

            });

            //blocking
            $(document).on('click', '.block', function (event) {
                event.preventDefault();
                var block_id = $(this).attr('id');

                Swal.fire({
                    title: "Are you sure?",
                    text: "You won't be able to revert this!",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonText: 'Yes, Block Email!',
                    cancelButtonText: 'No, keep it'

                }).then((block) => {
                    if (block.value) {

                        $.ajax({
                            url: "/subscribed/block/" + block_id,
                            success: function (data) {

                                if(data.success){
                                     //alerting
                                     var result =data.success;
                                    Swal.fire({
                                        title: 'blocked!',
                                        text: result,
                                        icon: 'success',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    });

                                     //refreshing page
                                    setTimeout(function () {
                                        window.location = "<?php echo e(url('subscribed')); ?>";
                                    }, 2000);
                                }

                                if(data.errors){

                                    var result = data.errors;
                                    Swal.fire({
                                        title: 'Notification!',
                                        text: result,
                                        icon: 'warning',
                                        showCancelButton: false,
                                        showConfirmButton: false,
                                        timer: 2000,
                                    });
                                }
                            }

                        });

                    } else if (result.dismiss === Swal.DismissReason.cancel) {
                        Swal.fire({
                            title: 'Information!',
                            text: 'User Data is Safe.',
                            type: 'info',
                            icon: 'info',
                            timer: 2000,
                            showCancelButton: false,
                            showConfirmButton: false,
                        })
                    }
                })

            });
        })
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/tphaortz/public_html/tpha/resources/views/backend/subscribed.blade.php ENDPATH**/ ?>