<?php

use NP\Factory as NpFactory;

// Activate the highlighter if enabled.
if (!empty($this->query->highlight) && $this->params->get('highlight_terms', 1)) {
    // Allow a maximum of 10 tokens to be highlighted. Otherwise the URL can get too long.
    $this->document->getWebAssetManager()->useScript('highlight');
    $this->document->addScriptOptions(
        'highlight',
        [[
            'class'      => 'js-highlight',
            'highLight'  => array_slice($this->query->highlight, 0, 10),
        ]]
    );
}
$results = !empty($this->results) && is_array($this->results) ? $this->results : array();
$data = array(
    'searchComponent' => $this,
    'query' => $this->query,
    'total' => $this->total,
    'params' => $this->params,
    'searchResults' => $results,
);

$page = NpFactory::getTemplate('search');
$page->setTemplateData($data);
$page->buildPageElements();
echo $page->getHtml();
