<?php
/**
 * Pro Features Helper
 * Checks whether Pro features are available (gating API for the Spin Wheel Pro add-on).
 *
 * @package Spin_Wheel
 */

// Exit if accessed directly
if (!defined('ABSPATH')) {
    exit;
}

/**
 * SWP_Pro_Helper Class
 */
// The "swp" hook prefix below is the plugin's established, documented extension
// API (shared with the Spin Wheel Pro add-on) and is kept for compatibility.
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals
class SWP_Pro_Helper {
    
    /**
     * Check if pro plugin is active
     *
     * @return bool
     */
    public static function is_pro_active() {
        return apply_filters('swp_is_pro_active', false);
    }
    
    /**
     * Check if specific feature is enabled
     *
     * @param string $feature Feature key
     * @return bool
     */
    public static function is_feature_enabled($feature) {
        $feature_map = [
            'event_mode' => 'swp_enable_event_mode',
            'prize_images' => 'swp_enable_prize_images',
            'entry_restrictions' => 'swp_enable_entry_restrictions',
            'animations' => 'swp_enable_animations',
            'participant_limit' => 'swp_enable_participant_limit',
            'display_modes' => 'swp_enable_display_modes',
            'presets' => 'swp_enable_presets',
            'form_advanced' => 'swp_enable_form_advanced',
            'otp_verification' => 'swp_enable_otp_verification',
            'recaptcha' => 'swp_enable_recaptcha',
            'rate_limiting' => 'swp_enable_rate_limiting',
            'vpn_blocking' => 'swp_enable_vpn_blocking',
            'sound_effects' => 'swp_enable_sound_effects',
            'database_management' => 'swp_enable_database_management',
            'crm' => 'swp_enable_crm',
            'utm_tracking' => 'swp_enable_utm_tracking',
        ];

        if (!isset($feature_map[$feature])) {
            return false;
        }

        // Every Pro feature is gated behind its own filter, which the Spin Wheel
        // Pro add-on enables when it is active and licensed. Without Pro the
        // feature is off and its implementation is not present in this plugin.
        return apply_filters($feature_map[$feature], false);
    }

    /**
     * Pro feature badge.
     *
     * Retained as part of the extension API (the Spin Wheel Pro add-on calls it).
     * The free plugin renders no upsell badge, so this always returns an empty string.
     *
     * @return string
     */
    public static function get_pro_badge() {
        return '';
    }

/**
 * License Validation
 */
	public static function sw_license_validation() {

		if (false === self::is_pro_active()) {
			return false;
		}
        
        $license_key = get_option( \SPIN_WHEEL_PRO\License\License::get_lic_key_param( 'swp_pro_lic_key' ) );

		if (isset($license_key) && ! empty($license_key)) {
			return true;
		} else {
			return false;
		}
		return false;
	}
}

// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals
