import { j as jsxRuntimeExports } from "../../../../../_virtual/jsx-runtime.js";
import { forwardRef } from "react";
import { useEditorHelpers, useDebugMode } from "../../../../../use-editor.js";
import "../../../../../node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import { toast as c } from "../../../../../node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hot-toast/dist/index.js";
import { useBrickManifest } from "../../shared/hooks/use-brick-manifest.js";
import { useDraftHelpers } from "../../../../../use-page-data.js";
import { Root as h, Trigger as S, Content as v, Label as y, Item as R, Sub as w, SubTrigger as B, SubContent as k, CheckboxItem as G, Separator as W } from "../../../../../node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/context-menu.js";
import { Portal as r } from "../../../../../node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/portal.js";
const EditableBrickContextMenu = forwardRef(
  ({ brick, isContainerChild, children }, ref) => {
    const draftHelpers = useDraftHelpers();
    const editorHelpers = useEditorHelpers();
    const debugMode = useDebugMode();
    const manifest = useBrickManifest(brick.type);
    const canMovePrev = draftHelpers.canMoveTo(brick.id, "previous");
    const canMoveNext = draftHelpers.canMoveTo(brick.id, "next");
    const parentContainer = draftHelpers.getParentBrick(brick.id);
    const parentElement = parentContainer ? document.getElementById(parentContainer.id) : null;
    const flexOrientation = parentElement ? getComputedStyle(parentElement).flexDirection || "row" : "row";
    return /* @__PURE__ */ jsxRuntimeExports.jsxs(
      h,
      {
        modal: false,
        onOpenChange: (menuOpen) => {
          editorHelpers.setContextMenuVisible(menuOpen);
        },
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(S, { disabled: debugMode, ref, children }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(r, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(v, { className: "nodrag", size: "2", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs(y, { className: "!text-sm", children: [
              manifest.name,
              " (brick)"
            ] }),
            manifest.duplicatable && /* @__PURE__ */ jsxRuntimeExports.jsx(
              R,
              {
                shortcut: "⌘D",
                onClick: (e) => {
                  e.stopPropagation();
                  draftHelpers.duplicateBrick(brick.id);
                },
                children: "Duplicate"
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              R,
              {
                onClick: (e) => {
                  e.stopPropagation();
                  navigator.clipboard.writeText(JSON.stringify(brick));
                  c(
                    `Brick "${manifest.name}" copied to clipboard. You can paste it on this page or another page.`,
                    {
                      className: "min-w-fit"
                    }
                  );
                },
                children: "Copy brick"
              }
            ),
            canMovePrev && /* @__PURE__ */ jsxRuntimeExports.jsx(
              R,
              {
                shortcut: isContainerChild ? "⌘↑" : "⌘←",
                onClick: (e) => {
                  e.stopPropagation();
                  draftHelpers.moveBrick(brick.id, "previous");
                },
                children: isContainerChild && flexOrientation === "column" ? "Move up" : "Move left"
              }
            ),
            canMoveNext && /* @__PURE__ */ jsxRuntimeExports.jsx(
              R,
              {
                shortcut: isContainerChild ? "⌘↓" : "⌘→",
                onClick: (e) => {
                  e.stopPropagation();
                  draftHelpers.moveBrick(brick.id, "next");
                },
                children: isContainerChild && flexOrientation === "column" ? "Move down" : "Move right"
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(w, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(B, { children: "Visible on" }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs(k, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  G,
                  {
                    checked: !brick.props.hidden?.mobile,
                    onClick: (e) => e.stopPropagation(),
                    onCheckedChange: () => draftHelpers.toggleBrickVisibilityPerBreakpoint(brick.id, "mobile"),
                    children: "Mobile"
                  }
                ),
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  G,
                  {
                    checked: !brick.props.hidden?.desktop,
                    onClick: (e) => e.stopPropagation(),
                    onCheckedChange: () => draftHelpers.toggleBrickVisibilityPerBreakpoint(brick.id, "desktop"),
                    children: "Desktop"
                  }
                )
              ] })
            ] }),
            parentContainer && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(W, {}),
              /* @__PURE__ */ jsxRuntimeExports.jsxs(w, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(B, { children: "Parent container" }),
                /* @__PURE__ */ jsxRuntimeExports.jsxs(k, { children: [
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    R,
                    {
                      onClick: (e) => {
                        e.stopPropagation();
                        draftHelpers.duplicateBrick(parentContainer.id);
                      },
                      children: "Duplicate container"
                    }
                  ),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    R,
                    {
                      onClick: (e) => {
                        e.stopPropagation();
                        editorHelpers.setSelectedBrickId(parentContainer.id);
                        editorHelpers.setPanel("inspector");
                      },
                      children: "Edit container"
                    }
                  ),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(W, {}),
                  /* @__PURE__ */ jsxRuntimeExports.jsx(
                    R,
                    {
                      shortcut: "⌫",
                      color: "red",
                      onClick: (e) => {
                        e.stopPropagation();
                        draftHelpers.deleteBrick(parentContainer.id);
                        editorHelpers.deselectBrick(parentContainer.id);
                        editorHelpers.hidePanel("inspector");
                      },
                      children: "Delete container"
                    }
                  )
                ] })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                R,
                {
                  onClick: (e) => {
                    e.stopPropagation();
                    draftHelpers.detachBrickFromContainer(brick.id);
                  },
                  children: "Detach from parent"
                }
              )
            ] }),
            manifest.deletable && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(W, {}),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                R,
                {
                  shortcut: "⌫",
                  color: "red",
                  onClick: (e) => {
                    e.stopPropagation();
                    draftHelpers.deleteBrick(brick.id);
                    editorHelpers.deselectBrick(brick.id);
                    editorHelpers.hidePanel("inspector");
                  },
                  children: "Delete"
                }
              )
            ] })
          ] }) })
        ]
      }
    );
  }
);
export {
  EditableBrickContextMenu as default
};
//# sourceMappingURL=EditableBrickContextMenu.js.map
