<?php $__env->startSection('content'); ?>
<div class="max-w-full sm:max-w-7xl mx-auto p-4 sm:p-6 bg-white shadow rounded">
  <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 space-y-4 sm:space-y-0">
    <h1 class="text-2xl font-semibold">Campagnes</h1>
    <div class="flex flex-col sm:flex-row sm:items-center sm:space-x-2 space-y-2 sm:space-y-0 w-full sm:w-auto">
      <button type="button" onclick="openModal('create-campaign')" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700 whitespace-nowrap">
        Nouvelle Campagne
      </button>
    </div>
  </div>

  
  <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4 mb-6">
    <div class="p-4 bg-blue-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Total Campagnes</h3>
      <p class="text-2xl font-bold"><?php echo e($campaigns->count()); ?></p>
    </div>
    <div class="p-4 bg-purple-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Liens générés</h3>
      <p class="text-2xl font-bold"><?php echo e($campaigns->pluck('links_count')->sum()); ?></p>
    </div>
    <div class="p-4 bg-green-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Payés</h3>
      <p class="text-2xl font-bold"><?php echo e($campaigns->pluck('paid_count')->sum()); ?></p>
    </div>
    <div class="p-4 bg-yellow-50 rounded text-center">
      <h3 class="text-sm text-gray-500 uppercase">Taux de conversion</h3>
      <?php
        $totalLinks = $campaigns->pluck('links_count')->sum();
        $totalPaid  = $campaigns->pluck('paid_count')->sum();
        $rate = $totalLinks > 0 ? number_format(($totalPaid/$totalLinks)*100,1) : 0;
      ?>
      <p class="text-2xl font-bold"><?php echo e($rate); ?>%</p>
    </div>
  </div>

  
  <div class="overflow-x-auto">
    <table class="w-full table-auto divide-y divide-gray-200 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">Liens</th>
          <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Payés</th>
          <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Conversion</th>
          <th class="px-4 py-2 text-center text-xs font-medium text-gray-500 uppercase">Actions</th>
        </tr>
      </thead>
      <tbody class="bg-white divide-y divide-gray-200">
        <?php $__currentLoopData = $campaigns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $camp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <tr class="hover:bg-gray-50">
          <td class="px-4 py-3 whitespace-nowrap"><?php echo e($camp->name); ?></td>
          <td class="px-4 py-3 whitespace-nowrap"><?php echo e($camp->links_count); ?></td>
          <td class="px-4 py-3 whitespace-nowrap"><?php echo e($camp->paid_count); ?></td>
          <td class="px-4 py-3 whitespace-nowrap"><?php echo e($camp->links_count > 0 ? number_format(($camp->paid_count/$camp->links_count)*100,1) : 0); ?>%</td>
          <td class="px-4 py-3 text-center space-x-1">
            <button type="button" onclick="loadCampaignDetails(<?php echo e($camp->id); ?>)" class="text-indigo-600 hover:text-indigo-800 whitespace-nowrap">Détails</button>
            <a href="<?php echo e(route('campaigns.send_form',$camp)); ?>" class="text-indigo-600 hover:text-indigo-800 whitespace-nowrap">Envoyer</a>
            <button type="button" onclick="openModal('edit-campaign-<?php echo e($camp->id); ?>')" class="text-blue-600 hover:text-blue-800 whitespace-nowrap">✎</button>
            <form id="delete-campaign-<?php echo e($camp->id); ?>-form" action="<?php echo e(route('campaigns.destroy',$camp)); ?>" method="POST" class="inline">
              <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
              <button type="button" onclick="openModal('confirm-delete-campaign-<?php echo e($camp->id); ?>')" class="text-red-600 hover:text-red-800 whitespace-nowrap">🗑</button>
            </form>
          </td>
        </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      </tbody>
    </table>
  </div>

</div>

