<?php $__env->startSection('heading', 'Reports'); ?>
<?php $__env->startSection('subheading', 'Sales, pipeline, balances, and salary — filtered and exportable.'); ?>

<?php $__env->startSection('actions'); ?>
  <div class="flex gap-2">
    <a href="<?php echo e(route('reports.export.excel', ['tab' => $tab, 'from' => $from, 'to' => $to])); ?>" class="px-3 py-2 rounded-lg text-xs font-medium" style="background:#E1F5EE; color:#0F6E56;">Export Excel</a>
    <a href="<?php echo e(route('reports.export.pdf', ['tab' => $tab, 'from' => $from, 'to' => $to])); ?>" class="px-3 py-2 rounded-lg text-xs font-medium" style="background:#FAECE7; color:#993C1D;">Export PDF</a>
  </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<!-- Tabs -->
<div class="flex gap-2 mb-4">
  <?php $__currentLoopData = ['sales' => 'Sales', 'pipeline' => 'Pipeline', 'balances' => 'Balances', 'salary' => 'Salary']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <a href="<?php echo e(route('reports.index', ['tab' => $key, 'from' => $from, 'to' => $to])); ?>"
       class="text-sm px-4 py-2 rounded-lg font-medium"
       style="<?php echo e($tab === $key ? 'background:#C2185B; color:white;' : 'background:#f2ece0; color:#6b6470;'); ?>">
      <?php echo e($label); ?>

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

<!-- Date filter (sales + salary only) -->
<?php if(in_array($tab, ['sales', 'salary'])): ?>
<form method="GET" class="card p-4 mb-4 flex items-end gap-3">
  <input type="hidden" name="tab" value="<?php echo e($tab); ?>">
  <div>
    <label class="block text-xs mb-1" style="color:#6b6470;">From</label>
    <input type="date" name="from" value="<?php echo e($from); ?>" class="px-3 py-2 rounded-lg border text-sm outline-none" style="border-color:#e6e1d8;">
  </div>
  <div>
    <label class="block text-xs mb-1" style="color:#6b6470;">To</label>
    <input type="date" name="to" value="<?php echo e($to); ?>" class="px-3 py-2 rounded-lg border text-sm outline-none" style="border-color:#e6e1d8;">
  </div>
  <button type="submit" class="px-4 py-2 rounded-lg text-sm font-medium text-white" style="background:#5E35B1;">Filter</button>
</form>
<?php endif; ?>

<?php if($tab === 'sales'): ?>
  <div class="grid grid-cols-4 gap-4 mb-4">
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Orders</p><p class="font-display font-semibold text-2xl"><?php echo e($data['total_orders']); ?></p></div>
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Revenue</p><p class="font-display font-semibold text-2xl">₹<?php echo e(number_format($data['total_revenue'], 0)); ?></p></div>
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Advance collected</p><p class="font-display font-semibold text-2xl">₹<?php echo e(number_format($data['total_advance'], 0)); ?></p></div>
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Balance pending</p><p class="font-display font-semibold text-2xl">₹<?php echo e(number_format($data['total_balance'], 0)); ?></p></div>
  </div>
  <div class="card p-0 overflow-hidden">
    <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">Order</th><th class="px-5 py-3 font-medium text-xs">Customer</th>
        <th class="px-5 py-3 font-medium text-xs">Date</th><th class="px-5 py-3 font-medium text-xs text-right">Total</th>
      </tr></thead>
      <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $data['orders']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
          <tr class="border-t" style="border-color:#f2ece0;">
            <td class="px-5 py-3">#<?php echo e($o->id); ?></td><td class="px-5 py-3"><?php echo e($o->customer->name ?? '—'); ?></td>
            <td class="px-5 py-3"><?php echo e($o->created_at->format('d M Y')); ?></td><td class="px-5 py-3 text-right font-medium">₹<?php echo e(number_format($o->total_amount, 0)); ?></td>
          </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
          <tr><td colspan="4" class="px-5 py-8 text-center" style="color:#a19a8f;">No orders in this range.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
<?php endif; ?>

<?php if($tab === 'pipeline'): ?>
  <div class="card p-6 mb-4">
    <div class="grid grid-cols-6 gap-4">
      <?php $__currentLoopData = $data['counts']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stage => $count): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="flex flex-col items-center gap-2">
          <div class="w-14 h-14 rounded-full flex items-center justify-center font-display font-semibold" style="background:#EEEDFE; color:#5E35B1;"><?php echo e($count); ?></div>
          <span class="text-xs capitalize" style="color:#6b6470;"><?php echo e($stage); ?></span>
        </div>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
  </div>
<?php endif; ?>

<?php if($tab === 'balances'): ?>
  <div class="grid grid-cols-2 gap-4 mb-4">
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Total outstanding</p><p class="font-display font-semibold text-2xl" style="color:#C2185B;">₹<?php echo e(number_format($data['total_outstanding'], 0)); ?></p></div>
    <div class="card p-5"><p class="text-xs mb-1" style="color:#6b6470;">Customers owing</p><p class="font-display font-semibold text-2xl"><?php echo e($data['customer_count']); ?></p></div>
  </div>
  <div class="card p-0 overflow-hidden">
    <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">Order</th><th class="px-5 py-3 font-medium text-xs">Customer</th>
        <th class="px-5 py-3 font-medium text-xs text-right">Balance</th>
      </tr></thead>
      <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $data['orders']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
          <tr class="border-t" style="border-color:#f2ece0;">
            <td class="px-5 py-3">#<?php echo e($o->id); ?></td><td class="px-5 py-3"><?php echo e($o->customer->name ?? '—'); ?></td>
            <td class="px-5 py-3 text-right font-medium" style="color:#C2185B;">₹<?php echo e(number_format($o->balance_amount, 0)); ?></td>
          </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
          <tr><td colspan="3" class="px-5 py-8 text-center" style="color:#a19a8f;">No outstanding balances.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
<?php endif; ?>

<?php if($tab === 'salary'): ?>
  <div class="card p-5 mb-4"><p class="text-xs mb-1" style="color:#6b6470;">Total paid in range</p><p class="font-display font-semibold text-2xl">₹<?php echo e(number_format($data['total_paid'], 0)); ?></p></div>
  <div class="card p-0 overflow-hidden">
    <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">Staff</th><th class="px-5 py-3 font-medium text-xs">Date</th>
        <th class="px-5 py-3 font-medium text-xs">Notes</th><th class="px-5 py-3 font-medium text-xs text-right">Amount</th>
      </tr></thead>
      <tbody>
        <?php $__empty_1 = true; $__currentLoopData = $data['payments']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
          <tr class="border-t" style="border-color:#f2ece0;">
            <td class="px-5 py-3"><?php echo e($p->staff->name ?? '—'); ?> <span class="text-xs" style="color:#a19a8f;"><?php echo e($p->staff->staff_code ?? ''); ?></span></td>
            <td class="px-5 py-3"><?php echo e($p->paid_on->format('d M Y')); ?></td><td class="px-5 py-3" style="color:#6b6470;"><?php echo e($p->notes ?? '—'); ?></td>
            <td class="px-5 py-3 text-right font-medium">₹<?php echo e(number_format($p->amount, 0)); ?></td>
          </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
          <tr><td colspan="4" class="px-5 py-8 text-center" style="color:#a19a8f;">No payments in this range.</td></tr>
        <?php endif; ?>
      </tbody>
    </table>
  </div>
<?php endif; ?>

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

<?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/reports/index.blade.php ENDPATH**/ ?>