<?php
// pages/components/license_check.php
// Async license check to avoid blocking the main page load.

global $connection_cache, $connection_cache_ts;

if (function_exists('mh_cloudbeez_check') && isset($connection_cache) && isset($connection_cache_ts)) {
    // We use a shorter TTL here because this is async and we want to ensure license status is relatively fresh.
    // legacy reconnect_delay is 5 mins, so we use 5 mins here too.
    if (class_exists('mailbeez_cache')) {
        $cache = new \mailbeez_cache();
        $cache->app_cache_time = 300;
        $cache->set_cache_id('mh_cloudbeez_check', 'license');
        $cached = $cache->read_cache('app');
        if (!is_array($cached) || !isset($cached['value'])) {
            try {
                $result = mh_cloudbeez_check($connection_cache, $connection_cache_ts);
                $cache->set_cache($result, 'app');
            } catch (\Throwable $e) {
                // ignore
            }
        }
    } else {
        mh_cloudbeez_check($connection_cache, $connection_cache_ts);
    }
}
// This endpoint returns nothing.
exit;
