<div class="card-box">
    <div class="card-box-header">
        <h5><i class="fa-solid fa-file-invoice-dollar" style="color:#7c3aed;"></i> Sales Billing</h5>
        <a href="<?= site_url('sales_billing/create') ?>" class="btn btn-primary btn-sm">
            <i class="fa-solid fa-plus me-1"></i> Add Sale Bill
        </a>
    </div>

    <?php if($this->session->flashdata('success')): ?>
    <div class="alert alert-success alert-dismissible fade show py-2">
        <i class="fa-solid fa-circle-check me-2"></i><?= $this->session->flashdata('success') ?>
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    <?php endif; ?>

    <div class="table-responsive">
        <table class="table table-bordered table-hover dt-table mb-0" style="font-size:13px;">
            <thead>
                <tr>
                    <th width="40">#</th>
                    <th>Bill No</th>
                    <th>Date</th>
                    <th>Customer</th>
                    <th>Mobile</th>
                    <th class="text-end">Sub Total (₹)</th>
                    <th class="text-end">Discount (₹)</th>
                    <th class="text-end">Net Payable (₹)</th>
                    <th width="150" class="text-center" style="white-space:nowrap;">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if(!empty($rows)): $i = 1; foreach($rows as $row): ?>
                <tr>
                    <td class="py-1"><?= $i++ ?></td>
                    <td class="py-1"><code style="font-size:12px;"><?= htmlspecialchars($row->bill_no) ?></code></td>
                    <td class="py-1" style="white-space:nowrap;"><?= date('d M Y', strtotime($row->bill_date)) ?></td>
                    <td class="py-1" style="white-space:nowrap;"><strong><?= htmlspecialchars($row->customer_name) ?></strong></td>
                    <td class="py-1"><?= htmlspecialchars($row->mobile) ?></td>
                    <td class="py-1 text-end">₹<?= (int)($row->subtotal) ?></td>
                    <td class="py-1 text-end text-danger">₹<?= (int)($row->discount) ?></td>
                    <td class="py-1 text-end fw-bold text-success">₹<?= (int)($row->net_payable) ?></td>
                    <td class="py-1 text-center" style="white-space:nowrap;">
                        <a href="<?= site_url('sales_billing/view/'.$row->id) ?>"   class="btn btn-sm btn-view me-1"  title="View"><i class="fa-solid fa-eye"></i></a>
                        <a href="<?= site_url('sales_billing/invoice/'.$row->id) ?>"
       class="btn btn-sm btn-success me-1" title="Invoice">
        <i class="fa-solid fa-file-invoice"></i>
    </a>
                        <a href="<?= site_url('sales_billing/edit/'.$row->id) ?>"   class="btn btn-sm btn-edit me-1"  title="Edit"><i class="fa-solid fa-pen-to-square"></i></a>
                        <!--<a href="<?= site_url('sales_billing/delete/'.$row->id) ?>" class="btn btn-sm btn-delete btn-delete-confirm" title="Delete"><i class="fa-solid fa-trash"></i></a>-->
                    </td>
                </tr>
                <?php endforeach; else: ?>
                <tr><td colspan="9" class="text-center py-4 text-muted">
                    No sales bills found. <a href="<?= site_url('sales_billing/create') ?>">Add first bill</a>
                </td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>