// packages/block-editor/src/components/url-popover/index.js
import { __ } from "@wordpress/i18n";
import { forwardRef, useState } from "@wordpress/element";
import {
  Button,
  Popover,
  privateApis as componentsPrivateApis
} from "@wordpress/components";
import { chevronDown } from "@wordpress/icons";
import deprecated from "@wordpress/deprecated";
import LinkViewer from "./link-viewer";
import LinkEditor from "./link-editor";
import { unlock } from "../../lock-unlock";
import { jsx, jsxs } from "react/jsx-runtime";
var { __experimentalPopoverLegacyPositionToPlacement } = unlock(
  componentsPrivateApis
);
var DEFAULT_PLACEMENT = "bottom";
var URLPopover = 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) {
      deprecated("`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] = useState(false);
    const showSettings = !!renderSettings && isSettingsExpanded;
    const toggleSettingsVisibility = () => {
      setIsSettingsExpanded(!isSettingsExpanded);
    };
    return /* @__PURE__ */ jsxs(
      Popover,
      {
        ref,
        role: "dialog",
        "aria-modal": "true",
        "aria-label": __("Edit URL"),
        className: "block-editor-url-popover",
        focusOnMount,
        placement: computedPlacement,
        shift: true,
        variant: "toolbar",
        ...popoverProps,
        children: [
          /* @__PURE__ */ jsx("div", { className: "block-editor-url-popover__input-container", children: /* @__PURE__ */ jsxs("div", { className: "block-editor-url-popover__row", children: [
            children,
            !!renderSettings && /* @__PURE__ */ jsx(
              Button,
              {
                className: "block-editor-url-popover__settings-toggle",
                icon: chevronDown,
                label: __("Link settings"),
                onClick: toggleSettingsVisibility,
                "aria-expanded": isSettingsExpanded,
                size: "compact"
              }
            )
          ] }) }),
          showSettings && /* @__PURE__ */ jsx("div", { className: "block-editor-url-popover__settings", children: renderSettings() }),
          additionalControls && !showSettings && /* @__PURE__ */ jsx("div", { className: "block-editor-url-popover__additional-controls", children: additionalControls })
        ]
      }
    );
  }
);
URLPopover.LinkEditor = LinkEditor;
URLPopover.LinkViewer = LinkViewer;
var url_popover_default = URLPopover;
export {
  url_popover_default as default
};
//# sourceMappingURL=index.js.map
