<div class="d-flex justify-content-between align-items-center mb-3">
  <h4 class="mb-0">تقرير أرصدة البنوك</h4>
  <div class="btn-group">
    <a class="btn btn-outline-primary" target="_blank" href="<?= e(url('/reports/finance/bank-balances/print?q=' . urlencode($q) . '&format=a4')) ?>"><i class="fa-solid fa-print"></i> طباعة</a>
    <a class="btn btn-outline-danger" href="<?= e(url('/reports/finance/bank-balances/pdf?q=' . urlencode($q))) ?>">PDF</a>
    <a class="btn btn-outline-success" href="<?= e(url('/reports/finance/bank-balances/export?q=' . urlencode($q))) ?>">Excel</a>
  </div>
</div>
<form class="card p-3 mb-3" method="get">
  <div class="row g-2 align-items-end">
    <div class="col-md-9">
      <label class="form-label">بحث</label>
      <input type="text" class="form-control" name="q" value="<?= e($q) ?>" placeholder="اسم الحساب / البنك / رقم الحساب / IBAN">
    </div>
    <div class="col-md-3 d-flex gap-2">
      <button class="btn btn-outline-primary w-100" type="submit">عرض</button>
      <a class="btn btn-outline-secondary" href="<?= e(url($bank_balances_url ?? '/reports/finance/bank-balances')) ?>">مسح</a>
    </div>
  </div>
</form>
<div class="row g-3 mb-3">
  <div class="col-md-6"><div class="card p-3"><div class="text-muted small">إجمالي الافتتاحي</div><div class="fs-4 fw-bold"><?= e(nf($totals['opening'])) ?></div></div></div>
  <div class="col-md-6"><div class="card p-3"><div class="text-muted small">إجمالي الرصيد الحالي</div><div class="fs-4 fw-bold text-success"><?= e(nf($totals['current'])) ?></div></div></div>
</div>
<div class="card p-3">
  <div class="table-responsive">
    <table class="table table-sm table-bordered align-middle mb-0">
      <thead class="table-light"><tr><th>اسم الحساب</th><th>البنك</th><th>رقم الحساب</th><th>العملة</th><th class="text-end">رصيد افتتاحي</th><th class="text-end">الرصيد الحالي</th><th>الحالة</th></tr></thead>
      <tbody>
      <?php if (empty($rows)): ?><tr><td colspan="7" class="text-center text-muted py-4">لا توجد بيانات</td></tr><?php endif; ?>
      <?php foreach ($rows as $r): ?>
      <tr>
        <td><div class="fw-bold"><?= e($r['name']) ?></div><?php if (!empty($r['iban'])): ?><small class="text-muted"><?= e($r['iban']) ?></small><?php endif; ?></td>
        <td><?= e($r['bank_name'] ?: '-') ?></td>
        <td><?= e($r['account_no'] ?: '-') ?></td>
        <td><?= e($r['currency_code'] ?: 'EGP') ?></td>
        <td class="text-end"><?= e(nf($r['opening_balance'])) ?></td>
        <td class="text-end fw-bold"><?= e(nf($r['current_balance'])) ?></td>
        <td><?= (int)$r['is_active']===1 ? '<span class="badge text-bg-success">نشط</span>' : '<span class="badge text-bg-secondary">غير نشط</span>' ?></td>
      </tr>
      <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>
