<?php if (isset($page) && !in_array($page, ['Pos'])) { ?>
    <?php include 'inc/inventory_menu.php'; ?>
<?php } ?>

<div class="row">
    <div class="col-md-6">
        <div class="card mt-50">
            <form action="<?= base_url('admin/inventory/add_stock_requests') ?>" method="post">
                <?= csrf(); ?>
                <div class="card-header px-17 py-12">
                    <h3 class="card-title"><?= lang('stock_request') ?></h3>
                </div>
                <div class="card-body">

                    <div class="row">
                        <div class="form-group col-md-12">
                            <label for=""><?= lang('item') ?><span class="error">*</span></label>
                            <select name="item_id" class="form-control" required>
                                <?php foreach ($purchases_items as $row): ?>
                                    <?php $item = $this->admin_m->single_select_by_id($row['item_id'], 'vendor_inventory_purchases_items'); ?>
                                    <option value="<?= $item['id'] ?>"><?= $item['name'] ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                    </div> <!-- row -->

                    <div class="row">

                        <div class="form-group col-md-6">
                            <label for=""><?= lang('quantity_needed') ?><span class="error">*</span></label>
                            <input type="text" name="quantity_needed" class="form-control" placeholder="<?= lang('enter_quantity') ?>" required>
                        </div>
                        <div class="form-group col-md-6">
                            <label for=""><?= lang('unit') ?><span class="error">*</span></label>
                            <select name="unit" class="form-control" required>
                                <option value="pieces"><?= lang('pieces') ?></option>
                                <option value="boxs"><?= lang('boxs') ?></option>
                                <option value="packet"><?= lang('packet') ?></option>
                                <option value="bottle"><?= lang('bottle') ?></option>
                                <option value="kg"><?= lang('kg') ?></option>
                                <option value="gm"><?= lang('gm') ?></option>
                                <option value="liter"><?= lang('liter') ?></option>
                            </select>
                        </div>

                    </div>




                    <div class="form-group">
                        <label for=""><?= lang('priority') ?><span class="error">*</span></label>
                        <select name="priority" class="form-control" required>
                            <option value="normal"><?= lang('normal') ?></option>
                            <option value="high"><?= lang('high') ?></option>
                            <option value="urgent"><?= lang('urgent') ?></option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for=""><?= lang('notes') ?></label>
                        <textarea name="notes" class="form-control" cols="5" rows="3" placeholder="<?= lang('additional_notes') ?>"></textarea>
                    </div>

                    <div class="pt-5">
                        <input type="hidden" name="is_pos" value="<?= isset($is_pos) ? $is_pos : 0 ?>">
                        <button type="submit" class="btn btn-primary c_btn btn-flat"><i class="icofont-hand-drag1"></i>&nbsp;<?= lang('submit') ?></button>
                    </div>

                </div>
            </form>
        </div>
    </div>
    <div class="col-md-6">

        <div class="card-header mb-10">
            <h3 class="card-title"><?= lang('activities') ?></h3>
        </div>

        <?php foreach ($inventory_logs as $row): ?>
            <div class="card mb-10">
                <div class="callout pending_callout_box <?= str_slug($row['priority']) ?? ''; ?>">
                    <div class="top_content">
                        <h4><?= $row['quantity'] . $row['unit'] ?> <?= isset($row['item_name']) ? $row['item_name'] : '' ?></h4>
                        <?php if ($row['status'] == 'pending'): ?>
                            <span class="db__status bg-primary"><i class="icofont-spinner"></i>&nbsp;<?= $row['status'] ?></span>
                        <?php elseif ($row['status'] == 'approved'): ?>
                            <span class="db__status bg_success"><i class="fa fa-check"></i> <?= $row['status'] ?></span>
                        <?php else: ?>
                            <div class="d-flex gap-10">
                                <span class="db__status bg_danger"><?= $row['status'] ?></span>

                                <a href="<?= base_url('delete-item/' . html_escape($row['id']) . '/vendor_inventory_logs'); ?>" class="text-danger action_btn" data-msg="<?= !empty(lang('want_to_delete')) ? lang('want_to_delete') : "Want to Delete?"; ?>"><i class="fa fa-trash"></i> <?= !empty(lang('delete')) ? lang('delete') : "Delete"; ?></a>
                            </div>
                        <?php endif; ?>
                    </div>
                    <h5><?= $row['status'] == 'pending' ? lang('pending_requests') : ""; ?>
                        <?php if ($row['status'] == 'pending'): ?><label class="label bg-info-soft"><?= get_time_ago($row['created_at']) ?></label> <?php else: ?><label class="label bg-primary-soft"><?= full_time($row['created_at'], restaurant()->id) ?> <?php endif; ?></h5>
                    <div class="mt-18">
                        <?php if ($row['priority'] == 'High Priority'): ?>
                            <span class="status bg-yellow"><?= $row['priority'] ?></span>
                        <?php elseif ($row['priority'] == 'Normal'): ?>
                            <span class="status btn-secondary"><?= $row['priority'] ?></span>
                        <?php else: ?>
                            <span class="status label-danger"><?= $row['priority'] ?></span>
                        <?php endif; ?>
                    </div>
                    <?php if (!empty($row['notes'])): ?>
                        <p class="mt-10 fz-12 text-muted"><?= __('notes'); ?>: <?= $row['notes'] ?></p>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; ?>

    </div>
</div>