<?php
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

if (!defined('NICKELBOX')) {
    die("Direct access denied.");
}
$query = $_GET['q'];

$dbitems = $binstack->select('items', 'itemid', [
    'AND' => [
        'price[>]' => 0,
        'OR' => [
            'name[~]' => $query,
            'code1' => $query,
            'code2' => $query,
            'text1[~]' => $query
        ]
    ], 'LIMIT' => 20]);

$items = [];

foreach ($dbitems as $i) {
    $items[] = new Item($i);
}
?>
<div class="container mt-4">
    <h1 class="display-4">Search <span class="h3 ml-3 d-none"><?php echo htmlspecialchars($query); ?></span></h1>

    <div class="list-group list-group-flush">
        <?php
        if (count($items) > 0) {
            foreach ($items as $i) {
                echo RenderItem::line($i);
            }
        } else {
            ?>
            <p>No results found for <?php echo htmlspecialchars($query); ?>.</p>
            <?php
        }
        ?>
    </div>
</div>