<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
  <div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
      <h5 class="mb-0"><?php echo e($isSuperAdmin ? 'All Shared Subscriptions' : 'My Shared Subscriptions'); ?></h5>
      <?php
        $legacyRole = strtolower(trim((string) auth()->user()->role));
        $canCreateSubscription = auth()->user()->can('create subscription')
            || auth()->user()->hasAnyRole(['user', 'member', 'owner', 'admin', 'super admin'])
            || in_array($legacyRole, ['user', 'member', 'owner', 'admin', 'super admin'], true);
      ?>
      <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(! $isSuperAdmin && $canCreateSubscription): ?>
      <a href="<?php echo e(route('subscriptions.create')); ?>" class="btn btn-sm btn-primary">New Listing</a>
      <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>

    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('view subscription')): ?>
      <div class="table-responsive">
        <table <?php if($subscriptions->count() > 0): ?> id="dashboard-shared-subscriptions-table" <?php endif; ?> class="table">
          <thead>
            <tr>
              <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isSuperAdmin): ?><th>Owner</th><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              <th>Service</th>
              <th>Plan</th>
              <th>Price/Slot</th>
              <th>Slots</th>
              <th>Visibility</th>
              <th>Status</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $subscriptions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
              <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isSuperAdmin): ?><td><?php echo e($item->owner?->name ?? 'N/A'); ?></td><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              <td><?php echo e($item->service?->name ?? 'N/A'); ?></td>
              <td><?php echo e($item->servicePlan?->name ?? 'N/A'); ?></td>
              <td>$<?php echo e(number_format($item->price_per_slot,2)); ?></td>
              <td><?php echo e($item->available_slots); ?>/<?php echo e($item->total_slots); ?></td>
              <td><?php echo e($item->is_public ? 'Public' : 'Private'); ?></td>
              <td>
                <span class="badge bg-label-info">
                  <?php echo e($item->status === 'draft' ? 'Pending' : ucfirst($item->status)); ?>

                </span>
              </td>
              <td>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isSuperAdmin): ?>
                  <div class="d-flex gap-2">
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('update subscription')): ?>
                      <a href="<?php echo e(route('admin.shared-subscriptions.edit', $item)); ?>" class="btn btn-sm btn-outline-primary">Manage</a>
                    <?php endif; ?>

                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('delete subscription')): ?>
                      <form method="POST" action="<?php echo e(route('admin.shared-subscriptions.destroy', $item)); ?>">
                        <?php echo csrf_field(); ?>
                        <?php echo method_field('DELETE'); ?>
                        <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this shared subscription?')">Delete</button>
                      </form>
                    <?php endif; ?>
                  </div>
                <?php else: ?>
                  <span class="text-muted">-</span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr><td colspan="<?php echo e($isSuperAdmin ? 8 : 7); ?>" class="text-center py-4">No shared subscriptions yet.</td></tr>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
          </tbody>
        </table>
      </div>
    <?php else: ?>
      <div class="card-body"><div class="alert alert-warning mb-0">You do not have permission to view subscriptions.</div></div>
    <?php endif; ?>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($subscriptions->count() > 0): ?>
<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
  const $table = $('#dashboard-shared-subscriptions-table');
  if (!$table.length) return;
  const serviceColumnIndex = <?php echo e($isSuperAdmin ? 1 : 0); ?>;

  $table.DataTable({
    responsive: false,
    scrollX: true,
    pageLength: 10,
    lengthMenu: [5, 10, 25, 50, 100],
    order: [[serviceColumnIndex, 'asc']],
    columnDefs: [{ orderable: false, targets: -1 }]
  });
});
</script>
<?php $__env->stopPush(); ?>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\xampp\htdocs\G_desizn\marketplace\resources\views/dashboard/my-shared-subscriptions.blade.php ENDPATH**/ ?>