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

// src/env/get-env.ts
init_esm_shims();
import { COLOR_KEYS, STORM_DEFAULT_DOCS, STORM_DEFAULT_HOMEPAGE, STORM_DEFAULT_LICENSING } from "@storm-software/config";
var getExtensionEnv = /* @__PURE__ */ __name((extensionName) => {
  const prefix = `STORM_EXTENSION_${extensionName.toUpperCase()}_`;
  return Object.keys(process.env).filter((key) => key.startsWith(prefix)).reduce((ret, key) => {
    const name = key.replace(prefix, "").split("_").map((i) => i.length > 0 ? i.trim().charAt(0).toUpperCase() + i.trim().slice(1) : "").join("");
    if (name) {
      ret[name] = process.env[key];
    }
    return ret;
  }, {});
}, "getExtensionEnv");
var getConfigEnv = /* @__PURE__ */ __name(() => {
  const prefix = "STORM_";
  let config = {
    extends: process.env[`${prefix}EXTENDS`] || void 0,
    name: process.env[`${prefix}NAME`] || void 0,
    namespace: process.env[`${prefix}NAMESPACE`] || void 0,
    owner: process.env[`${prefix}OWNER`] || void 0,
    bot: {
      name: process.env[`${prefix}BOT_NAME`] || void 0,
      email: process.env[`${prefix}BOT_EMAIL`] || void 0
    },
    organization: process.env[`${prefix}ORGANIZATION`] || void 0,
    packageManager: process.env[`${prefix}PACKAGE_MANAGER`] || void 0,
    license: process.env[`${prefix}LICENSE`] || void 0,
    homepage: process.env[`${prefix}HOMEPAGE`] || void 0,
    docs: process.env[`${prefix}DOCS`] || void 0,
    licensing: process.env[`${prefix}LICENSING`] || void 0,
    timezone: process.env[`${prefix}TIMEZONE`] || process.env.TZ || void 0,
    locale: process.env[`${prefix}LOCALE`] || process.env.LOCALE || void 0,
    configFile: process.env[`${prefix}CONFIG_FILE`] ? correctPaths(process.env[`${prefix}CONFIG_FILE`]) : void 0,
    workspaceRoot: process.env[`${prefix}WORKSPACE_ROOT`] ? correctPaths(process.env[`${prefix}WORKSPACE_ROOT`]) : void 0,
    directories: {
      cache: process.env[`${prefix}CACHE_DIR`] ? correctPaths(process.env[`${prefix}CACHE_DIR`]) : void 0,
      data: process.env[`${prefix}DATA_DIR`] ? correctPaths(process.env[`${prefix}DATA_DIR`]) : void 0,
      config: process.env[`${prefix}CONFIG_DIR`] ? correctPaths(process.env[`${prefix}CONFIG_DIR`]) : void 0,
      temp: process.env[`${prefix}TEMP_DIR`] ? correctPaths(process.env[`${prefix}TEMP_DIR`]) : void 0,
      log: process.env[`${prefix}LOG_DIR`] ? correctPaths(process.env[`${prefix}LOG_DIR`]) : void 0,
      build: process.env[`${prefix}BUILD_DIR`] ? correctPaths(process.env[`${prefix}BUILD_DIR`]) : void 0
    },
    skipCache: process.env[`${prefix}SKIP_CACHE`] !== void 0 ? Boolean(process.env[`${prefix}SKIP_CACHE`]) : void 0,
    env: (process.env[`${prefix}ENV`] ?? process.env.NODE_ENV ?? process.env.ENVIRONMENT) || void 0,
    // ci:
    //   process.env[`${prefix}CI`] !== undefined
    //     ? Boolean(
    //         process.env[`${prefix}CI`] ??
    //           process.env.CI ??
    //           process.env.CONTINUOUS_INTEGRATION
    //       )
    //     : undefined,
    repository: process.env[`${prefix}REPOSITORY`] || void 0,
    branch: process.env[`${prefix}BRANCH`] || void 0,
    preid: process.env[`${prefix}PRE_ID`] || void 0,
    externalPackagePatterns: process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`] ? JSON.parse(process.env[`${prefix}EXTERNAL_PACKAGE_PATTERNS`]) : [],
    registry: {
      github: process.env[`${prefix}REGISTRY_GITHUB`] || void 0,
      npm: process.env[`${prefix}REGISTRY_NPM`] || void 0,
      cargo: process.env[`${prefix}REGISTRY_CARGO`] || void 0,
      cyclone: process.env[`${prefix}REGISTRY_CYCLONE`] || void 0,
      container: process.env[`${prefix}REGISTRY_CONTAINER`] || void 0
    },
    logLevel: process.env[`${prefix}LOG_LEVEL`] !== null && process.env[`${prefix}LOG_LEVEL`] !== void 0 ? process.env[`${prefix}LOG_LEVEL`] && Number.isSafeInteger(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) ? getLogLevelLabel(Number.parseInt(process.env[`${prefix}LOG_LEVEL`])) : process.env[`${prefix}LOG_LEVEL`] : void 0
  };
  const themeNames = Object.keys(process.env).filter((envKey) => envKey.startsWith(`${prefix}COLOR_`) && COLOR_KEYS.every((colorKey) => !envKey.startsWith(`${prefix}COLOR_LIGHT_${colorKey}`) && !envKey.startsWith(`${prefix}COLOR_DARK_${colorKey}`)));
  config.colors = themeNames.length > 0 ? themeNames.reduce((ret, themeName) => {
    ret[themeName] = getThemeColorConfigEnv(prefix, themeName);
    return ret;
  }, {}) : getThemeColorConfigEnv(prefix);
  if (config.docs === STORM_DEFAULT_DOCS) {
    if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
      config.docs = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/docs`;
    } else {
      config.docs = `${config.homepage}/docs`;
    }
  }
  if (config.licensing === STORM_DEFAULT_LICENSING) {
    if (config.homepage === STORM_DEFAULT_HOMEPAGE) {
      config.licensing = `${STORM_DEFAULT_HOMEPAGE}/projects/${config.name}/licensing`;
    } else {
      config.licensing = `${config.homepage}/docs`;
    }
  }
  const serializedConfig = process.env[`${prefix}CONFIG`];
  if (serializedConfig) {
    const parsed = JSON.parse(serializedConfig);
    config = {
      ...config,
      ...parsed,
      colors: {
        ...config.colors,
        ...parsed.colors
      },
      extensions: {
        ...config.extensions,
        ...parsed.extensions
      }
    };
  }
  return config;
}, "getConfigEnv");
var getThemeColorConfigEnv = /* @__PURE__ */ __name((prefix, theme) => {
  const themeName = `COLOR_${theme && theme !== "base" ? `${theme}_` : ""}`.toUpperCase();
  return process.env[`${prefix}${themeName}LIGHT_BRAND`] || process.env[`${prefix}${themeName}DARK_BRAND`] ? getMultiThemeColorConfigEnv(prefix + themeName) : getSingleThemeColorConfigEnv(prefix + themeName);
}, "getThemeColorConfigEnv");
var getSingleThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
  return {
    dark: process.env[`${prefix}DARK`],
    light: process.env[`${prefix}LIGHT`],
    brand: process.env[`${prefix}BRAND`],
    alternate: process.env[`${prefix}ALTERNATE`],
    accent: process.env[`${prefix}ACCENT`],
    link: process.env[`${prefix}LINK`],
    help: process.env[`${prefix}HELP`],
    success: process.env[`${prefix}SUCCESS`],
    info: process.env[`${prefix}INFO`],
    warning: process.env[`${prefix}WARNING`],
    danger: process.env[`${prefix}DANGER`],
    fatal: process.env[`${prefix}FATAL`],
    positive: process.env[`${prefix}POSITIVE`],
    negative: process.env[`${prefix}NEGATIVE`]
  };
}, "getSingleThemeColorConfigEnv");
var getMultiThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
  return {
    light: getBaseThemeColorConfigEnv(`${prefix}_LIGHT_`),
    dark: getBaseThemeColorConfigEnv(`${prefix}_DARK_`)
  };
}, "getMultiThemeColorConfigEnv");
var getBaseThemeColorConfigEnv = /* @__PURE__ */ __name((prefix) => {
  return {
    foreground: process.env[`${prefix}FOREGROUND`],
    background: process.env[`${prefix}BACKGROUND`],
    brand: process.env[`${prefix}BRAND`],
    alternate: process.env[`${prefix}ALTERNATE`],
    accent: process.env[`${prefix}ACCENT`],
    link: process.env[`${prefix}LINK`],
    help: process.env[`${prefix}HELP`],
    success: process.env[`${prefix}SUCCESS`],
    info: process.env[`${prefix}INFO`],
    warning: process.env[`${prefix}WARNING`],
    danger: process.env[`${prefix}DANGER`],
    fatal: process.env[`${prefix}FATAL`],
    positive: process.env[`${prefix}POSITIVE`],
    negative: process.env[`${prefix}NEGATIVE`]
  };
}, "getBaseThemeColorConfigEnv");

export {
  getExtensionEnv,
  getConfigEnv
};
