"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunkI4SIJOYBcjs = require('./chunk-I4SIJOYB.cjs');



var _chunkSCFUDB74cjs = require('./chunk-SCFUDB74.cjs');

// src/utilities/apply-workspace-tokens.ts
_chunkSCFUDB74cjs.init_cjs_shims.call(void 0, );
var applyWorkspaceBaseTokens = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, async (option, tokenParams) => {
  let result = option;
  if (!result) {
    return result;
  }
  if (tokenParams) {
    const optionKeys = Object.keys(tokenParams);
    if (optionKeys.some((optionKey) => result.includes(`{${optionKey}}`))) {
      for (const optionKey of optionKeys) {
        if (result.includes(`{${optionKey}}`)) {
          result = result.replaceAll(`{${optionKey}}`, _optionalChain([tokenParams, 'optionalAccess', _ => _[optionKey]]) || "");
        }
      }
    }
  }
  if (tokenParams.config) {
    const configKeys = Object.keys(tokenParams.config);
    if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
      for (const configKey of configKeys) {
        if (result.includes(`{${configKey}}`)) {
          result = result.replaceAll(`{${configKey}}`, tokenParams.config[configKey] || "");
        }
      }
    }
  }
  if (result.includes("{workspaceRoot}")) {
    result = result.replaceAll("{workspaceRoot}", _nullishCoalesce(_nullishCoalesce(tokenParams.workspaceRoot, () => ( _optionalChain([tokenParams, 'access', _2 => _2.config, 'optionalAccess', _3 => _3.workspaceRoot]))), () => ( _chunkI4SIJOYBcjs.findWorkspaceRoot.call(void 0, ))));
  }
  return result;
}, "applyWorkspaceBaseTokens");
var applyWorkspaceProjectTokens = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, (option, tokenParams) => {
  return applyWorkspaceBaseTokens(option, tokenParams);
}, "applyWorkspaceProjectTokens");
var applyWorkspaceTokens = /* @__PURE__ */ _chunkSCFUDB74cjs.__name.call(void 0, async (options, tokenParams, tokenizerFn) => {
  if (!options) {
    return {};
  }
  const result = {};
  for (const option of Object.keys(options)) {
    if (typeof options[option] === "string") {
      result[option] = await Promise.resolve(tokenizerFn(options[option], tokenParams));
    } else if (Array.isArray(options[option])) {
      result[option] = await Promise.all(options[option].map(async (item) => typeof item === "string" ? await Promise.resolve(tokenizerFn(item, tokenParams)) : item));
    } else if (typeof options[option] === "object") {
      result[option] = await applyWorkspaceTokens(options[option], tokenParams, tokenizerFn);
    } else {
      result[option] = options[option];
    }
  }
  return result;
}, "applyWorkspaceTokens");





exports.applyWorkspaceBaseTokens = applyWorkspaceBaseTokens; exports.applyWorkspaceProjectTokens = applyWorkspaceProjectTokens; exports.applyWorkspaceTokens = applyWorkspaceTokens;
