<?php

if (!function_exists("is_plugin_active")) {
  include_once ABSPATH . "wp-admin/includes/plugin.php";
}

/**
 * Flag ci je povoleny rootcommerce plugin
 */
define("RC_ENABLED", is_plugin_active("rootcommerce/rootcommerce.php"));
define("WC_ENABLED", is_plugin_active("woocommerce/woocommerce.php"));
define("ESHOP_ENABLED", WC_ENABLED && RC_ENABLED);

// include child theme config
if (!defined("INOBY_THEME_CONFIG")) {
  include_once get_theme_file_path("/build/config.php");
}

class Inoby_Config {
  private static $config = null;

  public static function __callStatic($name, $arguments) {
    return self::get($name);
  }

  public static function component($blockId = null, $default = []) {
    return $blockId ? self::get("components", [])[$blockId] ?? $default : $default;
  }

  /**
   * Vrati hodnotu configu alebo default.
   */
  private static function get($feature, $default = null) {
    return self::get_config()[$feature] ?? $default;
  }

  private static function get_config() {
    if (!self::$config) {
      if (defined("INOBY_THEME_CONFIG")) {
        self::$config = INOBY_THEME_CONFIG;
      } else {
        self::$config = [];
      }
    }
    return self::$config;
  }
}
