<?php

use Mnv\Core\Locale\I18N;
use Mnv\Modules\Search;

require_once "../includes/visitor.inc.php";

if (request()->ajax()) {

    $query = request('query', '');
    $response = [];

    $search = new Search();
    $search->products($query);


    if (!empty($search->products)) {
        $response = array('status' => 200, 'message' => I18N::locale("По Вашему запросу найдено...", "Sizning so'rovingiz bo'yicha topildi...", "Found by your request..."), 'products' =>  $search->products);
    } else {
        $response = array('status' => 200, 'message' =>  I18N::locale("По Вашему запросу ничего не найдено...", "Sizning so'rovingiz bo'yicha hech narsa topilmadi...", "Nothing was found for your query..."), 'products' => $search->products);
    }

    return response()->json($response, \Mnv\Http\Response::HTTP_OK, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)->send();

} else {
    die('Hacking attempt!');
}