<?php

declare(strict_types=1);

namespace Numinix\SeekmodoWordPress\WPBakery;

/**
 * Sprint 11 PR 3 — WPBakery / Visual Composer integration loader.
 *
 * Two-tier registration:
 *
 *   1. {@see Shortcodes::register()} runs **unconditionally** on
 *      every site. The `[seekmodo_*]` shortcodes are useful even
 *      without WPBakery — a site author can drop them into a
 *      classic-editor post or a theme template directly.
 *
 *   2. {@see VcMap::register()} runs **only** when WPBakery is
 *      active (`class_exists('Vc_Manager')`). It registers the
 *      `vc_map()` calls so the four elements appear in the Visual
 *      Composer "Add Element" picker grouped under the "Seekmodo"
 *      category.
 *
 * Mirrors the gating model of the Elementor loader (PR 2): the
 * page-builder-specific surface is gated, the underlying surface
 * always works.
 */
final class Loader
{
    public static function register(): void
    {
        Shortcodes::register();

        if (function_exists('add_action')) {
            add_action('init', [self::class, 'maybeRegisterVcMap'], 20);
        }
    }

    /**
     * Decision gate for the WPBakery-specific surface. Public for
     * unit tests so they can exercise it without booting WP.
     */
    public static function maybeRegisterVcMap(): bool
    {
        if (!self::isWPBakeryActive()) {
            return false;
        }

        VcMap::register();

        return true;
    }

    public static function isWPBakeryActive(): bool
    {
        return class_exists('Vc_Manager') || function_exists('vc_map');
    }
}
