<?php
include "../../classes/db.class.php";

$db = new DBMain();

$where_data = [];

$tool_name = $_GET['tool_name'];
if ($tool_name >= 1) {
    $where_data[] = "tool_name = " . $tool_name . "";
}

$brand = $_GET['brand'];
if ($brand >= 1 && $brand != "Brand") {
    $where_data[] = "brand = " . $brand;
}

$qr_code = $_GET['qr_code'];
if (strlen($qr_code) >= 1) {
    $where_data[] = "qr_code LIKE '%" . $qr_code . "%'";
}

$category = $_GET['category_id'];
if ($category >= 1) {
    $where_data[] = "category_id = " . $category . "";
}

if (count($where_data) > 0) {
    $where = " WHERE " . implode(" AND ", $where_data);
} else {
    $where = " WHERE 1";
}
// echo "SELECT * FROM `tools` $where ORDER BY record_id DESC";
$result = $db->conn->query("SELECT * FROM `tools` $where ORDER BY record_id DESC");
if ($result->num_rows > 0) {
    while ($data = $result->fetch_assoc()) {

        echo "

        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
            <div class='flex_container'>
                <div class='flex_container_content'>
                    <input type='text' readonly value='$data[name]' />
                    <input type='text' readonly value='$data[brand]' />
                </div>
                <div class='flex_container_content'>
                    <input type='text' readonly value='$data[qr_code]' />
                    <input type='text' readonly value='$data[category_id]' />
                </div>
            </div>
            <button onclick='edit_tools($data[record_id])' style='width:100%; background-color: white;' class='font_size_2vw'>SELECT</button>
        </div>
        
        ";
    }
} else {

    echo "        <div class='flex_container_content' style='box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) ;background-color: #145593; width:80%;padding: 10px;border-radius: 10px; margin-bottom: 10px; margin-left:auto; margin-right:auto; margin-top:2vw;'>
        <h1> NO RESULTS </h1>
        </div>";
}
