 

<?php $__env->startSection('heading', 'Price Settings'); ?>
<?php $__env->startSection('subheading', 'Set prices for each garment your shop offers, by your own age types.'); ?>

<?php $__env->startSection('content'); ?>
<?php echo $__env->make('partials.master-tabs', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
<?php if($ageTypes->isEmpty()): ?>
  <div class="card p-6 text-center">
    <p class="text-sm mb-3" style="color:#6b6470;">You haven't set up any age types yet.</p>
    <a href="<?php echo e(route('shop.ageTypes.index')); ?>" class="text-sm font-medium" style="color:#C2185B;">Create age types first →</a>
  </div>
<?php else: ?>

<div id="statusBanner" class="hidden mb-4 text-sm rounded-lg px-4 py-3" style="background:#E1F5EE; color:#0F6E56;"></div>

<div class="card p-0 overflow-x-auto">
  <table class="w-full text-sm">
    <thead>
      <tr class="text-left" style="background:#FFF9F0; color:#a19a8f;">
        <th class="px-5 py-3 font-medium text-xs">Garment</th>
        <?php $__currentLoopData = $ageTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ageType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <th class="px-5 py-3 font-medium text-xs"><?php echo e($ageType->name); ?> ₹</th>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <th class="px-5 py-3 font-medium text-xs text-right">Save</th>
      </tr>
    </thead>
    <tbody>
      <?php $__empty_1 = true; $__currentLoopData = $shopGarments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sg): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <tr class="border-t price-row" data-id="<?php echo e($sg->id); ?>" style="border-color:#f2ece0;">
          <td class="px-5 py-3 font-medium" style="color:#1A1625;">
            <?php echo e($sg->garmentType->name); ?><?php echo e($sg->garmentType->name_ta ? ' / '.$sg->garmentType->name_ta : ''); ?>

          </td>
          <?php $__currentLoopData = $ageTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ageType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php $existing = $sg->prices->firstWhere('age_type_id', $ageType->id); ?>
            <td class="px-5 py-3">
              <input type="number" min="0" value="<?php echo e($existing->price ?? 0); ?>" data-age-type-id="<?php echo e($ageType->id); ?>"
                class="price-input w-24 px-2 py-1.5 rounded-lg border text-sm outline-none" style="border-color:#e6e1d8;">
            </td>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          <td class="px-5 py-3 text-right">
            <button type="button" class="save-price-btn text-xs px-3 py-1.5 rounded-lg font-medium text-white" style="background:#5E35B1;">Save</button>
          </td>
        </tr>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <tr><td colspan="<?php echo e($ageTypes->count() + 2); ?>" class="px-5 py-8 text-center" style="color:#a19a8f;">No garments offered yet.</td></tr>
      <?php endif; ?>
    </tbody>
  </table>
</div>
<?php endif; ?>

<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
document.querySelectorAll('.save-price-btn').forEach(btn => {
  btn.addEventListener('click', function () {
    const row = this.closest('.price-row');
    const shopGarmentId = row.dataset.id;

    const prices = {};
    row.querySelectorAll('.price-input').forEach(input => {
      prices[input.dataset.ageTypeId] = input.value || 0;
    });

    this.disabled = true;
    this.textContent = 'Saving...';

    fetch(`/settings/prices/${shopGarmentId}`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>' },
      body: JSON.stringify({ prices }),
    })
      .then(r => r.json())
      .then(data => {
        this.disabled = false;
        this.textContent = 'Save';
        showStatus(data.message || 'Updated');
      })
      .catch(() => {
        this.disabled = false;
        this.textContent = 'Save';
        showStatus('Something went wrong.', true);
      });
  });
});

function showStatus(msg, isError = false) {
  const banner = document.getElementById('statusBanner');
  banner.textContent = msg;
  banner.style.background = isError ? '#FCEBEB' : '#E1F5EE';
  banner.style.color = isError ? '#791F1F' : '#0F6E56';
  banner.classList.remove('hidden');
  setTimeout(() => banner.classList.add('hidden'), 2500);
}
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH F:\xampp\htdocs\etailorz-v2\resources\views/admin/settings/prices.blade.php ENDPATH**/ ?>