<?php

namespace PhotoSphereViewer\Includes;

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Single source of truth for detecting whether the Pro add-on is active.
 *
 * Accepts either detection strategy used across the codebase:
 *  - The constant defined at the top of photo-sphere-viewer-pro.php
 *  - The main Pro plugin class (loaded before any widget/shortcode runs)
 */
final class ProStatus {

    /** @var bool|null Cached result so the check runs at most once per request. */
    private static $active = null;

    public static function is_active(): bool {
        if (self::$active === null) {
            self::$active = defined('PHOTO_SPHERE_VIEWER_PRO_VERSION')
                || class_exists('PhotoSphereViewerPro\\Plugin');
        }
        return self::$active;
    }

    /**
     * Allow test suites to reset the cached state between tests.
     * Not called in production code.
     */
    public static function reset_cache(): void {
        self::$active = null;
    }
}
