"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/url-popover/index.js
var url_popover_exports = {};
__export(url_popover_exports, {
  default: () => url_popover_default
});
module.exports = __toCommonJS(url_popover_exports);
var import_i18n = require("@wordpress/i18n");
var import_element = require("@wordpress/element");
var import_components = require("@wordpress/components");
var import_icons = require("@wordpress/icons");
var import_deprecated = __toESM(require("@wordpress/deprecated"));
var import_link_viewer = __toESM(require("./link-viewer"));
var import_link_editor = __toESM(require("./link-editor"));
var import_lock_unlock = require("../../lock-unlock");
var import_jsx_runtime = require("react/jsx-runtime");
var { __experimentalPopoverLegacyPositionToPlacement } = (0, import_lock_unlock.unlock)(
  import_components.privateApis
);
var DEFAULT_PLACEMENT = "bottom";
var URLPopover = (0, import_element.forwardRef)(
  ({
    additionalControls,
    children,
    renderSettings,
    // The DEFAULT_PLACEMENT value is assigned inside the function's body
    placement,
    focusOnMount = "firstElement",
    // Deprecated
    position,
    // Rest
    ...popoverProps
  }, ref) => {
    if (position !== void 0) {
      (0, import_deprecated.default)("`position` prop in wp.blockEditor.URLPopover", {
        since: "6.2",
        alternative: "`placement` prop"
      });
    }
    let computedPlacement;
    if (placement !== void 0) {
      computedPlacement = placement;
    } else if (position !== void 0) {
      computedPlacement = __experimentalPopoverLegacyPositionToPlacement(position);
    }
    computedPlacement = computedPlacement || DEFAULT_PLACEMENT;
    const [isSettingsExpanded, setIsSettingsExpanded] = (0, import_element.useState)(false);
    const showSettings = !!renderSettings && isSettingsExpanded;
    const toggleSettingsVisibility = () => {
      setIsSettingsExpanded(!isSettingsExpanded);
    };
    return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_components.Popover,
      {
        ref,
        role: "dialog",
        "aria-modal": "true",
        "aria-label": (0, import_i18n.__)("Edit URL"),
        className: "block-editor-url-popover",
        focusOnMount,
        placement: computedPlacement,
        shift: true,
        variant: "toolbar",
        ...popoverProps,
        children: [
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-url-popover__input-container", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "block-editor-url-popover__row", children: [
            children,
            !!renderSettings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_components.Button,
              {
                className: "block-editor-url-popover__settings-toggle",
                icon: import_icons.chevronDown,
                label: (0, import_i18n.__)("Link settings"),
                onClick: toggleSettingsVisibility,
                "aria-expanded": isSettingsExpanded,
                size: "compact"
              }
            )
          ] }) }),
          showSettings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-url-popover__settings", children: renderSettings() }),
          additionalControls && !showSettings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-url-popover__additional-controls", children: additionalControls })
        ]
      }
    );
  }
);
URLPopover.LinkEditor = import_link_editor.default;
URLPopover.LinkViewer = import_link_viewer.default;
var url_popover_default = URLPopover;
//# sourceMappingURL=index.js.map