<?php if (isset($component)) { $__componentOriginal9f64f32e90b9102968f2bc548315018c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9f64f32e90b9102968f2bc548315018c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.modal','data' => ['id' => 'create-campaign']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['id' => 'create-campaign']); ?>
  <h2 class="text-xl font-semibold mb-4">Nouvelle campagne</h2>
  <form method="POST" action="<?php echo e(route('campaigns.store')); ?>" enctype="multipart/form-data">
    <?php echo csrf_field(); ?>
    <?php echo $__env->make('campaigns.partials.form', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <div class="mt-4 text-right space-x-2">
      <button type="button" onclick="closeModal()" class="px-4 py-2 bg-gray-200 rounded">Annuler</button>
      <button type="submit" class="px-4 py-2 bg-green-600 text-white rounded">Enregistrer</button>
    </div>
  </form>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $attributes = $__attributesOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__attributesOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $component = $__componentOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__componentOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>

<?php $__currentLoopData = $campaigns; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $camp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
  <?php if (isset($component)) { $__componentOriginal9f64f32e90b9102968f2bc548315018c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9f64f32e90b9102968f2bc548315018c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.modal','data' => ['id' => 'edit-campaign-'.e($camp->id).'']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['id' => 'edit-campaign-'.e($camp->id).'']); ?>
    <h2 class="text-xl font-semibold mb-4">Modifier la campagne</h2>
    <form method="POST" action="<?php echo e(route('campaigns.update', $camp)); ?>" enctype="multipart/form-data">
      <?php echo csrf_field(); ?>
      <?php echo method_field('PUT'); ?>
      <?php echo $__env->make('campaigns.partials.form', ['campaign' => $camp], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
      <div class="mt-4 text-right space-x-2">
        <button type="button" onclick="closeModal()" class="px-4 py-2 bg-gray-200 rounded">Annuler</button>
        <button type="submit" class="px-4 py-2 bg-green-600 text-white rounded">Mettre à jour</button>
      </div>
    </form>
   <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $attributes = $__attributesOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__attributesOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $component = $__componentOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__componentOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>
  <?php if (isset($component)) { $__componentOriginal2cfaf2d8c559a20e3495c081df2d0b10 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2cfaf2d8c559a20e3495c081df2d0b10 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.confirm-modal','data' => ['id' => 'confirm-delete-campaign-'.e($camp->id).'','formId' => 'delete-campaign-'.e($camp->id).'-form','message' => 'Supprimer cette campagne ?','confirmText' => 'Supprimer']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('confirm-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['id' => 'confirm-delete-campaign-'.e($camp->id).'','formId' => 'delete-campaign-'.e($camp->id).'-form','message' => 'Supprimer cette campagne ?','confirmText' => 'Supprimer']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2cfaf2d8c559a20e3495c081df2d0b10)): ?>
<?php $attributes = $__attributesOriginal2cfaf2d8c559a20e3495c081df2d0b10; ?>
<?php unset($__attributesOriginal2cfaf2d8c559a20e3495c081df2d0b10); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2cfaf2d8c559a20e3495c081df2d0b10)): ?>
<?php $component = $__componentOriginal2cfaf2d8c559a20e3495c081df2d0b10; ?>
<?php unset($__componentOriginal2cfaf2d8c559a20e3495c081df2d0b10); ?>
<?php endif; ?>

<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

<?php if (isset($component)) { $__componentOriginal9f64f32e90b9102968f2bc548315018c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9f64f32e90b9102968f2bc548315018c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.modal','data' => ['id' => 'campaign-details-modal','maxWidth' => 'max-w-5xl']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['id' => 'campaign-details-modal','maxWidth' => 'max-w-5xl']); ?>
  <div id="campaign-details-content"></div>
  <div class="mt-4 text-right">
    <button type="button" onclick="closeModal()" class="px-4 py-2 bg-gray-200 rounded">Fermer</button>
  </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $attributes = $__attributesOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__attributesOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9f64f32e90b9102968f2bc548315018c)): ?>
<?php $component = $__componentOriginal9f64f32e90b9102968f2bc548315018c; ?>
<?php unset($__componentOriginal9f64f32e90b9102968f2bc548315018c); ?>
<?php endif; ?>
</div>
<?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/campaigns/index.blade.php ENDPATH**/ ?>