<div class="card-box">
<div class="col-12">
    <div class="card-box-header">
        <h5>
            <i class="fa fa-file-excel-o" onclick="exportToExcel('product_detailview','products')" style="color:#17179e;font-size:18px;cursor:pointer;margin-right:8px;" title="Export Excel"></i>
            <i class="fa fa-print" onclick="window.print()" style="font-size:18px;cursor:pointer;margin-right:8px;" title="Print"></i>
            <i class="fa-solid fa-box" style="color:#7c3aed;"></i> Product Master
        </h5>
        <a href="<?php echo site_url('product/create'); ?>" class="btn btn-primary btn-sm">
            <i class="fa-solid fa-plus me-1"></i> Add Product
        </a>
    </div>
    <div class="print-title" style="display:none;">Product Master</div>

    <div class="table-responsive">
        <table id="product_detailview" class="table table-bordered table-hover dt-table mb-0">
            <thead>
                <tr>
                    <th width="60">Sr.</th>
                    <th>Code</th>
                    <th>Product Name</th>
                    <th>Unit</th>
                    <th>Category</th>
                    <th>Purchase Rate</th>
                    <th>Sale Rate</th>
                    <th>GST%</th>
                    <th width="180" class="text-center">Status</th>
                    <th width="160" class="text-center">Action</th>
                </tr>
            </thead>
            <tbody>
                <?php if(!empty($productdata)): $sr = 1; foreach($productdata as $row): ?>
                <tr>
                    <td><?php echo $sr++; ?></td>
                    <td><?php echo $row->product_code; ?></td>
                    <td><?php echo htmlspecialchars($row->product_name); ?></td>
                    <td><?php echo $row->unit_name; ?></td>
                    <td><?php echo $row->category_name; ?></td>
                    <td>₹<?php echo (int)($row->purchase_rate); ?></td>
                    <td>₹<?php echo (int)($row->sale_rate); ?></td>
                    <td><?php echo $row->gst_percent; ?>%</td>
                    <td class="text-center">
                        <?php if($row->status == 1): ?>
                            <span class="badge-active"><i class="fa-solid fa-circle-check me-1"></i>Active</span>
                        <?php else: ?>
                            <span class="badge-inactive"><i class="fa-solid fa-circle-xmark me-1"></i>Inactive</span>
                        <?php endif; ?>
                    </td>
                    <td class="text-center">
                        <a href="<?php echo site_url('product/edit/'.$row->id); ?>" class="btn btn-sm btn-edit me-1"><i class="fa-solid fa-pen-to-square"></i></a>
                        <!--<a href="<?php echo site_url('product/delete/'.$row->id); ?>" class="btn btn-sm btn-delete btn-delete-confirm"><i class="fa-solid fa-trash"></i></a>-->
                    </td>
                </tr>
                <?php endforeach; else: ?>
                <tr><td colspan="10" class="text-center py-4 text-muted">No products found. <a href="<?php echo site_url('product/create'); ?>">Add first</a></td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
</div>