<?php if(Auth::user()->unreadNotifications->count() === 0): ?>
    <li class="dropdown-item disabled">Aucune notification à consulter</li>
<?php else: ?>
    
    <li class="dropdown-header text-center p-0">
        <form action="<?php echo e(route('notifications.update_all')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <button type="submit" class="btn btn-link">Tout marquer comme lu</button>
        </form>
    </li>
    <li class="dropdown-divider"></li>

    <?php $__currentLoopData = Auth::user()->unreadNotifications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $notification): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <li onclick="markAsRead(<?php echo e(json_encode($notification)); ?>)">
        
        <?php if(auth()->user()->can('edit_projet') && isset($notification->data['projet_id'])): ?>
            <a class="dropdown-item" href="<?php echo e(route('projets.edit', $notification->data['projet_id'])); ?>"><?php echo e($notification->data["message"]); ?></a>
        
        <?php elseif(isset($notification->data['fichier_id'])): ?>
            <a class="dropdown-item" href="<?php echo e(route('fichiers.download_export_pdf', $notification->data['fichier_id'])); ?>"><span class="btn-link"><?php echo e($notification->data["message"]); ?></span></a>
        <?php else: ?>
            <a class="dropdown-item disabled"><?php echo e($notification->data["message"]); ?></a>
        <?php endif; ?>
        <form id="<?php echo e($notification->id); ?>" action="<?php echo e(route('notifications.update', [ $notification->id ])); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <?php echo method_field('PUT'); ?>
            <button type="submit" class="btn float-right"><span aria-hidden="true">&times;</span></button>
        </form>
        </li>
        <?php if($index !== array_key_last(Auth::user()->unreadNotifications->toArray())): ?>
            <li class="dropdown-divider"></li>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php endif; ?>

<script>
    function markAsRead(notification)
    {
        // On dénotifie si on va sur la fiche projet -> sinon l'utilisateur doit dénotifier manuellement
        if(notification['data']['projet_id'] != undefined)
        {
            $.ajax({
                url: 'notifications',
                type:'POST',
                data:{
                    notification_id: notification['id'],
                    _token: '<?php echo e(csrf_token()); ?>'
                }
            });
        }
    }
</script>
<?php /**PATH /var/www/html/resources/views/layouts/includes/notification.blade.php ENDPATH**/ ?>