<?php
/**
 * Pro module loader. Instantiates Pro feature classes only when the license
 * is active, and provides UI helpers for upsell prompts on the Free tier.
 *
 * Pro classes live in the same `includes/` folder behind the `Seoforge_Pro_*`
 * namespace prefix and self-register via `register( $loader )`.
 *
 * @package Brainwerk SEO Suite
 */

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

class Seoforge_Pro {

    /**
     * Pro modules and the file they live in.
     *
     * Filenames carry the `__premium_only` suffix so the Freemius deployment
     * tool strips them automatically from the Free build that ships to
     * WordPress.org.
     */
    private static $modules = array(
        'Seoforge_Pro_Geo'           => 'class-seoforge-pro-geo__premium_only.php',
        'Seoforge_Pro_Webhooks'      => 'class-seoforge-pro-webhooks__premium_only.php',
        'Seoforge_Pro_Anomaly'       => 'class-seoforge-pro-anomaly__premium_only.php',
        'Seoforge_Pro_Search_Console'=> 'class-seoforge-pro-search-console__premium_only.php',
        'Seoforge_Pro_Report'        => 'class-seoforge-pro-report__premium_only.php',
        'Seoforge_Pro_Pdf'           => 'class-seoforge-pro-pdf__premium_only.php',
    );

    public static function register( Seoforge_Loader $loader ) {
        if ( ! Seoforge_License::is_pro() ) {
            return;
        }
        foreach ( self::$modules as $class => $file ) {
            $path = SEOFORGE_PATH . 'includes/' . $file;
            if ( file_exists( $path ) ) {
                require_once $path;
                if ( class_exists( $class ) && method_exists( $class, 'register' ) ) {
                    call_user_func( array( $class, 'register' ), $loader );
                }
            }
        }
    }

    /**
     * Renders an upsell banner. Returns markup; caller decides where it goes.
     */
    public static function upsell( $feature_label, $blurb = '' ) {
        if ( Seoforge_License::is_pro() ) {
            return '';
        }
        ob_start();
        ?>
        <div class="seoforge-card seoforge-upsell">
            <h3><?php
                printf(
                    /* translators: %s feature name */
                    esc_html__( '✨ %s — Pro feature', 'brainwerk-seo-suite' ),
                    esc_html( $feature_label )
                );
            ?></h3>
            <?php if ( $blurb ) : ?>
                <p><?php echo esc_html( $blurb ); ?></p>
            <?php endif; ?>
            <p>
                <a class="button button-primary" href="https://seoforge.brainwerk.at/" target="_blank" rel="noopener">
                    <?php esc_html_e( 'See Brainwerk SEO Suite Pro plans →', 'brainwerk-seo-suite' ); ?>
                </a>
                &nbsp;
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=brainwerk-seo-suite&tab=license' ) ); ?>">
                    <?php esc_html_e( 'I already have a license key', 'brainwerk-seo-suite' ); ?>
                </a>
            </p>
        </div>
        <?php
        return ob_get_clean();
    }
}
