<?php
namespace Claromentis\Search\Controller;

$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_dd9cad65256ae" . "f406230e3f5ac1" . "65066" => base64_decode("c2VhcmNoX3" . "Byb21wdC52" . "aXNpYmxl"), "_6177aeb22c860" . "fcf2344b3d9d78" . "8fd0e" => base64_decode("c2Vhcm" . "NoX292" . "ZXJ2aW" . "V3"), "templ" . "ate" => base64_decode("dGVtcGxhd" . "GU="), "_fd5ef486365e07a7ea2dbcaa40d" . "15061" => base64_decode("YWlfc2VhcmNoX292ZXJ2aWV3LnNlYXJ" . "jaF9oYXNo"), "_9ae9318e64a" . "9503d48fe207" . "7b7441416" => base64_decode("c2VhcmNo" . "X2Zvcm0u" . "YWN0aW9u"), "_0c5123aa74" . "4f69bbc0e8b" . "3ea2f6e847d" => base64_decode("bG1" . "zZw" . "=="), "_62ddceb8208d1e7" . "44736030d4017cc0" . "5" => base64_decode("cmVkaXJlY" . "3Q="), "_678d945258a" . "520c3df1c42f" . "e4b558f34" => base64_decode("cGFnZV90aX" . "RsZQ=="), "_51ab3ea673fd9fb421dbbf9b72" . "fc21c6" => base64_decode("c2VhcmNoL2luZGV4" . "Lmh0bWw="), "sear" . "ch" => base64_decode("c2Vh" . "cmNo"), "is_error" . "_message" => base64_decode("aXNfZXJyb3JfbWVzc2" . "FnZQ=="), "_6fc9a83ab40b434d1e09977528" . "fe1ad0" => base64_decode("YWlfc2VhcmNoX292ZX" . "J2aWV3LnZpc2libGU="), "_660c1ff5691" . "112228db1364" . "e71c11458" => base64_decode("c2VhcmNoLnNlYXJjaF" . "90aXRsZQ=="), "_1163b61bcfa09a51abed581e52" . "8009b4" => base64_decode("YXBwbGljYXRpb25" . "fc2VhcmNoX3VpLm" . "tleXdvcmRz"), "page_siz" . "e" => base64_decode("cGFnZV9" . "zaXpl"), "_ab3ad95c56db2afae5c" . "1da39e5507781" => base64_decode("ZW5hYmxlX3VzZX" . "Jfc3VnZ2VzdGlv" . "bnM="), "_00e04eeec0a0a6f1840507958" . "d784780" => base64_decode("c2hvd19yZWNl" . "bnRfbGlrZQ=="), "_a80dcf9ba08" . "c5ceffb37f74" . "cb2ff9e88" => base64_decode("c3VibWl0X3N1Z2dlc3Rpb25fd" . "mlzaWJsZS52aXNpYmxl"), "_da5f12b06a" . "5057b16ed37" . "4f062b3fd71" => base64_decode("c2VhcmNoaW5nX2d1aWRlX3Rv" . "b2x0aXAudGl0bGU="), "_164394e73b7c6e7496aed6d" . "8db11ff82" => base64_decode("cmVjZW50X3NlYXJjaGVzX3VpLnBhcmFtZXRlcnM" . "="), "_22b7c52902d357e7d62e416" . "231bf4ece" => base64_decode("cmVjZW50X3NlYXJjaGVzX3Zp" . "c2libGUudmlzaWJsZQ=="), "_9dcd5331d86e108e9b83d56421" . "5671e3" => base64_decode("Ly4uLy4uL3hhamF4" . "X3NlcnZlci5waHA="), "_4d707fab93bebb00" . "bbe69e8159697c90" => base64_decode(""), "_cdf48e331bc4c489c7af5e" . "057b5e4df9" => base64_decode("c2hvd19yZXN1bHRzLnZp" . "c2libGU="), "_e7087785356ff19e44107a114d" . "47f987" => base64_decode("Y29tbW9uX3NlYXJjaA" . "=="), "_535788bf7b9d183654" . "4192d74e6746f7" => base64_decode("S2V5d" . "29yZH" . "M6IA=" . "="), "a" . "r" . "g" . "s" => base64_decode("YX" . "Jn" . "cw" . "=="), "_f55fdd4d4d7e39a8352" . "438e6453a3feb" => base64_decode("cmVjZW50X3N" . "lYXJjaGVzX3" . "VpLnVybF9id" . "WlsZGVy"), "_be4c9831c56fffb653ef" . "ea93b46ad105" => base64_decode("c2VhcmNoLnN" . "lYXJjaGluZ1" . "9ndWlkZQ=="), "messag" . "e" => base64_decode("bWVzc2F" . "nZQ=="));
use ClaAudit;
use Claromentis\Core\Ai\Ai;
use Claromentis\Core\Application;
use Claromentis\Core\Http\gpc;
use Claromentis\Core\Http\RedirectResponse;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Search\EmptySearch\Repository\EmptySearchRepository;
use Psr\Http\Message\ServerRequestInterface as Request;
use Claromentis\Search\Config;
use Claromentis\Search\GlobalSearchDialog;
use Claromentis\Search\History\HistoryFacade;
use Claromentis\Search\HttpInterop\StandardQueryString;
use Claromentis\Search\HttpInterop\UrlBuilderInterface;
use Claromentis\Search\Parameters;
use Claromentis\Search\ResultView;
use Claromentis\Search\Search;
use Claromentis\Search\Suggestions\Views\DisplaySuggestionsView;
use Claromentis\Core\Config\Config as CoreConfig;




