<?php
ini_set('display_errors', 0); error_reporting(0);
require_once 'functions.php';
checkAuth();

$q = $_GET['q'] ?? '';
$q = function_exists('mb_substr') ? mb_substr(trim($q), 0, 100, 'UTF-8') : substr(trim($q), 0, 100);
if ((function_exists('mb_strlen') ? mb_strlen($q, 'UTF-8') : strlen($q)) < 3) {
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode([]);
    exit;
}

set_time_limit(30); 
$results = searchAllMegaFolders($q);

header('Content-Type: application/json; charset=utf-8');
echo json_encode($results);
