<div class="page-header">
    <div>
        <h1>Supplier Ledger</h1>
        <div class="page-subtitle">Track supplier transactions and due balances</div>
    </div>
    <div class="flex gap-2">
        <a href="<?= APP_URL ?>/suppliers" class="btn btn-secondary">View Suppliers</a>
    </div>
</div>

<!-- Summary Cards -->
<div class="grid-4 gap-3 mb-6">
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Suppliers with Due</h3>
        </div>
        <div class="p-4">
            <div class="text-2xl font-bold"><?= count($suppliers) ?></div>
        </div>
    </div>
    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Total Due</h3>
        </div>
        <div class="p-4">
            <div class="text-2xl font-bold text-red-600"><?= money(array_sum(array_column($suppliers, 'balance'))) ?></div>
        </div>
    </div>
</div>

<!-- Suppliers with Due Balances -->
<div class="card">
    <div class="card-header">
        <h3 class="card-title">Suppliers with Due Balances</h3>
    </div>
    <div class="overflow-x-auto">
        <table class="data-table">
            <thead>
                <tr>
                    <th class="text-left">Supplier</th>
                    <th class="text-left">Phone</th>
                    <th class="text-left">Email</th>
                    <th class="text-center">Due Balance</th>
                    <th class="text-center">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($suppliers)): ?>
                <tr>
                    <td colspan="5" class="text-center" style="padding: 24px 10px;">No suppliers with due balances.</td>
                </tr>
                <?php else: foreach ($suppliers as $supplier): ?>
                <tr>
                    <td class="text-left font-bold"><?= e($supplier['name']) ?></td>
                    <td class="text-left"><?= e($supplier['phone']) ?></td>
                    <td class="text-left"><?= e($supplier['email']) ?></td>
                    <td class="text-center font-bold text-red-600"><?= money($supplier['balance']) ?></td>
                    <td class="text-center">
                        <a href="<?= APP_URL ?>/supplier-ledger/<?= $supplier['id'] ?>" class="btn btn-primary btn-sm">View Ledger</a>
                    </td>
                </tr>
                <?php endforeach; endif; ?>
            </tbody>
        </table>
    </div>
</div>
