var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  getPageTitle: () => getPageTitle,
  getPageTitleInfo: () => getPageTitleInfo,
  matchParamsPath: () => matchParamsPath
});
module.exports = __toCommonJS(stdin_exports);
var import_path_to_regexp = require("path-to-regexp");
function matchParamsPath(pathname, breadcrumb, breadcrumbMap) {
  if (breadcrumbMap) {
    const pathKey = [...breadcrumbMap.keys()].find((key) => {
      try {
        if (key.startsWith("http")) {
          return false;
        }
        return (0, import_path_to_regexp.match)(key)(pathname);
      } catch (error) {
        console.log("key", key, error);
        return false;
      }
    });
    if (pathKey) {
      return breadcrumbMap.get(pathKey);
    }
  }
  if (breadcrumb) {
    const pathKey = Object.keys(breadcrumb).find((key) => {
      try {
        if (key == null ? void 0 : key.startsWith("http")) {
          return false;
        }
        return (0, import_path_to_regexp.match)(key)(pathname);
      } catch (error) {
        console.log("key", key, error);
        return false;
      }
    });
    if (pathKey) {
      return breadcrumb[pathKey];
    }
  }
  return {
    path: ""
  };
}
function getPageTitleInfo(props, ignoreTitle) {
  const {
    pathname = "/",
    breadcrumb,
    breadcrumbMap,
    formatMessage,
    title,
    menu = {
      locale: false
    }
  } = props;
  const pageTitle = ignoreTitle ? "" : title || "";
  const currRouterData = matchParamsPath(pathname, breadcrumb, breadcrumbMap);
  if (!currRouterData) {
    return {
      title: pageTitle,
      id: "",
      pageName: pageTitle
    };
  }
  let pageName = currRouterData.name;
  if (menu.locale !== false && currRouterData.locale && formatMessage) {
    pageName = formatMessage({
      id: currRouterData.locale || "",
      defaultMessage: currRouterData.name
    });
  }
  if (!pageName) {
    return {
      title: pageTitle,
      id: currRouterData.locale || "",
      pageName: pageTitle
    };
  }
  if (ignoreTitle || !title) {
    return {
      title: pageName,
      id: currRouterData.locale || "",
      pageName
    };
  }
  return {
    title: `${pageName} - ${title}`,
    id: currRouterData.locale || "",
    pageName
  };
}
function getPageTitle(props, ignoreTitle) {
  return getPageTitleInfo(props, ignoreTitle).title;
}
