<?php
$usertype = profile();
if ($usertype->role_id == 3) {
    $warehouseList = $this->admin_model->select_data(
        'tbl_warehouse',
        'warehouse_id',
        'warehouse_name',
        array(
            'status' => 'published',
            'warehouse_id' => $this->session->userdata['warehouse_id'],
        )
    );
    $selected = $this->session->userdata['warehouse_id'];
} else {
    $warehouseList = $this->admin_model->select_data(
        'tbl_warehouse',
        'warehouse_id',
        'warehouse_name',
        array('status' => 'published')
    );
    $selected = !empty($warehouseID) ? $warehouseID : '';
}

$warehouse_class = !empty($warehouseID) ? $warehouseID : 'mwarehouse';
$warehouse_required = isset($warehouse_required) ? (bool) $warehouse_required : true;
$append = '';
if ($usertype->role_id == 1) {
    $append = '<a data-toggle="modal" data-target="#myModal_lg" href="' . base_url() . 'admin/warehouse/create/0/from_warehouse_id" class="inline-flex items-center text-slate-500 hover:text-slate-700 dark:text-slate-300 dark:hover:text-slate-100"><i data-lucide="plus" class="h-4 w-4"></i></a>';
}

echo form_select_group(
    'warehouse_id',
    lang('select') . ' ' . lang('warehouse'),
    !empty($warehouseList) ? $warehouseList : array(),
    $selected,
    $warehouse_required,
    array(
        'id' => 'warehouse',
        'class' => 'select_box ' . $warehouse_class,
        'onchange' => 'getItemByWarehouse(this.value)',
        'data-live-search' => true,
        'style' => 'width:100%',
    ),
    '',
    $append,
    'horizontal'
);
?>
<input type="hidden" name="warehouseId" class="<?= !empty($warehouseID) ? $warehouseID : 'WarehouseValue' ?>" value="<?= html_escape($selected) ?>">
