'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const separator = require('../../../separator.cjs');
const toolbarButton = require('../toolbar-button.cjs');
const reactIcons_esm = require('../../../../../../../node_modules/.pnpm/@radix-ui_react-icons@1.3.2_react@19.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');

function _interopNamespaceCompat(e) {
  if (e && typeof e === 'object' && 'default' in e) return e;
  const n = Object.create(null);
  if (e) {
    for (const k in e) {
      n[k] = e[k];
    }
  }
  n.default = e;
  return n;
}

const React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);

const LinkPopoverBlock = ({
  url,
  onClear,
  onEdit
}) => {
  const [copyTitle, setCopyTitle] = React__namespace.useState("Copy");
  const handleCopy = React__namespace.useCallback(
    (e) => {
      e.preventDefault();
      navigator.clipboard.writeText(url).then(() => {
        setCopyTitle("Copied!");
        setTimeout(() => setCopyTitle("Copy"), 1e3);
      }).catch(console.error);
    },
    [url]
  );
  const handleOpenLink = React__namespace.useCallback(() => {
    window.open(url, "_blank", "noopener,noreferrer");
  }, [url]);
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-background flex overflow-hidden rounded p-2 shadow-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "inline-flex items-center gap-1", children: [
    /* @__PURE__ */ jsxRuntime.jsx(toolbarButton.ToolbarButton, { tooltip: "Edit link", onClick: onEdit, children: "Edit link" }),
    /* @__PURE__ */ jsxRuntime.jsx(separator.Separator, { orientation: "vertical" }),
    /* @__PURE__ */ jsxRuntime.jsx(
      toolbarButton.ToolbarButton,
      {
        tooltip: "Open link in a new tab",
        onClick: handleOpenLink,
        children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.ExternalLinkIcon, {})
      }
    ),
    /* @__PURE__ */ jsxRuntime.jsx(separator.Separator, { orientation: "vertical" }),
    /* @__PURE__ */ jsxRuntime.jsx(toolbarButton.ToolbarButton, { tooltip: "Clear link", onClick: onClear, children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.LinkBreak2Icon, {}) }),
    /* @__PURE__ */ jsxRuntime.jsx(separator.Separator, { orientation: "vertical" }),
    /* @__PURE__ */ jsxRuntime.jsx(
      toolbarButton.ToolbarButton,
      {
        tooltip: copyTitle,
        onClick: handleCopy,
        tooltipOptions: {
          onPointerDownOutside: (e) => {
            if (e.target === e.currentTarget) e.preventDefault();
          }
        },
        children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.CopyIcon, {})
      }
    )
  ] }) });
};

exports.LinkPopoverBlock = LinkPopoverBlock;
