<?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(); ?>

<form method="POST"
    action="<?php echo e(route("projets.update_statuts", $projet->id ?? '')); ?>">
    <?php echo csrf_field(); ?>
    <?php echo e(method_field('PUT')); ?>


    <?php if(sizeof($projet->statuts) > 0): ?>

        <div class="row">
            <div class="col-12">
                <table id="tableStatus" class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Responsable</th>
                            <th>Fonction</th>
                            <th>Date modification</th>
                            <th>Message</th>
                            <th>Statut</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $projet->statuts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($s['user_prenom']); ?>

                                    <?php echo e($s['user_nom']); ?>

                                </td>
                                <td><?php echo e(App\Models\User::get_nom_role_static($s['fonction'], true)); ?></td>
                                
                                <td><?php echo e($s['updated_at'] ? Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $s['updated_at'])->format('d/m/Y') : null); ?></td>
                                <td><?php echo e($s['message']); ?></td>
                                <td>
                                    <img alt="Statut : <?php echo e($s['nom']); ?>" class=""
                                        src="<?php echo e(URL::to('img/statuts/')); ?>/<?php echo e($s['icon']); ?>" />
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>

    <?php else: ?>
        <div class="pt-2">
            <h4>Pas de données disponible.</h4>
        </div>
    <?php endif; ?>

    <div class="row">
        <div class="col-12">
            <div class="form-group text-right">
                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->any(["suspendre_acheteur",
                        "abandonner_acheteur",
                        "soumettre_acheteur",
                        "valider_responsable_achat",
                        "rejeter_responsable_achat",
                        "rejeter_chef_projet",
                        "valider_chef_projet",
                        "cloturer_chef_projet",
                        "avis_projet_controleur_gestion",
                        "rejeter_directeur_achat",
                        "valider_directeur_achatavis_projet_controleur_gestion"])): ?>
                    <?php if($editable): ?>
                        <button type="button" class="btn btn-outline-info" data-toggle="modal"
                            data-target="#modalStatutProjet">
                            Modifier le statut
                        </button>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="modalStatutProjet" tabindex="-1" aria-labelledby="modalStatutProjetLabel"
        aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Avis sur le projet</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="message">Commentaire</label>
                        <textarea class="form-control" name="message" rows="3" maxlength="255"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-outline-warning mr-auto" data-dismiss="modal">Annuler</button>
                    <?php if($editable): ?>
                        
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("suspendre_acheteur")): ?>
                        <button type="submit" class="btn btn-outline-warning" name="statut_id"
                            value="<?php echo e(PROJET_STATUT::SUSPENDUE); ?>">Suspendre</button>
                        <?php endif; ?>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("abandonner_acheteur")): ?>
                            <button type="submit" class="btn btn-outline-danger" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::ABANDONNEE); ?>">Abandonner</button>
                        <?php endif; ?>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("soumettre_acheteur")): ?>
                            <button type="submit" class="btn btn-outline-success" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::SOUMISE); ?>">Soumettre</button>
                        <?php endif; ?>

                        
                        <?php if($projet['statut'] !== PROJET_STATUT::REJETEE_RESPONSABLE_ACHAT): ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("valider_responsable_achat")): ?>
                                <button type="submit" class="btn btn-outline-success" name="statut_id"
                                    value="<?php echo e(PROJET_STATUT::VALIDEE_RESPONSABLE_ACHAT); ?>">Valider</button>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("rejeter_responsable_achat")): ?>
                                <button type="submit" class="btn btn-outline-danger" name="statut_id"
                                    value="<?php echo e(PROJET_STATUT::REJETEE_RESPONSABLE_ACHAT); ?>">Rejeter</button>
                            <?php endif; ?>
                        <?php else: ?>
                            <div class="alert alert-info text-left">
                                <i class="fa fa-info-circle"></i>
                                L'action a été rejetée par le chef de projet achat. L'acheteur doit modifier sa demande.
                            </div>
                        <?php endif; ?>

                        
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("rejeter_chef_projet")): ?>
                            <button type="submit" class="btn btn-outline-danger" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::REJETEE_CHEF_PROJET); ?>">Rejeter</button>
                        <?php endif; ?>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("valider_chef_projet")): ?>
                            <button type="submit" class="btn btn-outline-primary" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::VALIDEE_CHEF_PROJET); ?>">Valider</button>
                        <?php endif; ?>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("cloturer_chef_projet")): ?>
                            <button type="submit" class="btn btn-outline-success" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::CLOTUREE); ?>">Clôturer</button>
                        <?php endif; ?>

                        
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("avis_projet_controleur_gestion")): ?>
                            <button type="submit" class="btn btn-outline-danger" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::AVIS_DEFAVORABLE_CONTROLEUR); ?>">Défavorable</button>
                            <button type="submit" class="btn btn-outline-success" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::AVIS_FAVORABLE_CONTROLEUR); ?>">Favorable</button>
                        <?php endif; ?>

                        
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("rejeter_directeur_achat")): ?>
                            <button type="submit" class="btn btn-outline-danger" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::REJETEE_RESPONSABLE_ACHAT); ?>">Rejeter</button>
                        <?php endif; ?>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("valider_directeur_achat")): ?>
                            <button type="submit" class="btn btn-outline-success" name="statut_id"
                                value="<?php echo e(PROJET_STATUT::VALIDEE_RESPONSABLE_ACHAT); ?>">Valider</button>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</form>
<?php /**PATH /var/www/html/resources/views/projets/form/onglets/statut.blade.php ENDPATH**/ ?>