<?php
include "../../root.class.php";
$html = new html();
$html->add_styles_page();

// $html->check_user_type("ADMIN");
$stock = new input();
$stock->name("description");
$stock->id("description");
$stock->type("text");
$stock->placeholder("Descprition");
$stock->class("search_inputs");

$categories = new select();
$categories->name("category_id");
$categories->id("category_id");
$categories->class("search_inputs");
$categories->add_option("", "Category");
$categories->fill_from_db("stock_categories", "record_id", "name");

$stock_type = new select();
$stock_type->name("stock_type");
$stock_type->id("stock_type");
$stock_type->class("search_inputs");
$stock_type->add_option("", "Stock Type");
$stock_type->add_option("0", "STOCK");
$stock_type->add_option("1", "NON STOCK");
$stock_type->add_option("2", "UNITS");
// $suppliers = new select();
// $suppliers->name("supplier_id");
// $suppliers->id("supplier_id");
// $suppliers->class("search_inputs");
// $suppliers->add_option("", "Supplier");
// $suppliers->fill_from_db("suppliers", "record_id", "name");

$submit_btn = new button();
$submit_btn->id("submit");
$submit_btn->name("submit");
$submit_btn->value("SEARCH");
$submit_btn->class();
$submit_btn->style("color:black");
$submit_btn->onclick("goto();");
?>
<div class="search_form">
    <?php
    $stock->add();
    $categories->add();
    $stock_type->add();
    $submit_btn->add();
    ?>

</div>

<script>
    function goto() {
        var values = ["LOADING", "LOADING.", "LOADING..", "LOADING..."];
        var current_index = 0;
        var interval = setInterval(function () {
            document.getElementById('submit').innerHTML = values[current_index];
            current_index = (current_index + 1) % values.length;
        }, 500);
        description = document.getElementById('description').value;
        category_id = document.getElementById('category_id').value;
        stock_type = document.getElementById('stock_type').value;
        window.location.href = "stock_report.php?description=" + description + "&category_id=" + category_id + "&stock_type=" + stock_type;
    }
</script>