import { jsx, jsxs } from 'react/jsx-runtime';
import * as React from 'react';
import { Separator } from '../../../separator.mjs';
import { ToolbarButton } from '../toolbar-button.mjs';
import { ExternalLinkIcon, LinkBreak2Icon, CopyIcon } from '../../../../../../../node_modules/.pnpm/@radix-ui_react-icons@1.3.2_react@19.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.mjs';

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

export { LinkPopoverBlock };
