<?php
if (!defined('ABSPATH')) exit;

function searchshifter_get_current_plan() {
    if ( class_exists( 'SS_Licensing' ) ) {
        return strtolower( SS_Licensing::plan() );
    }
    return 'free';
}

function searchshifter_has_plan( $required_plan ) {

    $levels = [
        'free'      => 1,
        'pro'       => 2,
        'authority' => 3,
        'elite'     => 4
    ];

    $current = searchshifter_get_current_plan();

    if ( ! isset($levels[$current]) || ! isset($levels[$required_plan]) ) {
        return false;
    }

    return $levels[$current] >= $levels[$required_plan];
}

// Legacy alias
function ss_get_current_plan() {
    return searchshifter_get_current_plan();
}

function searchshifter_locked_field_message($required_plan = 'pro') {
    $link = 'https://searchshifter.ai/pricing/';

    echo '<div style="padding:10px;border:1px solid #ddd;background:#f9f9f9;border-radius:6px;margin-top:8px;">
            <strong>Locked Feature</strong><br>
            This feature require <strong>' . esc_html( ucfirst( $required_plan ) ) . '</strong> plan.<br>
            <a href="' . esc_url( $link ) . '" target="_blank" style="color:#2271b1;font-weight:600;">Upgrade Now →</a>
        </div>';
}

// Legacy alias
function ss_locked_field_message( $required_plan = 'pro' ) {
    searchshifter_locked_field_message( $required_plan );
}