

<?php $__env->startSection('content'); ?>

<?php if(count($errors) > 0): ?>
<div class="alert alert-danger">
    <?php $__currentLoopData = $errors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <ul>
        <li><?php echo e($error); ?></li>
    </ul>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>
<?php endif; ?>

<?php if(session('contact_delete_msg')): ?>
<div class="alert alert-success">
    <?php echo e(session('contact_delete_msg')); ?>

</div>
<?php endif; ?>


<div class="card shadow mb-4">
    <div class="card-header py-3">
        <h3 class="mb-3"> <?php echo e(awtTrans('الرسايل الغير مقروءة')); ?> </h3>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-striped" id="dataTableContacts" width="100%" cellspacing="0">
                <thead>
                    <tr>
                        <th><?php echo e(awtTrans('Delete')); ?></th>
                        <th><?php echo e(awtTrans('Sender')); ?></th>
                        <th><?php echo e(awtTrans('Email')); ?></th>
                        <th><?php echo e(awtTrans('Phone')); ?></th>
                        <th><?php echo e(awtTrans('Message')); ?></th>
                        <th><?php echo e(awtTrans('Actions')); ?></th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th><?php echo e(awtTrans('Delete')); ?></th>
                        <th><?php echo e(awtTrans('Sender')); ?></th>
                        <th><?php echo e(awtTrans('Email')); ?></th>
                        <th><?php echo e(awtTrans('Phone')); ?></th>
                        <th><?php echo e(awtTrans('Message')); ?></th>
                        <th><?php echo e(awtTrans('Actions')); ?></th>
                    </tr>
                </tfoot>
                <tbody>
                    <?php if(!empty($contacts)): ?>
                    <?php $__currentLoopData = $contacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $contact): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e($contact->id); ?></td>
                        <td>
                            <Strong><?php echo e($contact->name); ?></Strong>
                        </td>
                        <td>
                            <small><a href="mailto:<?php echo e($contact->email); ?>"><?php echo e($contact->email); ?></a></small>
                        </td>
                        <td>
                            <small><a href="tel:<?php echo e($contact->phone); ?>"><?php echo e($contact->phone); ?></a></small>
                        </td>
                        <td>
                            <div class="mb-2"><?php echo e($contact->message); ?></div>
                            <small class=""><em><?php echo e(awtTrans('Time And Date')); ?>: <?php echo e($contact->created_at); ?></em></small>

                            <a href="javascript:void(0)" class="contact-read contact-read-<?php echo e($contact->id); ?> text-decoration-none ml-2 <?php echo e($contact->read == 1 ? 'd-none' : ''); ?>" data-id="<?php echo e($contact->id); ?>"><?php echo e(awtTrans('Mark as read')); ?> <i class="far fa-check-circle fa-sm"></i></a>
                            <a href="javascript:void(0)" class="contact-unread contact-unread-<?php echo e($contact->id); ?> text-decoration-none ml-2 text-danger <?php echo e($contact->read == 0 ? 'd-none' : ''); ?>" data-id="<?php echo e($contact->id); ?>"><?php echo e(awtTrans('Mark as read')); ?> <i class="far fa-times-circle fa-sm"></i></a>
                        </td>
                        <td>
                            <a href=" <?php echo e(route('admin.contacts.destroy', $contact->id)); ?>" data-id="<?php echo e($contact->id); ?>" class="btn btn-danger btn-circle btn-sm item-delete">
                                <i class="fas fa-trash"></i>
                            </a>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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



<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function() {
        $('#dataTableContacts').DataTable({
            order: [0, 'desc'],
            'language': {
                'url': "<?php echo e(app()->getLocale() == 'ar' ? 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/Arabic.json' : 'https://cdn.datatables.net/plug-ins/1.10.12/i18n/English.json'); ?>",
            },
        });
    });


    $('.contact-read').click(function() {
        var contactId = $(this).data('id');
        var url = '/admin/contacts/' + contactId;
        axios.put(url, {
                read: 1,
            })
            .then(res => {
                if (res.status == 200) {
                    if (res.data == 1) {
                        $('.contact-read-' + contactId).addClass('d-none');
                        $('.contact-unread-' + contactId).removeClass('d-none');

                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'top-start',
                            showConfirmButton: false,
                            timer: 4000,
                            timerProgressBar: true,
                            didOpen: (toast) => {
                                toast.addEventListener('mouseenter', Swal.stopTimer)
                                toast.addEventListener('mouseleave', Swal.resumeTimer)
                            }
                        })

                        Toast.fire({
                            icon: 'success',
                            title: "<?php echo e(awtTrans('تم القراءة')); ?>"
                        })

                    } else {
                        toastr.error('Update failed');
                    }
                } else {
                    toastr.error('Update failed');
                }
            })
            .catch(err => {
                toastr.error(err);
            })
    });

    $('.contact-unread').click(function() {
        var contactId = $(this).data('id');
        var url = '/admin/contacts/' + contactId;
        axios.put(url, {
                read: 0,
            })
            .then(res => {
                if (res.status == 200) {
                    if (res.data == 1) {
                        $('.contact-unread-' + contactId).addClass('d-none');
                        $('.contact-read-' + contactId).removeClass('d-none');

                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'top-start',
                            showConfirmButton: false,
                            timer: 4000,
                            timerProgressBar: true,
                            didOpen: (toast) => {
                                toast.addEventListener('mouseenter', Swal.stopTimer)
                                toast.addEventListener('mouseleave', Swal.resumeTimer)
                            }
                        })

                        Toast.fire({
                            icon: 'success',
                            title: "<?php echo e(awtTrans('تم إلغاء القراءة')); ?>"
                        })

                    } else {
                        toastr.error('Update failed');
                    }
                } else {
                    toastr.error('Update failed');
                }
            })
            .catch(err => {
                toastr.error(err);
            })
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/sitejadara/public_html/ics/resources/views/admin/contacts/unread-contacts.blade.php ENDPATH**/ ?>