<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
  <div class="card">
    <div class="card-header"><h5 class="mb-0">Share Subscription</h5></div>
    <div class="card-body">
      <form method="POST" action="<?php echo e(route('subscriptions.store')); ?>" class="row g-3">
        <?php echo csrf_field(); ?>
        <div class="col-md-6">
          <label class="form-label">Service</label>
          <select name="service_id" id="service_id" class="form-select" required>
            <option value="">Select service</option>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $services; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $service): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($service->id); ?>" data-plans='<?php echo json_encode($service->plans, 15, 512) ?>' <?php if(old('service_id') == $service->id): echo 'selected'; endif; ?>><?php echo e($service->name); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
          </select>
        </div>
        <div class="col-md-6">
          <label class="form-label">Plan</label>
          <select name="service_plan_id" id="service_plan_id" class="form-select" required></select>
        </div>
        <div class="col-md-6"><label class="form-label">Title</label><input name="title" class="form-control" value="<?php echo e(old('title')); ?>"></div>
        <div class="col-md-3"><label class="form-label">Total Slots</label><input type="number" min="1" name="total_slots" class="form-control" value="<?php echo e(old('total_slots',1)); ?>" required></div>
        <div class="col-md-3"><label class="form-label">Available Slots</label><input type="number" min="1" name="available_slots" class="form-control" value="<?php echo e(old('available_slots',1)); ?>" required></div>
        <div class="col-md-6"><label class="form-label">Total Price</label><input type="number" step="0.01" min="0" name="total_price" class="form-control" value="<?php echo e(old('total_price')); ?>" required></div>
        <div class="col-md-6"><label class="form-label">Price Per Slot</label><input type="number" step="0.01" min="0" name="price_per_slot" class="form-control" value="<?php echo e(old('price_per_slot')); ?>" required></div>
        <div class="col-md-4">
          <label class="form-label d-block">Status</label>
          <span class="badge bg-label-warning">Pending Review</span>
          <small class="d-block text-muted mt-1">Admin/Super Admin will review and update listing status.</small>
        </div>
        <div class="col-md-4 form-check mt-4 ms-3"><input class="form-check-input" type="checkbox" name="is_public" value="1" <?php if(old('is_public',1)): echo 'checked'; endif; ?>><label class="form-check-label">Public Listing</label></div>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(auth()->check() && auth()->user()->hasRole('super admin')): ?>
          <div class="col-md-4 form-check mt-4">
            <input class="form-check-input" type="checkbox" name="requires_manual_approval" value="1" <?php if(old('requires_manual_approval')): echo 'checked'; endif; ?>>
            <label class="form-check-label">Manual Approval Required</label>
          </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        <div class="col-12"><label class="form-label">Notes</label><textarea name="notes" class="form-control" rows="3"><?php echo e(old('notes')); ?></textarea></div>
        <div class="col-12">
          <button class="btn btn-primary">Create Listing</button>
        </div>
      </form>
    </div>
  </div>
</div>

<script>
(() => {
  const serviceSelect = document.getElementById('service_id');
  const planSelect = document.getElementById('service_plan_id');
  const selectedPlan = '<?php echo e(old('service_plan_id')); ?>';

  function renderPlans() {
    const option = serviceSelect.options[serviceSelect.selectedIndex];
    const plans = option && option.dataset.plans ? JSON.parse(option.dataset.plans) : [];
    planSelect.innerHTML = '';
    plans.forEach(plan => {
      const opt = document.createElement('option');
      opt.value = plan.id;
      opt.textContent = `${plan.name} ($${Number(plan.price).toFixed(2)})`;
      if (String(plan.id) === String(selectedPlan)) opt.selected = true;
      planSelect.appendChild(opt);
    });
  }

  serviceSelect.addEventListener('change', renderPlans);
  renderPlans();
})();
</script>
<?php $__env->stopSection(); ?>

<?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/subscriptions/create.blade.php ENDPATH**/ ?>