<?php $__env->startSection('content'); ?>
<div class="max-w-5xl mx-auto p-6 bg-white shadow rounded">
  <h2 class="text-2xl font-semibold mb-4">Prévisualisation de l'import pour le groupe : <?php echo e($group->name); ?></h2>

  <form method="POST" action="<?php echo e(route('groups.import_members', $group)); ?>">
    <?php echo csrf_field(); ?>
    <input type="hidden" name="confirm" value="1">

    <div class="overflow-x-auto">
      <table class="min-w-full divide-y divide-gray-200 mb-4 datatable">
        <thead class="bg-gray-50">
          <tr>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Nom</th>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Prénom</th>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Email</th>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Téléphone</th>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Statut</th>
            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">&nbsp;</th>
          </tr>
        </thead>
        <tbody class="bg-white divide-y divide-gray-200">
          <?php $__currentLoopData = $rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <tr class="hover:bg-gray-50 <?php echo e($row['errors'] ? 'bg-red-50' : ''); ?>">
            <td class="px-4 py-2">
              <input type="text" name="rows[<?php echo e($i); ?>][nom]" value="<?php echo e(old('rows.'.$i.'.nom', $row['nom'])); ?>" class="w-full rounded border-gray-300" />
            </td>
            <td class="px-4 py-2">
              <input type="text" name="rows[<?php echo e($i); ?>][prenom]" value="<?php echo e(old('rows.'.$i.'.prenom', $row['prenom'])); ?>" class="w-full rounded border-gray-300" />
            </td>
            <td class="px-4 py-2">
              <input type="text" name="rows[<?php echo e($i); ?>][email]" value="<?php echo e(old('rows.'.$i.'.email', $row['email'])); ?>" class="w-full rounded border-gray-300" />
            </td>
            <td class="px-4 py-2">
              <input type="text" name="rows[<?php echo e($i); ?>][telephone]" value="<?php echo e(old('rows.'.$i.'.telephone', $row['telephone'])); ?>" class="w-full rounded border-gray-300" />
            </td>
            <?php $__currentLoopData = $row['errors']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $err): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <input type="hidden" name="rows[<?php echo e($i); ?>][errors][]" value="<?php echo e($err); ?>" />
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <td class="px-4 py-2">
              <?php if($row['errors']): ?>
                <ul class="text-red-600 text-sm list-disc pl-4">
                  <?php $__currentLoopData = $row['errors']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $err): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($err); ?></li>
                  <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
              <?php else: ?>
                <span class="text-green-600">OK</span>
              <?php endif; ?>
            </td>
            <td class="px-4 py-2 text-center">
              <button type="button" class="remove-row text-red-600">🗑</button>
            </td>
          </tr>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
      </table>
    </div>

    <div class="flex justify-end space-x-2">
      <a href="<?php echo e(route('groups.edit_members', $group)); ?>" class="px-4 py-2 bg-gray-200 rounded">Annuler</a>
      <button type="submit" name="action" value="visible" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">Confirmer la liste affichée</button>
      <button type="submit" name="action" value="all" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">Confirmer l'importation</button>
    </div>
  </form>
</div>
<script>
  document.addEventListener('DOMContentLoaded', function () {
    var tableEl = $('.datatable');
    tableEl.on('init.dt', function () {
      var table = tableEl.DataTable();

      tableEl.on('click', '.remove-row', function () {
        table.row($(this).closest('tr')).remove().draw();
      });
    });
    document.querySelector('form').addEventListener('submit', function (e) {
      if (e.submitter && e.submitter.name === 'action' && e.submitter.value === 'visible') {
        let table = $('.datatable').DataTable();
        $(table.rows({ search: 'removed' }).nodes()).remove();
      }
    });
  });
</script>
<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/ecamesuac/public_html/notifications_colloque_uac/resources/views/groups/import_preview.blade.php ENDPATH**/ ?>