<?php

/**
 * Return the active, time-valid and visible info popups for the current
 * session user as lightweight metadata (id, editDate, maxWidth, maxHeight,
 * timeout).
 *
 * Public and must not be cached (user-dependent). The popup markup itself is
 * fetched per entry through getPopupHtml.
 *
 * @param string $projectName - project name
 * @param string $projectLanguage - project language
 * @return array<int, array<string, int>>
 */

use QUI\InfoPopup\Handler;

QUI::getAjax()->registerFunction(
    'package_quiqqer_info-popup_ajax_frontend_getActivePopups',
    function ($projectName, $projectLanguage) {
        try {
            $Project = QUI::getProject($projectName, $projectLanguage);
        } catch (QUI\Exception) {
            return [];
        }

        return Handler::getActiveEntries($Project, QUI::getUserBySession());
    },
    ['projectName', 'projectLanguage']
);
