<div class="page-header">
    <div>
        <a href="<?= APP_URL ?>/dashboard" class="btn btn-ghost btn-sm mb-4" style="padding-left:0;">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>
            Back to Dashboard
        </a>
        <h1>Tax Groups</h1>
        <div class="page-subtitle">Manage tax rates for different product categories</div>
    </div>
    <a href="<?= APP_URL ?>/tax/create" class="btn btn-primary">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
        Add Tax Group
    </a>
</div>

<div class="card">
    <?php if (empty($taxGroups)): ?>
        <div style="padding:48px; text-align:center;">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="width:48px;height:48px;color:var(--text-muted);margin:0 auto 16px;">
                <rect x="4" y="4" width="16" height="16" rx="2"></rect>
                <line x1="12" y1="8" x2="12" y2="16"></line>
                <line x1="8" y1="12" x2="16" y2="12"></line>
            </svg>
            <h3 style="margin-bottom:8px;">No Tax Groups</h3>
            <p style="color:var(--text-muted); margin-bottom:16px;">Create tax groups to apply different tax rates to products.</p>
            <a href="<?= APP_URL ?>/tax/create" class="btn btn-primary">Create Tax Group</a>
        </div>
    <?php else: ?>
        <div class="table-wrapper">
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Rate</th>
                        <th>Products</th>
                        <th>Status</th>
                        <th class="text-right">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($taxGroups as $tg): ?>
                    <tr>
                        <td>
                            <div style="font-weight:600;"><?= e($tg['name']) ?></div>
                            <?php if (!empty($tg['description'])): ?>
                            <div style="font-size:0.85rem; color:var(--text-muted);"><?= e($tg['description']) ?></div>
                            <?php endif; ?>
                        </td>
                        <td>
                            <span class="badge badge-info"><?= strtoupper($tg['type']) ?></span>
                        </td>
                        <td>
                            <span style="font-weight:600;"><?= $tg['type'] === 'percentage' ? $tg['rate'] . '%' : money($tg['rate']) ?></span>
                        </td>
                        <td><?= $tg['product_count'] ?? 0 ?></td>
                        <td>
                            <?php if ($tg['is_active']): ?>
                            <span class="badge badge-success">Active</span>
                            <?php else: ?>
                            <span class="badge badge-danger">Inactive</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-right">
                            <a href="<?= APP_URL ?>/tax/<?= $tg['id'] ?>/edit" class="btn btn-ghost btn-icon" title="Edit">
                                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>
                            </a>
                            <form action="<?= APP_URL ?>/tax/<?= $tg['id'] ?>/delete" method="POST" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this tax group?');">
                                <?= Security::csrfField() ?>
                                <button type="submit" class="btn btn-ghost btn-icon" style="color:var(--danger);" title="Delete">
                                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
                                </button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php endif; ?>
</div>
