<div class="space-y-1">
  <form method="get" class="flex items-center gap-3 text-sm mb-3">
    <label class="font-bold text-gray-700">조회기간</label>
    <input type="date" name="start_date" value="<?= esc($startDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
    <span>~</span>
    <input type="date" name="end_date" value="<?= esc($endDate ?? '') ?>" class="border border-gray-300 rounded px-2 py-1 text-sm"/>
    <button type="submit" class="bg-btn-search text-white px-4 py-1.5 rounded-sm text-sm">조회</button>
    <a href="<?= base_url('bag/sales-stats') ?>" class="text-sm text-gray-500 hover:text-gray-700">초기화</a>
  </form>

  <table class="data-table">
    <thead><tr>
      <th class="w-16 text-center">번호</th><th>판매소</th><th class="text-center">판매일</th><th class="text-center">봉투코드</th><th>봉투명</th><th class="text-right">수량</th><th class="text-right">단가</th><th class="text-right">금액</th>
    </tr></thead>
    <tbody>
    <?php if (! empty($result)): ?>
      <?php foreach ($result as $i => $row): ?>
      <tr>
        <td class="text-center"><?= $i + 1 ?></td>
        <td><?= esc($row->bs_shop_name ?? '') ?></td>
        <td class="text-center"><?= esc($row->bs_sale_date ?? '') ?></td>
        <td class="text-center"><?= esc($row->bs_bag_code ?? '') ?></td>
        <td><?= esc($row->bs_bag_name ?? '') ?></td>
        <td class="text-right"><?= number_format((int)($row->bs_qty ?? 0)) ?></td>
        <td class="text-right"><?= number_format((float)($row->bs_unit_price ?? 0)) ?></td>
        <td class="text-right"><?= number_format((float)($row->bs_amount ?? 0)) ?></td>
      </tr>
      <?php endforeach; ?>
    <?php else: ?>
      <tr><td colspan="8" class="text-center text-gray-400 py-4">판매 데이터가 없습니다.</td></tr>
    <?php endif; ?>
    </tbody>
  </table>
</div>
