<?php
/**
 * Structure Viewer — Pro Gate
 *
 * Single entry point for all Pro features.
 * Called from structure-viewer.php when the user has an active Freemius
 * licence (guarded by can_use_premium_code__premium_only() in the main file).
 *
 * Adding a new Pro feature:
 *   1. Create a folder under pro/  (e.g. pro/BulkExport/)
 *   2. Add a require_once block below inside init()
 *   3. Register any hooks inside that feature's own class
 *      (or add them to SV_Plugin via a filter hook)
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit( 'Direct access denied.' );
}

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- SV_ is the established plugin prefix used consistently across all plugin classes.
final class SV_Pro {

    /**
     * Load all Pro feature files and boot each one.
     * Called once from structure-viewer.php, already inside the
     * can_use_premium_code__premium_only() check.
     */
    public static function init() {
        // ── Comparator ───────────────────────────────────────────────
        $comp_dir = __DIR__ . '/Comparator/';
        if ( is_dir( $comp_dir ) ) {
            require_once $comp_dir . 'file-handler.php';
            require_once $comp_dir . 'comparator.php';
            require_once $comp_dir . 'comparator-ajax.php';
            new SV_Pro_Comparator_Ajax();
            add_action( 'admin_init', [ 'SV_Pro_File_Handler', 'ensure_upload_dir' ] );
        }

        // ── FlatPack ─────────────────────────────────────────────────
        $fp_dir = __DIR__ . '/FlatPack/';
        if ( is_dir( $fp_dir ) ) {
            require_once $fp_dir . 'flatpack.php';
            require_once $fp_dir . 'flatpack-ajax.php';
            new SV_Pro_FlatPack_Ajax();
        }

        // ── Future Pro features ───────────────────────────────────────
        // Example: require_once __DIR__ . '/BulkExport/bulk-export.php';
        //          SV_Pro_BulkExport::init();
    }

    /**
     * Check whether Pro features are licensed and active.
     * Delegates to Freemius so the answer is always authoritative.
     *
     * @return bool
     */
    public static function is_active() {
        return function_exists( 'structureviewer_fs' ) && structureviewer_fs()->can_use_premium_code__premium_only();
    }
}