import {
  correctPaths
} from "./chunk-WBQEFUVW.js";
import {
  getLogLevel
} from "./chunk-L3RZVSYE.js";
import {
  LogLevel
} from "./chunk-WN4V6QSX.js";
import {
  __name,
  init_esm_shims
} from "./chunk-65NJ2BNV.js";

// src/env/set-env.ts
init_esm_shims();
var setExtensionEnv = /* @__PURE__ */ __name((extensionName, extension) => {
  for (const key of Object.keys(extension ?? {})) {
    if (extension[key]) {
      const result = key?.replace(/([A-Z])+/g, (input) => input ? input[0]?.toUpperCase() + input.slice(1) : "").split(/(?=[A-Z])|[.\-\s_]/).map((x) => x.toLowerCase()) ?? [];
      let extensionKey;
      if (result.length === 0) {
        return;
      }
      if (result.length === 1) {
        extensionKey = result[0]?.toUpperCase() ?? "";
      } else {
        extensionKey = result.reduce((ret, part) => {
          return `${ret}_${part.toLowerCase()}`;
        });
      }
      process.env[`STORM_EXTENSION_${extensionName.toUpperCase()}_${extensionKey.toUpperCase()}`] = extension[key];
    }
  }
}, "setExtensionEnv");
var setConfigEnv = /* @__PURE__ */ __name((config) => {
  const prefix = "STORM_";
  if (config.extends) {
    process.env[`${prefix}EXTENDS`] = Array.isArray(config.extends) ? JSON.stringify(config.extends) : config.extends;
  }
  if (config.name) {
    process.env[`${prefix}NAME`] = config.name;
  }
  if (config.namespace) {
    process.env[`${prefix}NAMESPACE`] = config.namespace;
  }
  if (config.owner) {
    process.env[`${prefix}OWNER`] = config.owner;
  }
  if (config.bot) {
    process.env[`${prefix}BOT_NAME`] = config.bot.name;
    process.env[`${prefix}BOT_EMAIL`] = config.bot.email;
  }
  if (config.organization) {
    process.env[`${prefix}ORGANIZATION`] = config.organization;
  }
  if (config.packageManager) {
    process.env[`${prefix}PACKAGE_MANAGER`] = config.packageManager;
  }
  if (config.license) {
    process.env[`${prefix}LICENSE`] = config.license;
  }
  if (config.homepage) {
    process.env[`${prefix}HOMEPAGE`] = config.homepage;
  }
  if (config.docs) {
    process.env[`${prefix}DOCS`] = config.docs;
  }
  if (config.licensing) {
    process.env[`${prefix}LICENSING`] = config.licensing;
  }
  if (config.timezone) {
    process.env[`${prefix}TIMEZONE`] = config.timezone;
    process.env.TZ = config.timezone;
    process.env.DEFAULT_TIMEZONE = config.timezone;
  }
  if (config.locale) {
    process.env[`${prefix}LOCALE`] = config.locale;
    process.env.LOCALE = config.locale;
    process.env.DEFAULT_LOCALE = config.locale;
    process.env.LANG = config.locale ? `${config.locale.replaceAll("-", "_")}.UTF-8` : "en_US.UTF-8";
  }
  if (config.configFile) {
    process.env[`${prefix}CONFIG_FILE`] = correctPaths(config.configFile);
  }
  if (config.workspaceRoot) {
    process.env[`${prefix}WORKSPACE_ROOT`] = correctPaths(config.workspaceRoot);
    process.env.NX_WORKSPACE_ROOT = correctPaths(config.workspaceRoot);
    process.env.NX_WORKSPACE_ROOT_PATH = correctPaths(config.workspaceRoot);
  }
  if (config.directories) {
    if (!config.skipCache && config.directories.cache) {
      process.env[`${prefix}CACHE_DIR`] = correctPaths(config.directories.cache);
    }
    if (config.directories.data) {
      process.env[`${prefix}DATA_DIR`] = correctPaths(config.directories.data);
    }
    if (config.directories.config) {
      process.env[`${prefix}CONFIG_DIR`] = correctPaths(config.directories.config);
    }
    if (config.directories.temp) {
      process.env[`${prefix}TEMP_DIR`] = correctPaths(config.directories.temp);
    }
    if (config.directories.log) {
      process.env[`${prefix}LOG_DIR`] = correctPaths(config.directories.log);
    }
    if (config.directories.build) {
      process.env[`${prefix}BUILD_DIR`] = correctPaths(config.directories.build);
    }
  }
  if (config.skipCache !== void 0) {
    process.env[`${prefix}SKIP_CACHE`] = String(config.skipCache);
    if (config.skipCache) {
      process.env.NX_SKIP_NX_CACHE ??= String(config.skipCache);
      process.env.NX_CACHE_PROJECT_GRAPH ??= String(config.skipCache);
    }
  }
  if (config.env) {
    process.env[`${prefix}ENV`] = config.env;
    process.env.NODE_ENV = config.env;
    process.env.ENVIRONMENT = config.env;
  }
  if (config.colors?.base?.light || config.colors?.base?.dark) {
    for (const key of Object.keys(config.colors)) {
      setThemeColorConfigEnv(`${prefix}COLOR_${key}_`, config.colors[key]);
    }
  } else {
    setThemeColorConfigEnv(`${prefix}COLOR_`, config.colors);
  }
  if (config.repository) {
    process.env[`${prefix}REPOSITORY`] = config.repository;
  }
  if (config.branch) {
    process.env[`${prefix}BRANCH`] = config.branch;
  }
  if (config.preid) {
    process.env[`${prefix}PRE_ID`] = String(config.preid);
  }
  if (config.externalPackagePatterns) {
    process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] = JSON.stringify(config.externalPackagePatterns);
  }
  if (config.registry) {
    if (config.registry.github) {
      process.env[`${prefix}REGISTRY_GITHUB`] = String(config.registry.github);
    }
    if (config.registry.npm) {
      process.env[`${prefix}REGISTRY_NPM`] = String(config.registry.npm);
    }
    if (config.registry.cargo) {
      process.env[`${prefix}REGISTRY_CARGO`] = String(config.registry.cargo);
    }
    if (config.registry.cyclone) {
      process.env[`${prefix}REGISTRY_CYCLONE`] = String(config.registry.cyclone);
    }
    if (config.registry.container) {
      process.env[`${prefix}REGISTRY_CONTAINER`] = String(config.registry.cyclone);
    }
  }
  if (config.logLevel) {
    process.env[`${prefix}LOG_LEVEL`] = String(config.logLevel);
    process.env.LOG_LEVEL = String(config.logLevel);
    process.env.NX_VERBOSE_LOGGING = String(getLogLevel(config.logLevel) >= LogLevel.DEBUG ? true : false);
    process.env.RUST_BACKTRACE = getLogLevel(config.logLevel) >= LogLevel.DEBUG ? "full" : "none";
  }
  process.env[`${prefix}CONFIG`] = JSON.stringify(config);
  for (const key of Object.keys(config.extensions ?? {})) {
    config.extensions[key] && Object.keys(config.extensions[key]) && setExtensionEnv(key, config.extensions[key]);
  }
}, "setConfigEnv");
var setThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
  return config?.light?.brand || config?.dark?.brand ? setMultiThemeColorConfigEnv(prefix, config) : setSingleThemeColorConfigEnv(prefix, config);
}, "setThemeColorConfigEnv");
var setSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
  if (config.dark) {
    process.env[`${prefix}DARK`] = config.dark;
  }
  if (config.light) {
    process.env[`${prefix}LIGHT`] = config.light;
  }
  if (config.brand) {
    process.env[`${prefix}BRAND`] = config.brand;
  }
  if (config.alternate) {
    process.env[`${prefix}ALTERNATE`] = config.alternate;
  }
  if (config.accent) {
    process.env[`${prefix}ACCENT`] = config.accent;
  }
  if (config.link) {
    process.env[`${prefix}LINK`] = config.link;
  }
  if (config.help) {
    process.env[`${prefix}HELP`] = config.help;
  }
  if (config.success) {
    process.env[`${prefix}SUCCESS`] = config.success;
  }
  if (config.info) {
    process.env[`${prefix}INFO`] = config.info;
  }
  if (config.warning) {
    process.env[`${prefix}WARNING`] = config.warning;
  }
  if (config.danger) {
    process.env[`${prefix}DANGER`] = config.danger;
  }
  if (config.fatal) {
    process.env[`${prefix}FATAL`] = config.fatal;
  }
  if (config.positive) {
    process.env[`${prefix}POSITIVE`] = config.positive;
  }
  if (config.negative) {
    process.env[`${prefix}NEGATIVE`] = config.negative;
  }
}, "setSingleThemeColorConfigEnv");
var setMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
  return {
    light: setBaseThemeColorConfigEnv(`${prefix}LIGHT_`, config.light),
    dark: setBaseThemeColorConfigEnv(`${prefix}DARK_`, config.dark)
  };
}, "setMultiThemeColorConfigEnv");
var setBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, config) => {
  if (config.foreground) {
    process.env[`${prefix}FOREGROUND`] = config.foreground;
  }
  if (config.background) {
    process.env[`${prefix}BACKGROUND`] = config.background;
  }
  if (config.brand) {
    process.env[`${prefix}BRAND`] = config.brand;
  }
  if (config.alternate) {
    process.env[`${prefix}ALTERNATE`] = config.alternate;
  }
  if (config.accent) {
    process.env[`${prefix}ACCENT`] = config.accent;
  }
  if (config.link) {
    process.env[`${prefix}LINK`] = config.link;
  }
  if (config.help) {
    process.env[`${prefix}HELP`] = config.help;
  }
  if (config.success) {
    process.env[`${prefix}SUCCESS`] = config.success;
  }
  if (config.info) {
    process.env[`${prefix}INFO`] = config.info;
  }
  if (config.warning) {
    process.env[`${prefix}WARNING`] = config.warning;
  }
  if (config.danger) {
    process.env[`${prefix}DANGER`] = config.danger;
  }
  if (config.fatal) {
    process.env[`${prefix}FATAL`] = config.fatal;
  }
  if (config.positive) {
    process.env[`${prefix}POSITIVE`] = config.positive;
  }
  if (config.negative) {
    process.env[`${prefix}NEGATIVE`] = config.negative;
  }
}, "setBaseThemeColorConfigEnv");

export {
  setExtensionEnv,
  setConfigEnv
};
