<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3><?= lang('App.invoices') ?></h3>
    <a href="/admin/invoices/create" class="btn btn-dark btn-sm"><?= lang('App.add_new') ?></a>
</div>
<div class="card p-3">
<table class="table">
    <thead><tr><th><?= lang('App.invoice_number') ?></th><th><?= lang('App.client') ?></th><th><?= lang('App.amount') ?></th><th><?= lang('App.due_date') ?></th><th><?= lang('App.status') ?></th><th><?= lang('App.actions') ?></th></tr></thead>
    <tbody>
    <?php foreach ($invoices as $inv): ?>
        <tr>
            <td><?= esc($inv['invoice_number']) ?></td>
            <td><?= esc($inv['client_name']) ?></td>
            <td><?= number_format($inv['amount'], 2) ?> <?= esc($inv['currency']) ?></td>
            <td><?= esc($inv['due_date']) ?></td>
            <td><span class="badge bg-secondary"><?= lang('App.' . $inv['status']) ?></span></td>
            <td>
                <a href="/admin/invoices/<?= $inv['id'] ?>/view" class="btn btn-sm btn-outline-secondary">عرض</a>
                <a href="/admin/invoices/<?= $inv['id'] ?>/edit" class="btn btn-sm btn-outline-primary"><?= lang('App.edit') ?></a>
                <form method="post" action="/admin/invoices/<?= $inv['id'] ?>/delete" class="d-inline" onsubmit="return confirm('?')">
                    <?= csrf_field() ?><button class="btn btn-sm btn-outline-danger"><?= lang('App.delete') ?></button>
                </form>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<?= $pager->links() ?>
</div>
<?= $this->endSection() ?>
