const boot = window.EkestoCacheInvalidator || {};
const config =
    typeof boot.config === "object" && boot.config !== null
        ? boot.config
        : {};

// Normalize runtime config to empty-string defaults to avoid undefined usage.
const readString = (value) => (typeof value === "string" ? value : "");

export const SETTINGS_BOOT = boot;
export const SETTINGS_CONFIG = config;

// Authoritative backend premium feature flags. Presentation-layer gating only —
// never a security/licensing boundary. Missing/unknown flags resolve to false.
export const SETTINGS_FEATURES =
    typeof config.features === "object" && config.features !== null
        ? config.features
        : {};

export const hasFeature = (key) => SETTINGS_FEATURES[key] === true;
export const REST_PATH = readString(config.restPath);
export const REST_NAMESPACE = readString(config.restNamespace);
export const REST_ROOT = readString(config.restRoot);
export const REST_NONCE = readString(config.restNonce);
export const ROOT_ELEMENT_ID = readString(config.rootId);
