<link href="/css/pages/search.css" rel="stylesheet">

<div id="page_search" class="container h-100">
    <div class="row py-3">
        <nav class="col-3">
            <div class="p-3 rounded">

            </div>
        </nav>
        <article class="col-9">
            <div class="row mx-0 p-3 rounded">
                <?php
                if (isset($timer) && $timer > 0) {
                    echo  <<<HTML
                        <div class="d-flex flex-column mx-auto">
                            <p class="px-2 mb-1 text-center d-flex justify-content-center">Слишком частые запросы, повторите попытку через: $timer секунд</p>
                            <small class="mb-3 text-center d-flex justify-content-center">Подождите или нажмите на кнопку вручную</small>
                            <a class="btn text-white button_clean button_blue mx-auto" onclick="window.location.reload();">Повторить</a>
                        </div>
                        <script type="text/javascript">
                            setTimeout('window.location.reload()', $timer + '000');
                        </script>
                    HTML;
                } else {
                    if (isset($response) && is_array($response) && $response) {

                        $i = 0;
                        $amount = count($response);

                        foreach ($response as $row) {
                            $catn = $row['catn'];
                            $covr = $row['covr'] ?? '/img/covers/h150/product.png';
                            $amnt = $row['amnt'] ?? 1;


                            //     <button class="button_clean_full d-flex p-0">
                            //     <i class="fas fa-plus-square search_card_cart_icon my-auto"></i>
                            // </button>

                            echo <<<HTML
                                <div class="col-3 p-2 d-flex flex-column search_card rounded">
                                    <div class="col">
                                        <div class="row mb-2">
                                            <img class="w-100 img-fluid rounded" src="$covr"/>
                                        </div>
                                        <div class="row mb-2">
                                            <a class="mx-auto text-dark" href="/product/$catn"><h5 class="m-0">$catn</h5></a>
                                        </div>
                                        <div class="row px-2 mb-2">
                                            <small class="mt-auto">{$amnt}шт</small>
                                            <p class="mr-0">1000р</p>
                                        </div>
                                        <div class="row">
                                            <button class="btn button_grey button_clean w-100 text-white">В корзину</button>
                                        </div>
                                    </div>
                                </div>
                            HTML;

                            if (++$i % 4 === 0 && $amount - $i !== 0) {
                                echo <<<HTML
                                    <div class="dropdown-divider my-3 mx-4 w-100 "></div>
                                HTML;
                            }
                        }
                    } else {
                        echo <<<HTML
                            <div class="d-flex flex-column mx-auto">
                                <p class="m-0 py-2 d-flex justify-content-center">Ничего не найдено</p>
                            </div>
                        HTML;
                    }
                }
                ?>
            </div>
        </article>
    </div>
</div>