<?php

include "../../classes/app.class.php";
$app = new app();
$db = new DBMain();
?>

<div class='container flex_container'>
    <h1>SEARCH STOCK BY:</h1>
    <div class="container flex_container" style='border: 1px solid black; width:80%;padding: 10px;border-radius: 10px;'>

        <div class='flex_container_content'>
        <label>UserID</label>
            <select id='user_id' style='font-size:1vw;'>
                    <option>User ID</option>
                    <?php echo $db->get_names_in_user() ?>
                </select>
            <label>NAME</label>
            <input type='text' id='stock_name' placeholder='Name'>
            <input type='text' id='qr_code' placeholder='QR Code'>
        </div>
        <br>
        <div class='flex_container_content'>
            <label>SHELF</label>
                <select id='stock_shelf' style='font-size:1vw;'>
                    <option>SHELF</option>
                    <?php echo $db->get_names_in_shelf() ?>
                </select>
            <label>ROW</label>
                <select id='stock_row' style='font-size:1vw;'>
                    <option>ROW</option>
                    <?php echo $db->get_names_in_row() ?>
                </select>
            <label>DATE</label>
            <input type='date' id='date' placeholder='Date'>
                <select id='category' name='category' style='font-size:1vw;'>
                    <option>CATEGORY</option>
                    <?php echo $db->get_tool_category_list() ?>
                </select>
        </div>
    </div>
        <br>
        <button onclick="search_stock()" class='font_size_2vw'>SEARCH</button>
</div>

<div class='flex_container' id='stock_content'>

</div>

<script>
    function search_stock() {

        user_id = document.getElementById('user_id').value;
        name = document.getElementById('stock_name').value;
        qr_code = document.getElementById('qr_code').value;
        shelf = document.getElementById('stock_shelf').value;
        row = document.getElementById('stock_row').value;
        date = document.getElementById('date').value;
        category = document.getElementById('category').value;

        var xhttp = new XMLHttpRequest();
        xhttp.onload = function() {
            console.log(this.responseText);
            document.getElementById('stock_content').innerHTML = this.responseText;
        }
        xhttp.open("GET", '../../ajax/stock/search_stock.php?name=' + name + '&qr_code=' + qr_code + '&shelf=' + shelf + '&row=' + row  + '&category_id=' + category);
        xhttp.send();
    }

    function edit_stock($id) {
        window.location.href = 'edit_stock.php?record_id=' + $id;
    }
</script>