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

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

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

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