<?= view('components/print_header', ['printTitle' => '지정판매소 현황']) ?>
<section class="border-b border-gray-300 p-2 shrink-0 bg-control-panel">
  <div class="flex flex-wrap items-center justify-between gap-y-2">
    <span class="text-sm font-bold text-gray-700">지정판매소 현황 (신규/취소)</span>
    <div class="flex items-center gap-2">
      <button onclick="window.print()" class="no-print border border-btn-print-border text-gray-600 px-3 py-1 rounded-sm text-sm hover:bg-gray-50 transition">인쇄</button>
      <a href="<?= base_url('admin/designated-shops') ?>" class="border border-gray-300 text-gray-600 px-3 py-1 rounded-sm text-sm hover:bg-gray-50">목록으로</a>
    </div>
  </div>
</section>

<!-- 전체 현황 요약 -->
<div class="flex gap-4 mt-2 mb-2">
  <div class="border border-gray-300 p-3 flex-1 text-center">
    <div class="text-sm text-gray-500">활성 판매소</div>
    <div class="text-2xl font-bold text-green-600"><?= number_format($totalActive) ?></div>
  </div>
  <div class="border border-gray-300 p-3 flex-1 text-center">
    <div class="text-sm text-gray-500">비활성/취소 판매소</div>
    <div class="text-2xl font-bold text-red-600"><?= number_format($totalInactive) ?></div>
  </div>
  <div class="border border-gray-300 p-3 flex-1 text-center">
    <div class="text-sm text-gray-500">전체</div>
    <div class="text-2xl font-bold text-gray-700"><?= number_format($totalActive + $totalInactive) ?></div>
  </div>
</div>

<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-2">
  <!-- 연도별 신규등록 -->
  <div>
    <h3 class="text-sm font-bold text-gray-700 mb-1">연도별 신규등록 건수</h3>
    <div class="border border-gray-300 overflow-auto">
      <table class="w-full data-table">
        <thead>
          <tr>
            <th>연도</th>
            <th>신규등록 건수</th>
          </tr>
        </thead>
        <tbody class="text-right">
          <?php foreach ($newByYear as $row): ?>
          <tr>
            <td class="text-center"><?= esc($row->yr) ?>년</td>
            <td><?= number_format((int) $row->cnt) ?></td>
          </tr>
          <?php endforeach; ?>
          <?php if (empty($newByYear)): ?>
          <tr><td colspan="2" class="text-center text-gray-400 py-4">데이터가 없습니다.</td></tr>
          <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- 연도별 취소/비활성 -->
  <div>
    <h3 class="text-sm font-bold text-gray-700 mb-1">연도별 취소/비활성 건수</h3>
    <div class="border border-gray-300 overflow-auto">
      <table class="w-full data-table">
        <thead>
          <tr>
            <th>연도</th>
            <th>취소/비활성 건수</th>
          </tr>
        </thead>
        <tbody class="text-right">
          <?php foreach ($cancelByYear as $row): ?>
          <tr>
            <td class="text-center"><?= esc($row->yr) ?>년</td>
            <td><?= number_format((int) $row->cnt) ?></td>
          </tr>
          <?php endforeach; ?>
          <?php if (empty($cancelByYear)): ?>
          <tr><td colspan="2" class="text-center text-gray-400 py-4">데이터가 없습니다.</td></tr>
          <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>
