<div class="row">
    <div class="col-12">

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

        <?php if(sizeof($thematiques) > 0): ?>
            <form method="post" action="<?php echo e(route('projets.update-resp-soc-env', $projet->id)); ?>">
            <?php echo csrf_field(); ?>
            <?php echo e(method_field('PUT')); ?>


            <table class="table table-responsive mt-4">
                <thead>
                    <tr>
                        <th>Thématique</th>
                        <th colspan="2">Actions</th>
                        <th>Unité d'oeuvre</th>
                        <th>Cible</th>
                        <th>Notifié</th>
                        <th>Réalisé</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $thematiques; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php if($t->actions_visibles()->count() > 0): ?>
                            <tr>
                                <td rowspan="<?php echo e($t->actions_visibles()->count() + 1); ?>"><?php echo e($t->nom); ?></td>
                            </tr>
                                <?php $__currentLoopData = $t->actions_visibles(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $a): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $is_disabled = !in_array($a->id, array_column($actions_checked, 'action_id')) || Auth::user()->cannot('edit_projet');
                                    ?>
                                    <tr>
                                        <td><?php echo e($a->nom); ?></td>
                                        <td>
                                            
                                            <input name="action_rse[]" type="checkbox" value="<?php echo e($a->id); ?>"
                                                <?php if(in_array($a->id, array_column($actions_checked, 'action_id'))): ?> checked <?php endif; ?> 
                                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->denies('edit_projet')): ?> disabled <?php endif; ?>>
                                        </td>
                                        <td>
                                            <select name="unite_oeuvre_rse[<?php echo e($a->id); ?>]" class="form-control" data-action-id="<?php echo e($a->id); ?>" <?php if($is_disabled): ?> disabled <?php endif; ?>>
                                                <?php $__currentLoopData = $actions_unite_oeuvre; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ue): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <option value="<?php echo e($ue->id); ?>" 
                                                        <?php if(!$is_disabled && old('unite_oeuvre_rse[$a->id]', $actions_checked[$a->id]['action_unite_oeuvre_id']) == $ue->id): ?>
                                                            selected
                                                        <?php endif; ?>
                                                        ><?php echo e($ue->libelle); ?></option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" data-action-id="<?php echo e($a->id); ?>" <?php if($is_disabled): ?> disabled <?php endif; ?>
                                                name="cible-rse[<?php echo e($a->id); ?>]" value="<?php echo e(!$is_disabled ? old('cible-rse[$a->id]', $actions_checked[$a->id]['cible']) : ''); ?>">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" data-action-id="<?php echo e($a->id); ?>" <?php if($is_disabled): ?> disabled <?php endif; ?>
                                                name="notifie-rse[<?php echo e($a->id); ?>]" value="<?php echo e(!$is_disabled ? old('notifie-rse[$a->id]', $actions_checked[$a->id]['notifie']) : ''); ?>">
                                        </td>
                                        <td>
                                            <input type="text" class="form-control" data-action-id="<?php echo e($a->id); ?>" <?php if($is_disabled): ?> disabled <?php endif; ?>
                                                name="realise-rse[<?php echo e($a->id); ?>]" value="<?php echo e(!$is_disabled ? old('realise-rse[$a->id]', $actions_checked[$a->id]['realise']) : ''); ?>">
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php else: ?>
                            <tr>
                                <td>-</td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
            <div class="row">
                <div class="col-12">
                    <div class="form-group row text-right">
                        <div class="col-sm-12">
                            <a href="<?php echo e(route('projets.index')); ?>" class="btn btn-outline-warning">Annuler</a>
                            <?php if($editable): ?>
                                <button id="sauvegarder" type="submit" class="btn btn-outline-success">
                                    Sauvegarder
                                </button>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <?php else: ?>
            <div class="pt-2">
                <h4>Pas de données disponible.</h4>
            </div>
        <?php endif; ?>
    </div>
</div>


<?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('edit_projet')): ?>
    <script>
        $(document).ready(function() {
            $("input[type='checkbox'][name='action_rse[]']").on('change', function() {
                // Si on décoche la case
                if (!this.checked) {
                    // On efface les valeurs entrées
                    $("input[data-action-id='" + this.value + "']").val('');
                }
                // Dans tous les cas, on inverse la propriété "disabled"
                $("[data-action-id='" + this.value + "']").prop('disabled', function(i, v) { return !v; });
                // alert(this.checked);
            });
        });
    </script>
<?php endif; ?><?php /**PATH /var/www/html/resources/views/projets/form/onglets/resp-soc-env.blade.php ENDPATH**/ ?>