<?php

/**
 * Pro licensing gate.
 *
 * All Pro features gate on Pro::is_active().
 * Teasers gate on Pro::is_showing_teaser().
 *
 * IMPORTANT (Freemius free-build): the Freemius PHP preprocessor only strips
 * `if` blocks whose condition calls an SDK method with the `__premium_only`
 * suffix. Both methods below are structured so the premium branch is removed
 * from the Free build, leaving safe `return false;` / `return true;` stubs.
 *
 * @package Leadite
 */
namespace Leadite;

defined( 'ABSPATH' ) || exit;
class Pro {
    /**
     * Whether Pro features may run on this install.
     *
     * Premium build: true for an active trial or valid Freemius license.
     * Free (wp.org) build: always false (the premium branch is stripped).
     *
     * @return bool
     */
    public static function is_active() : bool {
        // Hard override for debugging/staging.
        if ( defined( 'leadite_PRO' ) && leadite_PRO ) {
            return true;
        }
        // Dev override (local dev / staging).
        if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE && defined( 'WP_FS__leadite_SECRET_KEY' ) ) {
            return true;
        }
        if ( \function_exists( 'leadite_fs' ) ) {
        }
        return false;
    }

    /**
     * Whether to show a Pro teaser/upsell to the current user.
     *
     * Premium build: never show teasers (is_premium() is true).
     * Free (wp.org) build: show teasers (premium branch stripped, falls
     * through to `return true;`).
     *
     * @return bool
     */
    public static function is_showing_teaser() : bool {
        if ( !\function_exists( 'leadite_fs' ) ) {
            // During very early boot, assume we might need a teaser unless we know we are Pro.
            return !(defined( 'leadite_PRO' ) && leadite_PRO);
        }
        // If this is the Premium build/copy of the plugin, don't show teasers.
        if ( \leadite_fs()->is_premium() ) {
            return false;
        }
        return true;
    }

    /**
     * Invalidate any cached Pro status.
     *
     * @return void
     */
    public static function invalidate_cache() : void {
        // No-op — kept for hook compatibility.
    }

}
