<div class="row">
    <div class="col-12">
        <div class="card glass-card">
            <div class="card-header"><h5 class="card-title">Tax Report</h5></div>
            <div class="card-body">
                <?php $this->include('Reports/partials/filter_date') ?>
                <div class="table-responsive mt-3">
                    <table class="table table-hover">
                        <thead>
                            <tr><th>Period</th><th>Tax Name</th><th class="text-end">Taxable Amount</th><th class="text-end">Tax Amount</th><th class="text-center">Invoices</th></tr>
                        </thead>
                        <tbody>
                            <?php if (empty($data)): ?>
                            <tr><td colspan="5" class="text-center py-4 text-muted">No data available.</td></tr>
                            <?php else: ?>
                                <?php foreach ($data as $row): ?>
                                <tr>
                                    <td><?= e($row->period) ?></td>
                                    <td><?= e($row->tax_name ?? 'VAT') ?></td>
                                    <td class="text-end"><?= currency($row->taxable_amount) ?></td>
                                    <td class="text-end"><?= currency($row->tax_amount) ?></td>
                                    <td class="text-center"><?= $row->invoice_count ?></td>
                                </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                        <?php if (!empty($data)): ?>
                        <tfoot>
                            <tr class="fw-bold">
                                <td colspan="2" class="text-end">Totals:</td>
                                <td class="text-end"><?= currency(array_sum(array_column($data, 'taxable_amount'))) ?></td>
                                <td class="text-end"><?= currency(array_sum(array_column($data, 'tax_amount'))) ?></td>
                                <td></td>
                            </tr>
                        </tfoot>
                        <?php endif; ?>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
