import { findParentDirectoryWithFile } from './3CLGGUZ6.js';
import { versionMatrices } from './MWXKZUMG.js';
import { init_esm_shims, __name } from './4RNWLMHM.js';
import fs from 'fs';
import * as semver from 'semver';

// src/utils/finder-utils.ts
init_esm_shims();

// src/config/index.ts
init_esm_shims();

// src/config/tools.ts
init_esm_shims();

// src/utils/version-utils.ts
init_esm_shims();
function versionsSatisfied(current, expected) {
  return semver.satisfies(current.version, expected.version);
}
__name(versionsSatisfied, "versionsSatisfied");
function parseAnchorTomlVersion(cwd, name) {
  const projectFolder = findParentDirectoryWithFile(cwd, "Anchor.toml");
  if (projectFolder === null) {
    throw new Error("Anchor project not found");
  }
  const toml = fs.readFileSync(projectFolder.file, "utf-8");
  const test = /^([a-z]+)(?:_version ?= ?")((?:[0-9]+\.?){3})(?:")$/gm;
  let match;
  while (match = test.exec(toml)) {
    const [, matchedName, version] = match;
    if (matchedName === name) {
      return {
        version
      };
    }
  }
  throw new Error(`${name} version not found in ${projectFolder.file}`);
}
__name(parseAnchorTomlVersion, "parseAnchorTomlVersion");
function findSemVersionFromString(input) {
  const match = input.match(/^(solana-cli|anchor-cli|aptos)\s+(([0-9]+\.?){3}).*?/m);
  if (match === null || match.length < 3) {
    throw new Error(`Invalid semver version: ${input}`);
  }
  return {
    version: match[2]
  };
}
__name(findSemVersionFromString, "findSemVersionFromString");
function validateToolVersion(toolName, version) {
  const supportedVersions = getToolSupportedVersions(toolName);
  return supportedVersions.includes(version);
}
__name(validateToolVersion, "validateToolVersion");

// src/config/tools.ts
var solanaDefaultVolumes = [
  {
    type: "isolate",
    containerPath: "/usr/local/cargo",
    name: "cargo"
  },
  {
    type: "isolate",
    containerPath: "/usr/local/rustup",
    name: "rustup"
  },
  {
    type: "isolate",
    containerPath: "/var/lib/docker",
    name: "docker"
  }
];
var tools = [
  {
    name: "hardhat",
    toolType: "evm",
    fromImage: "evm",
    defaultVolumes: []
  },
  {
    name: "forge",
    toolType: "evm",
    fromImage: "evm"
  },
  {
    name: "anchor",
    toolType: "solana",
    fromImage: "solana",
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersionCheckValue: /* @__PURE__ */ __name(({ cwd }) => {
      return parseAnchorTomlVersion(cwd, "anchor");
    }, "getSecondaryVersionCheckValue")
  },
  {
    name: "solana",
    toolType: "solana",
    fromImage: "solana",
    privileged: true,
    defaultVolumes: solanaDefaultVolumes,
    getSecondaryVersionCheckValue: /* @__PURE__ */ __name(({ cwd }) => {
      return parseAnchorTomlVersion(cwd, "solana");
    }, "getSecondaryVersionCheckValue")
  },
  {
    name: "aptos",
    toolType: "aptos",
    fromImage: "aptos",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "aptos"
      }
    ]
  },
  {
    name: "initiad",
    toolType: "initia",
    fromImage: "initia",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "initia"
      }
    ]
  },
  {
    name: "blueprint",
    toolType: "ton",
    fromImage: "ton"
  },
  {
    name: "scarb",
    toolType: "starknet",
    fromImage: "starknet"
  },
  {
    name: "sui",
    toolType: "sui",
    fromImage: "sui",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.move",
        name: "sui"
      },
      {
        type: "isolate",
        containerPath: "/root/.sui",
        name: "sui-config",
        shared: true,
        locked: true
      }
    ]
  },
  {
    name: "stellar",
    toolType: "stellar",
    fromImage: "stellar",
    defaultVolumes: [
      {
        type: "isolate",
        containerPath: "/root/.config/stellar",
        name: "stellar-config",
        shared: true,
        locked: true
      },
      {
        type: "isolate",
        containerPath: "/usr/local/cargo",
        name: "stellar-cargo",
        shared: true,
        locked: false
      }
    ]
  }
];

// src/config/index.ts
var AWS_ACCOUNT_ID = "438003944538";
var AWS_REGION = "us-east-1";

// src/utils/finder-utils.ts
function findToolByName(toolName) {
  return tools.find((tool) => tool.name === toolName);
}
__name(findToolByName, "findToolByName");
function findToolsByType(type) {
  return tools.filter((tool) => tool.toolType === type);
}
__name(findToolsByType, "findToolsByType");
function getToolType(toolName) {
  const tool = findToolByName(toolName);
  return tool?.toolType;
}
__name(getToolType, "getToolType");
function findMatrixByType(type) {
  return versionMatrices.find((matrix) => matrix.toolType === type);
}
__name(findMatrixByType, "findMatrixByType");
function findDefaultCombination(matrix) {
  const recommended = matrix.combinations.find((combo) => combo.isRecommended === true);
  if (recommended) {
    return recommended;
  }
  if (matrix.combinations.length === 0) {
    throw new Error(`No combinations found in matrix for type '${matrix.toolType}'`);
  }
  return matrix.combinations[0];
}
__name(findDefaultCombination, "findDefaultCombination");
function getToolDefaultVersion(toolName) {
  const tool = findToolByName(toolName);
  if (!tool) {
    throw new Error(`Tool '${toolName}' not found`);
  }
  const matrix = findMatrixByType(tool.toolType);
  if (!matrix) {
    throw new Error(`No version matrix found for tool type '${tool.toolType}'`);
  }
  const defaultCombination = findDefaultCombination(matrix);
  const defaultVersion = defaultCombination.versions[toolName];
  if (!defaultVersion?.length) {
    console.warn(`No default version found for tool '${toolName}' in matrix`);
    return null;
  }
  return defaultVersion;
}
__name(getToolDefaultVersion, "getToolDefaultVersion");
function getToolSupportedVersions(toolName) {
  const tool = findToolByName(toolName);
  if (!tool) {
    throw new Error(`Tool '${toolName}' not found`);
  }
  const matrix = findMatrixByType(tool.toolType);
  if (!matrix) {
    throw new Error(`No version matrix found for tool type '${tool.toolType}'`);
  }
  const versions = /* @__PURE__ */ new Set();
  for (const combination of matrix.combinations) {
    const version = combination.versions[toolName];
    if (version != null && version.length > 0) {
      versions.add(version);
    }
  }
  return Array.from(versions).sort();
}
__name(getToolSupportedVersions, "getToolSupportedVersions");

export { AWS_ACCOUNT_ID, AWS_REGION, findDefaultCombination, findMatrixByType, findSemVersionFromString, findToolByName, findToolsByType, getToolDefaultVersion, getToolSupportedVersions, getToolType, parseAnchorTomlVersion, tools, validateToolVersion, versionsSatisfied };
//# sourceMappingURL=W2CW3JVG.js.map
//# sourceMappingURL=W2CW3JVG.js.map