<?php
/**
 * @package   Essentials YOOtheme Pro 2.2.16 build 0813.1608
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

use function YOOtheme\app;
use YOOtheme\Application;
use YOOtheme\Path;

defined('WPINC') or die();

add_action('after_setup_theme', function () {
    if (!class_exists(Application::class, false)) {
        return;
    }

    include_once __DIR__ . '/modules/autoload.php';

    Path::setAlias('~yooessentials', __DIR__);
    Path::setAlias('~yooessentials_url', plugins_url('yooessentials'));

    $config = YooessentialsHelper::fetchConfig();
    $modules = ['core', 'condition', 'api', 'auth', 'storage'];

    foreach (['access', 'form', 'source', 'icon', 'dynamic', 'layout', 'element'] as $addon) {
        $enabled = $config[$addon]['state'] ?? true;

        if ($enabled) {
            $modules[] = $addon;
        }
    }

    foreach ($modules as $module) {
        app()->load('~yooessentials/modules/{' . $module . '{,-wordpress}}/bootstrap.php');
    }
});
