<?php

/**
 * Return the complete, server-rendered markup of a single info popup.
 *
 * Public and must re-check the active / time / visibility gate for the
 * session user (never leak the content of a hidden entry by id).
 *
 * @param int $id - entry id
 * @param string $projectName - project name
 * @param string $projectLanguage - project language
 * @return string - popup markup or '' when the entry must not be shown
 */

use QUI\InfoPopup\Handler;

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

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