export const FORGE_EXTENSION_TYPE = 'com.atlassian.ecosystem';
export const NATIVE_EMBED_EXTENSION_TYPE = 'com.atlassian.native-embeds';
export const NATIVE_EMBED_EXTENSION_KEY = 'native-embed';
export const getExtensionKeyAndNodeKey = (extensionKey, extensionType) => {
  // Forge macro extensionKey has a user generated string, so splitting on
  // a colon is unstable for their particular use case. They only have one
  // node in the relevant manifest so we can hardcode nodeKey to 'default'.
  if (extensionType === FORGE_EXTENSION_TYPE) {
    return [extensionKey, 'default'];
  }
  const [extKey, nodeKey = 'default'] = extensionKey.split(':');
  return [extKey, nodeKey];
};
export const buildExtensionKeyAndNodeKey = (extensionKey, nodeKey) => {
  if (!nodeKey || nodeKey === 'default') {
    return extensionKey;
  }
  return `${extensionKey}:${nodeKey}`;
};
export function buildAction(action, manifest) {
  if (typeof action === 'function') {
    return action;
  }
  if (action.type === 'node' && manifest.modules.nodes) {
    return buildNode(action, manifest);
  }
}
export const resolveImportSync = importedModule => {
  return importedModule && importedModule.__esModule ? importedModule.default : importedModule;
};
export const resolveImport = async importPromise => {
  return resolveImportSync(await importPromise);
};
export function buildNode(action, manifest) {
  if (!manifest.modules.nodes) {
    return;
  }
  const node = manifest.modules.nodes[action.key];
  const extensionKey = buildExtensionKeyAndNodeKey(manifest.key, action.key);
  const extension = {
    type: node.type,
    attrs: {
      extensionType: manifest.type,
      extensionKey: extensionKey,
      parameters: action.parameters
    }
  };
  if (node.type === 'bodiedExtension') {
    return {
      ...extension,
      content: [{
        type: 'paragraph',
        content: []
      }]
    };
  } else if (node.type === 'multiBodiedExtension') {
    return {
      ...extension,
      content: [{
        type: 'extensionFrame',
        content: [{
          type: 'paragraph',
          content: []
        }]
      }]
    };
  }
  return extension;
}