"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

var _chunkA2QPNGB4cjs = require('./chunk-A2QPNGB4.cjs');


var _chunkUIA5EFWJcjs = require('./chunk-UIA5EFWJ.cjs');




var _chunkD7SRJTRQcjs = require('./chunk-D7SRJTRQ.cjs');


var _chunkGNNKAT6Ccjs = require('./chunk-GNNKAT6C.cjs');


var _chunkMUKNCWDCcjs = require('./chunk-MUKNCWDC.cjs');



var _chunkEG6MZ74Dcjs = require('./chunk-EG6MZ74D.cjs');


var _chunk56YHC4NMcjs = require('./chunk-56YHC4NM.cjs');


var _chunkGTJILL6Ucjs = require('./chunk-GTJILL6U.cjs');



var _chunkDFJNOFN2cjs = require('./chunk-DFJNOFN2.cjs');

// src/create-storm-config.ts
_chunkDFJNOFN2cjs.init_cjs_shims.call(void 0, );
var _extension_cache = /* @__PURE__ */ new WeakMap();
var _static_cache = void 0;
var createConfig = /* @__PURE__ */ _chunkDFJNOFN2cjs.__name.call(void 0, (workspaceRoot) => {
  return createStormConfig(void 0, void 0, workspaceRoot);
}, "createConfig");
var createStormConfig = /* @__PURE__ */ _chunkDFJNOFN2cjs.__name.call(void 0, (extensionName, schema, workspaceRoot) => {
  let result;
  if (!_optionalChain([_static_cache, 'optionalAccess', _ => _.data]) || !_optionalChain([_static_cache, 'optionalAccess', _2 => _2.timestamp]) || _static_cache.timestamp < Date.now() - 3e4) {
    const config = _chunkEG6MZ74Dcjs.getConfigEnv.call(void 0, );
    const defaultConfig = _chunkGNNKAT6Ccjs.getDefaultConfig.call(void 0, workspaceRoot);
    result = _chunk56YHC4NMcjs.StormConfigSchema.parse(_chunkUIA5EFWJcjs.defu.call(void 0, config, defaultConfig));
    result.workspaceRoot ??= defaultConfig.workspaceRoot || _chunkMUKNCWDCcjs.findWorkspaceRoot.call(void 0, workspaceRoot);
  } else {
    result = _static_cache.data;
  }
  if (schema && extensionName) {
    result.extensions = {
      ...result.extensions,
      [extensionName]: createConfigExtension(extensionName, schema)
    };
  }
  _static_cache = {
    timestamp: Date.now(),
    data: result
  };
  return result;
}, "createStormConfig");
var createConfigExtension = /* @__PURE__ */ _chunkDFJNOFN2cjs.__name.call(void 0, (extensionName, schema) => {
  const extension_cache_key = {
    extensionName
  };
  if (_extension_cache.has(extension_cache_key)) {
    return _extension_cache.get(extension_cache_key);
  }
  let extension = _chunkEG6MZ74Dcjs.getExtensionEnv.call(void 0, extensionName);
  if (schema) {
    extension = schema.parse(extension);
  }
  _extension_cache.set(extension_cache_key, extension);
  return extension;
}, "createConfigExtension");
var loadStormConfig = /* @__PURE__ */ _chunkDFJNOFN2cjs.__name.call(void 0, async (workspaceRoot) => {
  let config = {};
  if (_optionalChain([_static_cache, 'optionalAccess', _3 => _3.data]) && _optionalChain([_static_cache, 'optionalAccess', _4 => _4.timestamp]) && _static_cache.timestamp >= Date.now() + 3e4) {
    _chunkD7SRJTRQcjs.writeTrace.call(void 0, `Configuration cache hit - ${_static_cache.timestamp}`, _static_cache.data);
    return _static_cache.data;
  }
  let _workspaceRoot = workspaceRoot;
  if (!_workspaceRoot) {
    _workspaceRoot = _chunkMUKNCWDCcjs.findWorkspaceRoot.call(void 0, );
  }
  const configFile = await _chunkA2QPNGB4cjs.getConfigFile.call(void 0, _workspaceRoot);
  if (!configFile) {
    _chunkD7SRJTRQcjs.writeWarning.call(void 0, "No Storm config file found in the current workspace. Please ensure this is the expected behavior - you can add a `storm.json` file to the root of your workspace if it is not.\n", {
      logLevel: "all"
    });
  }
  config = _chunkUIA5EFWJcjs.defu.call(void 0, _chunkEG6MZ74Dcjs.getConfigEnv.call(void 0, ), configFile, _chunkGNNKAT6Ccjs.getDefaultConfig.call(void 0, _workspaceRoot));
  _chunkGTJILL6Ucjs.setConfigEnv.call(void 0, config);
  _chunkD7SRJTRQcjs.writeTrace.call(void 0, `\u2699\uFE0F  Using Storm configuration: 
${_chunkD7SRJTRQcjs.formatLogMessage.call(void 0, config)}`, config);
  return config;
}, "loadStormConfig");






exports.createConfig = createConfig; exports.createStormConfig = createStormConfig; exports.createConfigExtension = createConfigExtension; exports.loadStormConfig = loadStormConfig;
