<?php $__env->startSection('content'); ?>
    <div class="container">
        <div>
            <h2 class="pb-2">Utilisateurs
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('add_parametre')): ?>
                    <a class="btn btn-outline-success float-right mb-4" href="<?php echo e(route('utilisateurs.create')); ?>">Ajouter</a>
                <?php endif; ?>
            </h2>
        </div>

        <?php echo $__env->make('layouts.commons.errors', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php echo $__env->make('layouts.commons.success', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

        
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th class="align-middle">ID</th>
                    <th class="align-middle">Nom</th>
                    <th class="align-middle">Portefeuille achats</th>
                    <th class="align-middle">Établissement</th>
                    <th class="align-middle">Service</th>
                    <th class="align-middle">Groupe</th>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->any(array('edit_utilisateur', 'delete_utilisateur'))): ?>
                        <th class="align-middle">Statut</th>
                        <th class="align-middle">Actions</th>
                    <?php endif; ?>
                </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($u->id); ?></td>
                    <td>
                        <?php echo e($u->nom_complet()); ?>

                        <br>
                        <small><?php echo e($u->email); ?></small>
                    </td>
                    <td>
                        <?php if(!app()->environment('local')): ?>
                            <?php if($u->hasAnyRole([ROLE::ACHETEUR, ROLE::EQUIPE_PROJET])): ?>
                                <?php echo e($u->portefeuille_acheteur->nom); ?>

                            <?php elseif($u->hasRole(ROLE::RESPONSABLE_ACHAT)): ?>
                                <?php echo e($u->portefeuille_responsable->nom); ?>

                            <?php else: ?>
                                -
                            <?php endif; ?>
                        <?php else: ?>
                            -
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if(isset($u->direction)): ?> <?php echo e($u->direction->nom); ?> <?php else: ?> - <?php endif; ?>
                    </td>
                    <td>
                        <?php if(isset($u->service)): ?> <?php echo e($u->service->nom); ?> <?php else: ?> - <?php endif; ?>
                    </td>
                    <td><?php echo e($u->nom_role(true)); ?></td>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->any(array('edit_utilisateur', 'delete_utilisateur'))): ?>
                        <td>
                            <?php if($u->id != Auth::user()->getAuthIdentifier()): ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit_utilisateur')): ?>
                                    <form class="inline-form-table" action="<?php echo e(route('utilisateurs.active', $u->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <?php echo e(method_field('PUT')); ?>

                                        <?php if($u->active): ?>
                                            <button type="submit" class="btn btn-success" 
                                                data-toggle="tooltip" data-placement="top" title="Désactiver">
                                                <i class="fas fa-toggle-on"></i>
                                            </button>
                                        <?php else: ?>
                                            <button type="submit" class="btn btn-secondary"
                                            data-toggle="tooltip" data-placement="top" title="Activer">
                                                <i class="fas fa-toggle-off"></i>
                                            </button>
                                        <?php endif; ?>
                                    </form>
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                        <td style="width: 10%">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit_utilisateur')): ?>
                                <a class="btn btn-outline-primary" href="<?php echo e(route('utilisateurs.edit', $u->id)); ?>" 
                                    data-toggle="tooltip" data-placement="top" title="Editer">
                                    <i class="fas fa-pencil-alt"></i>
                                </a>
                            <?php endif; ?>
                            <?php if($u->id != Auth::user()->getAuthIdentifier()): ?>
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete_utilisateur')): ?>
                                    <form class="inline-form-table" action="<?php echo e(route('utilisateurs.destroy', $u->id)); ?>" method="POST">
                                        <?php echo csrf_field(); ?>
                                        <?php echo e(method_field('DELETE')); ?>

                                        <button type="submit" class="btn btn-outline-danger"
                                            data-toggle="tooltip" data-placement="top" title="Supprimer">
                                            <i class="fas fa-trash-alt"></i>
                                        </button>
                                    </form>
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                    <?php endif; ?>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>

        <?php echo e($users->links("pagination::bootstrap-4")); ?>

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

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/resources/views/utilisateurs/index.blade.php ENDPATH**/ ?>