<?php
if(!$sf_request->isXmlHttpRequest()){
    slot('title', __('Поиск'));
    include_partial('main/breadcrumbs');
    echo '<h1 class="content_title">' . __('Поиск') . '</h1>';
    echo '<div class="search_wrap">';
    echo '<div class="search_line">
        <form action="' . url_for('@search') . '" method="get">
          <input class="search_line__inp" type="text" name="q" value="' . (isset($_GET['q']) ? htmlspecialchars($_GET['q']) : '') . '" placeholder="' . __('Поиск') . '" />
        </form>
      </div>';
    echo '<div class="search_result">';
}
if (!empty($query)) {
    //print_r($total_found);

    if ($total_found > 0) {
        $crs = $rs->getRaw(0);
        if (isset($crs['product']) && count($crs['product']) > 0) {
            foreach ($crs['product'] as $product) {
                echo '<div class="search_result__item">';
                echo '<div class="search_result__item__cat">' . __('Товар') . '</div>';
                echo '<a href="' . url_for($product['link']) . '" class="search_result__item__link search_result__item__link_product">' . $product['title'] . '</a>';
                echo '</div>';
            }
        }
        if (isset($crs['cat']) && count($crs['cat']) > 0) {
            foreach ($crs['cat'] as $cat) {
                echo '<div class="search_result__item">';
                echo '<div class="search_result__item__cat">' . __('Категории') . '</div>';
                echo '<a href="' . url_for($cat['link']) . '" class="search_result__item__link search_result__item__link_cat">' . $cat['title'] . '</a>';
                echo '</div>';
            }
        }
        if (isset($crs['article']) && count($crs['article']) > 0) {
            foreach ($crs['article'] as $article) {
                echo '<div class="search_result__item">';
                echo '<div class="search_result__item__cat">' . __('Статья') . '</div>';
                echo '<a href="' . url_for($article['link']) . '" class="search_result__item__link search_result__item__link_article">' . $article['title'] . '</a>';
                echo '</div>';
            }
        }
        if (isset($crs['video']) && count($crs['video']) > 0) {
            foreach ($crs['video'] as $video) {
                echo '<div class="search_result__item">';
                echo '<div class="search_result__item__cat">' . __('Видео') . '</div>';
                echo '<a data-src="' . $video['link'] . '" class="search_result__item__link search_result__item__link_video" onclick="video.open(this);">' . $video['title'] . '</a>';
                echo '</div>';
            }
        }

    } else {
        echo '<div class="i">' . __('Ничего не найдено') . '</div>';
    }
} else {
    echo '<div class="i">' . __('Пустой поисковый запрос') . '</div>';
}
if(!$sf_request->isXmlHttpRequest()){
    echo '</div>';
    echo '</div>';
}
?>