"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var boundary_warning_exports = {};
__export(boundary_warning_exports, {
  BoundaryLine: () => BoundaryLine
});
module.exports = __toCommonJS(boundary_warning_exports);
var import_react_dom = require("@floating-ui/react-dom");
var import_design_system = require("@wix/design-system");
var import_react = __toESM(require("react"));
var import_react_dom2 = __toESM(require("react-dom"));
var import_ricos_context = require("./../ricos-context/index.js");
var import_card_scss = __toESM(require("./card-scss.js"));
var import_split_horizontally_small = require("./icons/split-horizontally-small.js");
const BoundaryLine = ({
  visible,
  onSplit,
  getBoundaryWarningPortal
}) => {
  const portal = getBoundaryWarningPortal?.() ?? null;
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const [isHovered, setIsHovered] = (0, import_react.useState)(false);
  const leaveTimer = (0, import_react.useRef)(null);
  const clearLeaveTimer = (0, import_react.useCallback)(() => {
    if (leaveTimer.current !== null) {
      clearTimeout(leaveTimer.current);
      leaveTimer.current = null;
    }
  }, []);
  const handleMouseEnter = (0, import_react.useCallback)(() => {
    clearLeaveTimer();
    setIsHovered(true);
  }, [clearLeaveTimer]);
  const handleMouseLeave = (0, import_react.useCallback)(() => {
    clearLeaveTimer();
    leaveTimer.current = setTimeout(() => {
      setIsHovered(false);
    }, 50);
  }, [clearLeaveTimer]);
  const {
    x,
    y,
    refs: { setReference, setFloating },
    strategy
  } = (0, import_react_dom.useFloating)({
    placement: "left",
    strategy: portal ? "fixed" : "absolute",
    middleware: [
      (0, import_react_dom.offset)(() => ({
        mainAxis: 8
      }))
    ],
    whileElementsMounted: (referenceEl, floatingEl, update) => (0, import_react_dom.autoUpdate)(referenceEl, floatingEl, update, { animationFrame: true })
  });
  const lineClassName = `${import_card_scss.default.cardBoundaryLineContent}${isHovered ? ` ${import_card_scss.default.hovered}` : ""}`;
  const iconContent = /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: setFloating,
      style: {
        position: strategy,
        top: y ?? "",
        left: x ?? "",
        zIndex: 1
      },
      onMouseEnter: handleMouseEnter,
      onMouseLeave: handleMouseLeave
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: `${import_card_scss.default.cardBoundaryWarning}${isHovered ? ` ${import_card_scss.default.hovered}` : ""}` }, /* @__PURE__ */ import_react.default.createElement(import_design_system.Tooltip, { content: t("Card_BoundaryWarning_Tooltip"), size: "small", placement: "left" }, /* @__PURE__ */ import_react.default.createElement(import_design_system.ToggleButton, { skin: "inverted", selected: true, tooltipDisabled: true, size: "small", onClick: onSplit }, /* @__PURE__ */ import_react.default.createElement(import_split_horizontally_small.SplitHorizontallySmall, null))))
  );
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: setReference,
      className: lineClassName,
      onMouseEnter: handleMouseEnter,
      onMouseLeave: handleMouseLeave
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: import_card_scss.default.cardBoundaryLine })
  ), visible && portal && import_react_dom2.default.createPortal(iconContent, portal));
};
//# sourceMappingURL=boundary-warning.js.map
