import { jsx } from 'react/jsx-runtime';
import { getComponentData } from '@backstage/core-plugin-api';
import { PageBlueprint } from '@backstage/frontend-plugin-api';
import kebabCase from 'lodash/kebabCase';
import { convertLegacyRouteRef } from './convertLegacyRouteRef.esm.js';
import { compatWrapper } from './compatWrapper/compatWrapper.esm.js';

function convertLegacyPageExtension(LegacyExtension, overrides) {
  const element = /* @__PURE__ */ jsx(LegacyExtension, {});
  const extName = getComponentData(element, "core.extensionName");
  if (!extName) {
    throw new Error("Extension has no name");
  }
  const mountPoint = getComponentData(
    element,
    "core.mountPoint"
  );
  const name = extName.endsWith("Page") ? extName.slice(0, -"Page".length) : extName;
  const kebabName = kebabCase(name);
  return PageBlueprint.make({
    name: overrides?.name ?? kebabName,
    params: {
      defaultPath: overrides?.defaultPath ?? `/${kebabName}`,
      routeRef: mountPoint && convertLegacyRouteRef(mountPoint),
      loader: async () => compatWrapper(element)
    }
  });
}

export { convertLegacyPageExtension };
//# sourceMappingURL=convertLegacyPageExtension.esm.js.map