class GlobalSearchController
{
    
    
    
    
    protected $result = array();
    
    
    
    
    protected $url_builder;
    
    
    
    
    protected $empty_search_repository;
    
    
    
    
    
    
    public function __construct(EmptySearchRepository $empty_search_repository)
    {
        $this->result = array($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["arg" . "s"] => array(), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_678d945258" . "a520c3df1c4" . "2fe4b558f34"] => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_0c5123aa7" . "44f69bbc0e" . "8b3ea2f6e8" . "47d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_660c1ff" . "56911122" . "28db1364" . "e71c1145" . "8"]), $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["te" . "mp" . "la" . "te"] => $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_51ab3ea673fd9fb421dbbf9b72fc" . "21c6"]);
        $this->url_builder = new StandardQueryString();
        $this->empty_search_repository = $empty_search_repository;
    }
    public function Show(Application $app, Request $request, Ai $ai)
    {
        $result = $this->Run($app, $request, $ai);
        return static::ProcessResultArray($result);
    }
    
    
    
    
    
    
    
    
    
    public function Run(Application $app, Request $request, Ai $ai)
    {
        $args = $this->result[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["ar" . "gs"]];
        $_17b6edaaad6516b211c9017df5e98d83 = $this->GetUISettings();
        $sp = new Parameters();
        $sp->SetFuzzy(true);
        $_94aee9abc156b50b0a00cf95c1660154 = $this->GetSearchForm($sp);
        $_94aee9abc156b50b0a00cf95c1660154->Update($request);
        $args[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_a80dcf9ba08c5cef" . "fb37f74cb2ff9e88"]] = 0;
        if (!$sp->IsEmpty()) {
            if ($sp->GetStart() == 0 && $sp->GetKeywords() != $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_4d707fab93bebb00bbe69e" . "8159697c90"]) {
                ClaAudit::Store(AUDIT_SUCCESS, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["sea" . "rch"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_e7087785356ff19e44107a114d4" . "7f987"], null, $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_535788bf7b9d1836544192d7" . "4e6746f7"] . $sp->GetKeywords());
            }
            $search = new Search();
            $search->SetUrlBuilder($this->url_builder);
            if ($ai->isModuleEnabled($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["searc" . "h"]) && $sp->GetKeywords() !== $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_4d707fab" . "93bebb00b" . "be69e8159" . "697c90"]) {
                $_f6435639088ceb6622480409bfdf8fb7 = $ai->generateTextEmbedding($sp->GetKeywords());
                $sp->setVectorSearchEnabled(true);
                $sp->SetVectorKeywords($_f6435639088ceb6622480409bfdf8fb7);
            }
            if ($ai->isModuleEnabled($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_6177aeb22c860fcf2344" . "b3d9d788fd0e"])) {
                $sp->SetCacheResult(true);
            }
            $_062f61fa774258f6a1d2623f00210ef3 = $search->Execute($sp);
            
            
            $this->empty_search_repository->SaveEmptySearch($app->security, $sp, $_062f61fa774258f6a1d2623f00210ef3);
            $_8341860084541a8daa06f8c6ad9398e1 = new ResultView($_062f61fa774258f6a1d2623f00210ef3);
            $args = $_8341860084541a8daa06f8c6ad9398e1->Show() + $args;
            if ($sp->GetStart() === 0) {
                HistoryFacade::CreateDefault()->Add($sp, $_062f61fa774258f6a1d2623f00210ef3);
            }
            if ($_17b6edaaad6516b211c9017df5e98d83[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_00e04eeec0a0a6f184050795" . "8d784780"]]) {
                $args[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_164394e73b7c6e7" . "496aed6d8db11ff8" . "2"]] = $sp;
                $args[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_f55fdd4d4d7e39" . "a8352438e6453a3" . "feb"]] = $this->url_builder;
            } else {
                $args[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_22b7c52" . "902d357e" . "7d62e416" . "231bf4ec" . "e"]] = 0;
            }
            
            
            $keywords = $sp->GetKeywords();
            $_acd4f661d81d67c1251e2ab970297a9f = new DisplaySuggestionsView();
            $args = $_acd4f661d81d67c1251e2ab970297a9f->Show($keywords, $this->url_builder) + $args;
            
            
            if ($_17b6edaaad6516b211c9017df5e98d83[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_ab3ad95c56db2afae5c1da39e55077" . "81"]]) {
                $args[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_a80dcf9ba08c" . "5ceffb37f74cb" . "2ff9e88"]] = 1;
                
                
                $_61ddd137a242bb910576e5aa44991ada = $args;
                ${$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["arg" . "s"]} =& $args;
                require __DIR__ . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_9dcd5331d86e108e9b83" . "d564215671e3"];
                $args = $_61ddd137a242bb910576e5aa44991ada + $args;
            }
            
            
            $args[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_1163b61bcfa09a51abed581e528009b" . "4"]] = $keywords;
        } else {
            $args[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_cdf48e331bc4c489c7a" . "f5e057b5e4df9"]] = false;
            $args[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_dd9cad65256aef406230e3f" . "5ac165066"]] = 1;
        }
        $args[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_da5f12b06a5057b16ed374f062b3fd7" . "1"]] = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_0c5123aa744f69bbc0" . "e8b3ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_be4c9831c56fff" . "b653efea93b46ad" . "105"]);
        $args[$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_6fc9a83a" . "b40b434d1" . "e09977528" . "fe1ad0"]] = $sp->GetStart() < $sp->GetPagesize();
        $args[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_fd5ef486365e07a7ea" . "2dbcaa40d15061"]] = $sp->GetHash();
        $args = $_94aee9abc156b50b0a00cf95c1660154->Show() + $args;
        $args[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_9ae9318e64a9503d48fe2077b74" . "41416"]] = gpc::getRequestPath($request);
        $this->result[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["ar" . "gs"]] = $args + $this->result[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["arg" . "s"]];
        return $this->result;
    }
    
    
    
    
    protected function GetUISettings()
    {
        $_17b6edaaad6516b211c9017df5e98d83 = new Config\UserInterfaceSettings();
        return $_17b6edaaad6516b211c9017df5e98d83;
    }
    
    
    
    
    
    
    protected function GetSearchForm($sp)
    {
        $_17b6edaaad6516b211c9017df5e98d83 = $this->GetUISettings();
        $_f63a9d5cd180b0593c6b314728f8bb23 = new Config\Applications();
        $_0daae353ac9fab3e5fa2c17593c01a68 = $_f63a9d5cd180b0593c6b314728f8bb23->GetSelectedAll();
        $_03137a93e6b1a3658dc69ba6926b402f = $_f63a9d5cd180b0593c6b314728f8bb23->AppsToTypes($_0daae353ac9fab3e5fa2c17593c01a68);
        $_94aee9abc156b50b0a00cf95c1660154 = new GlobalSearchDialog($sp);
        $_94aee9abc156b50b0a00cf95c1660154->SetDefaultPageSize($_17b6edaaad6516b211c9017df5e98d83[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["page_siz" . "e"]]);
        $_94aee9abc156b50b0a00cf95c1660154->SetDefaultObjTypes($_03137a93e6b1a3658dc69ba6926b402f);
        return $_94aee9abc156b50b0a00cf95c1660154;
    }
    
    
    
    
    
    
    
    public static function ProcessResultArray(array $result, $message = '', $is_error_message = false)
    {
        $message = isset($result[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["messa" . "ge"]]) ? $result[$GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["messa" . "ge"]] : $message;
        $is_error_message = isset($result[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["is_error_" . "message"]]) ? $result[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["is_error_mes" . "sage"]] : $is_error_message;
        if (isset($result[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_62ddceb8208d1e7" . "44736030d4017cc0" . "5"]])) {
            return RedirectResponse::httpRedirect($result[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_62ddceb8208d1e" . "744736030d4017c" . "c05"]], $message, $is_error_message);
        }
        $template = $result[$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["templ" . "ate"]];
        $_678d945258a520c3df1c42fe4b558f34 = $result[$GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_678d945258a520c3df1c42fe4b5" . "58f34"]];
        $args = isset($result[$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["ar" . "gs"]]) ? $result[$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["arg" . "s"]] : [];
        $response = new TemplaterCallResponse($template, $args, $_678d945258a520c3df1c42fe4b558f34);
        $response->SetMessage($message, $is_error_message);
        return $response;
    }
}