'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const tooltip = require('../../../../tooltip.cjs');
const utils = require('../../../../../lib/utils.cjs');
const button = require('../../../../button.cjs');
const dropdownMenu = require('../../../../dropdown-menu.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 ActionWrapper = ({
  children,
  className,
  ...props
}) => /* @__PURE__ */ jsxRuntime.jsx(
  "div",
  {
    className: utils.cn(
      "absolute top-3 right-3 flex flex-row rounded px-0.5 opacity-0 group-hover/node-image:opacity-100",
      "border-[0.5px] bg-[var(--mt-bg-secondary)] [backdrop-filter:saturate(1.8)_blur(20px)]",
      className
    ),
    ...props,
    children
  }
);
ActionWrapper.displayName = "ActionWrapper";
const ActionButton = ({
  icon,
  tooltip: tooltip$1,
  className,
  ...props
}) => /* @__PURE__ */ jsxRuntime.jsxs(tooltip.Tooltip, { children: [
  /* @__PURE__ */ jsxRuntime.jsx(tooltip.TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
    button.Button,
    {
      variant: "ghost",
      className: utils.cn(
        "text-muted-foreground hover:text-foreground relative flex h-7 w-7 flex-row rounded-none p-0",
        "bg-transparent hover:bg-transparent",
        className
      ),
      ...props,
      children: icon
    }
  ) }),
  /* @__PURE__ */ jsxRuntime.jsx(tooltip.TooltipContent, { side: "bottom", children: tooltip$1 })
] });
ActionButton.displayName = "ActionButton";
const ActionItems = [
  {
    key: "onView",
    icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.SizeIcon, {}),
    tooltip: "View image"
  },
  {
    key: "onDownload",
    icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.DownloadIcon, {}),
    tooltip: "Download image"
  },
  {
    key: "onCopy",
    icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.ClipboardCopyIcon, {}),
    tooltip: "Copy image to clipboard"
  },
  {
    key: "onCopyLink",
    icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.Link2Icon, {}),
    tooltip: "Copy image link",
    isLink: true
  }
];
const ImageActions = ({
  shouldMerge = false,
  isLink = false,
  ...actions
}) => {
  const [isOpen, setIsOpen] = React__namespace.useState(false);
  const handleAction = React__namespace.useCallback(
    (e, action) => {
      e.preventDefault();
      e.stopPropagation();
      action?.();
    },
    []
  );
  const filteredActions = React__namespace.useMemo(
    () => ActionItems.filter((item) => isLink || !item.isLink),
    [isLink]
  );
  return /* @__PURE__ */ jsxRuntime.jsx(ActionWrapper, { className: utils.cn({ "opacity-100": isOpen }), children: shouldMerge ? /* @__PURE__ */ jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { open: isOpen, onOpenChange: setIsOpen, children: [
    /* @__PURE__ */ jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
      ActionButton,
      {
        icon: /* @__PURE__ */ jsxRuntime.jsx(reactIcons_esm.DotsHorizontalIcon, {}),
        tooltip: "Open menu",
        onClick: (e) => e.preventDefault()
      }
    ) }),
    /* @__PURE__ */ jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { className: "w-56", align: "end", children: filteredActions.map(({ key, icon, tooltip }) => /* @__PURE__ */ jsxRuntime.jsx(
      dropdownMenu.DropdownMenuItem,
      {
        onClick: (e) => handleAction(e, actions[key]),
        children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2", children: [
          icon,
          /* @__PURE__ */ jsxRuntime.jsx("span", { children: tooltip })
        ] })
      },
      key
    )) })
  ] }) : filteredActions.map(({ key, icon, tooltip }) => /* @__PURE__ */ jsxRuntime.jsx(
    ActionButton,
    {
      icon,
      tooltip,
      onClick: (e) => handleAction(e, actions[key])
    },
    key
  )) });
};
ImageActions.displayName = "ImageActions";

exports.ActionButton = ActionButton;
exports.ActionWrapper = ActionWrapper;
exports.ImageActions = ImageActions;
