<?php
/**
 * Branch Wallets List — Gmind Institute ERP
 * Lists all branches with wallet balances
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<div class="admin-page-header" style="display:flex;justify-content:space-between;align-items:center;margin-bottom:24px;">
    <h1 style="margin:0;font-size:22px;font-weight:700;">Branch Wallets</h1>
</div>

<div class="admin-table-wrapper">
    <table class="admin-table">
        <thead>
            <tr>
                <th>Branch Name</th>
                <th>City</th>
                <th>Branch Code</th>
                <th>Wallet Balance (₹)</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($branches)): ?>
                <?php foreach ($branches as $br): ?>
                <tr>
                    <td><?= htmlspecialchars($br['name'], ENT_QUOTES, 'UTF-8') ?></td>
                    <td><?= htmlspecialchars($br['city'] ?? '', ENT_QUOTES, 'UTF-8') ?></td>
                    <td><code style="background:#f5f5f5;padding:2px 6px;border-radius:3px;font-size:12px;"><?= htmlspecialchars($br['branch_code'] ?? '', ENT_QUOTES, 'UTF-8') ?></code></td>
                    <td style="font-weight:600;">₹<?= number_format((float)($br['wallet_balance'] ?? 0), 2) ?></td>
                    <td>
                        <a href="<?= $bp ?>/admin/branch-wallet/<?= (int)$br['id'] ?>" class="admin-btn admin-btn-sm admin-btn-secondary" title="View Transactions">View</a>
                        <form method="POST" action="<?= $bp ?>/admin/branch-wallet/<?= (int)$br['id'] ?>/add-funds" style="display:inline;" onsubmit="var amt=prompt('Enter amount to add (₹):'); if(amt===null||isNaN(amt)||amt<=0){return false;} this.elements['amount'].value=amt; return true;">
                            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken, ENT_QUOTES, 'UTF-8') ?>">
                            <input type="hidden" name="amount" value="">
                            <button type="submit" class="admin-btn admin-btn-sm admin-btn-primary" style="background:#2e7d32;color:#fff;" title="Add Funds">Add Funds</button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr><td colspan="5" style="text-align:center;color:#999;">No branches found.</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
