<div class="table-responsive responsiveTable">
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th><?= lang('item_name') ?></th>
                <th><?= lang('quantity') ?></th>
                <th><?= lang('unit') ?></th>
                <th><?= lang('priority') ?></th>
                <th><?= lang('current_stock') ?></th>
                <th><?= lang('min_stock') ?></th>
                <th><?= lang('request_date') ?></th>
                <th><?= lang('status') ?></th>
                <th><?= lang('action') ?></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($inventory_logs as $row): ?>
                <tr>
                    <td data-label="<?= lang('item_name'); ?>"><?= $row['item_name'] ?></td>
                    <td data-label="<?= lang('quantity'); ?>"><?= $row['quantity'] ?></td>
                    <td data-label="<?= lang('unit'); ?>"><?= $row['unit'] ?></td>
                    <td data-label="<?= lang('priority'); ?>">
                        <?php if ($row['priority'] == 'Urgent'): ?>
                            <label class="fz-14 label text-danger"><?= $row['priority'] ?></label>
                        <?php elseif ($row['priority'] == 'High Priority'): ?>
                            <label class="fz-14 label text-warning"><?= $row['priority'] ?></label>
                        <?php elseif ($row['priority'] == 'Normal'): ?>
                            <label class="fz-14 label text-success"><?= $row['priority'] ?></label>
                        <?php else: ?>
                            <label class="fz-14 label text-secondary"><?= $row['priority'] ?></label>
                        <?php endif; ?>
                    </td>
                    <td data-label="<?= lang('current_stock'); ?>"><?= $row['p_item_stock'] ?></td>
                    <td data-label="<?= lang('min_stock'); ?>">
                        <?= $row['item_min_stock'] ?>
                    </td>
                    <td data-label="<?= lang('request_date'); ?>"><?= full_time($row['created_at'], restaurant()->id) ?></td>
                    <td data-label="<?= lang('status'); ?>">
                        <?php if ($row['status'] == 'pending'): ?>
                            <span class="db__status label-primary"><i class="icofont-spinner"></i>&nbsp;<?= $row['status'] ?></span>
                        <?php elseif ($row['status'] == 'approved'): ?>
                            <span class="db__status label-success"><i class="fa fa-check"></i> <?= $row['status'] ?></span>
                        <?php else: ?>
                            <span class="db__status label-danger"><i class="fa fa-times"></i> <?= $row['status'] ?></span>
                        <?php endif; ?>

                        <div class="mt-5">
                            <?php if ($row['p_item_stock'] > $row['item_min_stock']): ?>
                                <small class="text-success">(<?= $row['p_item_stock'] . '' . $row['unit'] ?>) <?= lang('in_stock') ?></small>
                            <?php elseif ($row['p_item_stock'] == 0): ?>
                                <small class="text-danger"><?= lang('out_of_stock') ?></small>
                            <?php elseif ($row['p_item_stock'] <= $row['item_min_stock']): ?>
                                <small class="text-warning">(<?= $row['p_item_stock'] . '' . $row['unit'] ?>) <?= lang('limited_stock') ?></small>
                            <?php endif; ?>
                        </div>
                    </td>
                    <td data-label="<?= lang('action'); ?>">
                        <div class="stock_status_btn">
                            <select class="form-control request_select">

                                <?php if (!in_array($row['status'], ['canceled', 'approved'])): ?>
                                    <option <?= $row['status'] == 'pending' ? 'selected' : '' ?>
                                        value="<?= base_url('admin/inventory/request_status_change/' . $row['id'] . '/pending') ?>">
                                        <?= lang('pending') ?>
                                    </option>
                                <?php endif; ?>

                                <?php if ($row['status'] != 'canceled'): ?>
                                    <option <?= $row['status'] == 'approved' ? 'selected' : '' ?> value="<?= base_url('admin/inventory/request_status_change/' . $row['id'] . '/' . 'approved') ?>"><?= lang('approve') ?></option>
                                <?php endif; ?>

                                <option <?= $row['status'] == 'canceled' ? 'selected' : '' ?> value="<?= base_url('admin/inventory/request_status_change/' . $row['id'] . '/' . 'canceled') ?>"><?= lang('cancel') ?></option>
                            </select>
                        </div>
                    </td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>