"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/link-control/search-item.js
var search_item_exports = {};
__export(search_item_exports, {
  LinkControlSearchItem: () => LinkControlSearchItem,
  __experimentalLinkControlSearchItem: () => __experimentalLinkControlSearchItem,
  default: () => search_item_default
});
module.exports = __toCommonJS(search_item_exports);
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_icons = require("@wordpress/icons");
var import_dom = require("@wordpress/dom");
var import_url = require("@wordpress/url");
var import_compose = require("@wordpress/compose");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_jsx_runtime = require("react/jsx-runtime");
var TYPES = {
  post: {
    icon: import_icons.postList,
    label: (0, import_i18n.__)("Post")
  },
  page: {
    icon: import_icons.page,
    label: (0, import_i18n.__)("Page")
  },
  post_tag: {
    icon: import_icons.tag,
    label: (0, import_i18n.__)("Tag")
  },
  category: {
    icon: import_icons.category,
    label: (0, import_i18n.__)("Category")
  },
  attachment: {
    icon: import_icons.file,
    label: (0, import_i18n.__)("Attachment")
  }
};
function SearchItemIcon({ isURL, suggestion }) {
  let icon = null;
  if (isURL) {
    icon = import_icons.globe;
  } else if (suggestion.type in TYPES) {
    icon = TYPES[suggestion.type].icon;
    if (suggestion.type === "page") {
      if (suggestion.isFrontPage) {
        icon = import_icons.home;
      }
      if (suggestion.isBlogHome) {
        icon = import_icons.verse;
      }
    }
  }
  if (icon) {
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_icons.Icon,
      {
        className: "block-editor-link-control__search-item-icon",
        icon
      }
    );
  }
  return null;
}
function addLeadingSlash(url) {
  const trimmedURL = url?.trim();
  if (!trimmedURL?.length) {
    return url;
  }
  return url?.replace(/^\/?/, "/");
}
function removeTrailingSlash(url) {
  const trimmedURL = url?.trim();
  if (!trimmedURL?.length) {
    return url;
  }
  return url?.replace(/\/$/, "");
}
var partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
var defaultTo = (d) => (v) => {
  return v === null || v === void 0 || v !== v ? d : v;
};
function getURLForDisplay(url) {
  if (!url) {
    return url;
  }
  return (0, import_compose.pipe)(
    import_url.safeDecodeURI,
    import_url.getPath,
    defaultTo(""),
    partialRight(import_url.filterURLForDisplay, 24),
    removeTrailingSlash,
    addLeadingSlash
  )(url);
}
var LinkControlSearchItem = ({
  itemProps,
  suggestion,
  searchTerm,
  onClick,
  isURL = false,
  shouldShowType = false
}) => {
  const info = isURL ? (0, import_i18n.__)("Press ENTER to add this link") : getURLForDisplay(suggestion.url);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.MenuItem,
    {
      ...itemProps,
      info,
      iconPosition: "left",
      icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SearchItemIcon, { suggestion, isURL }),
      onClick,
      shortcut: shouldShowType && getVisualTypeName(suggestion),
      className: "block-editor-link-control__search-item",
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_components.TextHighlight,
        {
          text: (0, import_dom.__unstableStripHTML)(suggestion.title),
          highlight: searchTerm
        }
      )
    }
  );
};
function getVisualTypeName(suggestion) {
  if (suggestion.isFrontPage) {
    return (0, import_i18n.__)("Front page");
  }
  if (suggestion.isBlogHome) {
    return (0, import_i18n.__)("Blog home");
  }
  if (suggestion.type in TYPES) {
    return TYPES[suggestion.type].label;
  }
  return suggestion.type;
}
var search_item_default = LinkControlSearchItem;
var __experimentalLinkControlSearchItem = (props) => {
  (0, import_deprecated.default)("wp.blockEditor.__experimentalLinkControlSearchItem", {
    since: "6.8"
  });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LinkControlSearchItem, { ...props });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  LinkControlSearchItem,
  __experimentalLinkControlSearchItem
});
//# sourceMappingURL=search-item.js.map
