<div class="card-box">
    <div class="card-box-header">
        <h5><i class="fa-solid fa-shirt" style="color:#7c3aed;"></i> Tailoring Orders</h5>
        <a href="<?= site_url('tailoring_order/create') ?>" class="btn btn-primary btn-sm">
            <i class="fa-solid fa-plus me-1"></i> Add Order
        </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; white-space:nowrap;">
            <thead>
                <tr>
                    <th width="40">#</th>
                    <th>Order No</th>
                    <th>Customer</th>
                    <th>Mobile</th>
                    <th class="text-end">Total (₹)</th>
                    <th class="text-end">Advance (₹)</th>
                    <th>Order Date</th>
                    <th>Delivery Date</th>
                    <th class="text-center">Status</th>
                    <th width="130" class="text-center">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $status_colors = [
                    'Pending'     => ['bg' => '#fef3c7', 'color' => '#d97706'],
                    'In Progress' => ['bg' => '#dbeafe', 'color' => '#2563eb'],
                    'Ready'       => ['bg' => '#d1fae5', 'color' => '#059669'],
                    'Delivered'   => ['bg' => '#dcfce7', 'color' => '#16a34a'],
                    'Cancelled'   => ['bg' => '#fee2e2', 'color' => '#dc2626'],
                ];
                if(!empty($rows)): $i = 1; foreach($rows as $row):
                    $sc = $status_colors[$row->order_status] ?? ['bg' => '#f1f5f9', 'color' => '#64748b'];
                ?>
                <tr>
                    <td><?= $i++ ?></td>
                    <td><code style="font-size:12px;"><?= htmlspecialchars($row->order_no) ?></code></td>
                    <td><strong><?= htmlspecialchars($row->customer_name) ?></strong></td>
                    <td><?= htmlspecialchars($row->mobile) ?></td>
                    <td class="text-end fw-bold">₹<?= (int)($row->total_charge) ?></td>
                    <td class="text-end">₹<?= (int)($row->advance_paid) ?></td>
                    <td><?= date('d M Y', strtotime($row->order_date)) ?></td>
                    <td><?= date('d M Y', strtotime($row->delivery_date)) ?></td>
                    <td class="text-center">
                        <span style="background:<?= $sc['bg'] ?>;color:<?= $sc['color'] ?>;padding:3px 10px;border-radius:12px;font-size:11px;font-weight:700;">
                            <?= $row->order_status ?>
                        </span>
                    </td>
                    <td class="text-center">
                        <a href="<?= site_url('tailoring_order/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('tailoring_order/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('tailoring_order/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="10" class="text-center py-4 text-muted">
                    No tailoring orders found. <a href="<?= site_url('tailoring_order/create') ?>">Add first order</a>
                </td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>