"use strict";
const Toggle = require("./Toggle-CAW20E9V.cjs");
const jsxRuntime = require("./jsx-runtime-B3vWrP5x.cjs");
const React = require("react");
require("./aggregator-Ca8xiVD2.cjs");
const css = require("./css-Pf9qxhQ4.cjs");
const Center = require("./Center-5NJ61qfA.cjs");
const Keyboard = require("./Keyboard-CsgjS96C.cjs");
const Status = (props) => {
  const { listen } = Toggle.useContext$1();
  const [trigger, setTrigger] = React.useState([]);
  React.useEffect(
    () => listen(({ next: [trigger2] }) => setTrigger(trigger2 ?? [])),
    [listen, setTrigger]
  );
  return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Toggle.Text, { ...props, children: trigger.join(" ") });
};
const useDrag = ({
  onDrag,
  triggers = [["MouseLeft"], ["MouseRight"]],
  bound,
  loose = false
}) => {
  const triggerRef = React.useRef(null);
  const startLoc = React.useRef(css.q.ZERO);
  const onMove = React.useCallback(
    (e) => {
      const cursor = css.q.construct(e);
      if (triggerRef.current === null)
        return;
      const { triggers: triggers2 } = triggerRef.current;
      onDrag({
        box: css.To.construct(startLoc.current, cursor),
        cursor,
        triggers: triggers2,
        stage: "during"
      });
    },
    [onDrag]
  );
  const handleTrigger = React.useCallback(
    (event) => {
      const { stage, cursor } = event;
      if (stage === "start") {
        onDrag({ box: css.To.construct(cursor), ...event });
        window.addEventListener("mousemove", onMove);
        triggerRef.current = event;
        startLoc.current = cursor;
      } else if (stage === "end" && triggerRef.current != null) {
        onDrag({ box: css.To.construct(startLoc.current, cursor), ...event });
        window.removeEventListener("mousemove", onMove);
        triggerRef.current = null;
        startLoc.current = css.q.ZERO;
      }
    },
    [onDrag]
  );
  Toggle.use$2({ triggers, callback: handleTrigger, region: bound, loose });
};
const CUSTOM_TEXT = {
  Control: () => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Toggle.Symbols.Meta, {}),
  Alt: () => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Toggle.Symbols.Alt, {}),
  Shift: () => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Toggle.m0.Keyboard.Shift, {}),
  MouseLeft: "Left Click",
  MouseRight: "Right Click",
  MouseMiddle: "Middle Click",
  Enter: () => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Toggle.m0.Keyboard.Return, {})
};
const getCustomText = (trigger) => {
  const t = CUSTOM_TEXT[trigger];
  if (t != null)
    return typeof t === "function" ? t() : t;
  return trigger;
};
const toSymbols = (trigger) => trigger.map((t) => getCustomText(t));
const Text = ({
  className,
  style,
  trigger,
  ...props
}) => {
  return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Center.Space, { className, style, direction: "x", children: trigger.map((t) => (
    // @ts-expect-error - issues with generic element types
    /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Keyboard.Keyboard, { ...props, children: getCustomText(t) }, t)
  )) });
};
const external = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  ALPHANUMERIC_KEYS: Toggle.ALPHANUMERIC_KEYS,
  ALPHANUMERIC_KEYS_SET: Toggle.ALPHANUMERIC_KEYS_SET,
  KEYS: Toggle.KEYS,
  MOUSE_KEYS: Toggle.MOUSE_KEYS,
  Provider: Toggle.Provider$1,
  Status,
  Text,
  compareModeConfigs: Toggle.compareModeConfigs,
  determineMode: Toggle.determineMode,
  diff: Toggle.diff,
  eventKey: Toggle.eventKey,
  filter: Toggle.filter,
  flattenConfig: Toggle.flattenConfig,
  keyZ: Toggle.keyZ,
  keyboardKey: Toggle.keyboardKey,
  match: Toggle.match,
  mouseKey: Toggle.mouseKey,
  mouseKeyZ: Toggle.mouseKeyZ,
  purge: Toggle.purge,
  purgeMouse: Toggle.purgeMouse,
  toSymbols,
  triggerZ: Toggle.triggerZ,
  use: Toggle.use$2,
  useContext: Toggle.useContext$1,
  useDrag,
  useFlattenedMemoConfig: Toggle.useFlattenedMemoConfig,
  useHeld: Toggle.useHeld,
  useHeldRef: Toggle.useHeldRef
}, Symbol.toStringTag, { value: "Module" }));
exports.Text = Text;
exports.external = external;
exports.useDrag = useDrag;
//# sourceMappingURL=external-kZAfJn1X.cjs.map
