const GLOBAL_INTEGRATION_REGISTRY_KEY = "__openMercatoIntegrationRegistry__";
function getIntegrationRegistryState() {
  const globalRegistry = globalThis;
  if (!globalRegistry[GLOBAL_INTEGRATION_REGISTRY_KEY]) {
    globalRegistry[GLOBAL_INTEGRATION_REGISTRY_KEY] = {
      integrations: /* @__PURE__ */ new Map(),
      bundles: /* @__PURE__ */ new Map()
    };
  }
  return globalRegistry[GLOBAL_INTEGRATION_REGISTRY_KEY];
}
function registerIntegration(definition) {
  getIntegrationRegistryState().integrations.set(definition.id, definition);
}
function registerIntegrations(definitions) {
  const registry = getIntegrationRegistryState().integrations;
  for (const definition of definitions) {
    registry.set(definition.id, definition);
  }
}
function registerBundle(bundle) {
  getIntegrationRegistryState().bundles.set(bundle.id, bundle);
}
function registerBundles(bundles) {
  const registry = getIntegrationRegistryState().bundles;
  for (const bundle of bundles) {
    registry.set(bundle.id, bundle);
  }
}
function clearRegisteredIntegrations() {
  const registry = getIntegrationRegistryState();
  registry.integrations.clear();
  registry.bundles.clear();
}
function getIntegration(integrationId) {
  return getIntegrationRegistryState().integrations.get(integrationId);
}
function getAllIntegrations() {
  return Array.from(getIntegrationRegistryState().integrations.values());
}
function getBundle(bundleId) {
  return getIntegrationRegistryState().bundles.get(bundleId);
}
function getAllBundles() {
  return Array.from(getIntegrationRegistryState().bundles.values());
}
function getBundleIntegrations(bundleId) {
  return Array.from(getIntegrationRegistryState().integrations.values()).filter((integration) => integration.bundleId === bundleId);
}
function resolveIntegrationCredentialsSchema(integrationId) {
  const registry = getIntegrationRegistryState();
  const definition = registry.integrations.get(integrationId);
  if (!definition) return void 0;
  if (definition.credentials && definition.credentials.fields.length > 0) {
    return definition.credentials;
  }
  if (!definition.bundleId) return definition.credentials;
  return registry.bundles.get(definition.bundleId)?.credentials;
}
function getIntegrationTitle(integrationId) {
  return getIntegrationRegistryState().integrations.get(integrationId)?.title ?? integrationId;
}
const LEGACY_INTEGRATION_DETAIL_TABS_SPOT_ID = "integrations.detail:tabs";
function buildIntegrationDetailWidgetSpotId(integrationId) {
  return `integrations.detail:${integrationId}`;
}
export {
  LEGACY_INTEGRATION_DETAIL_TABS_SPOT_ID,
  buildIntegrationDetailWidgetSpotId,
  clearRegisteredIntegrations,
  getAllBundles,
  getAllIntegrations,
  getBundle,
  getBundleIntegrations,
  getIntegration,
  getIntegrationTitle,
  registerBundle,
  registerBundles,
  registerIntegration,
  registerIntegrations,
  resolveIntegrationCredentialsSchema
};
//# sourceMappingURL=types.js.map
