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);

// src/components/pisellFloorMapLayout/components/ViewControls.tsx
var ViewControls_exports = {};
__export(ViewControls_exports, {
  ViewControls: () => ViewControls,
  default: () => ViewControls_default
});
module.exports = __toCommonJS(ViewControls_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_ViewControls = require("./ViewControls.less");
var PREFIX = "pisell-floor-map-layout";
var I18N_VC = "pisell-floor-map-layout.view-controls";
function ViewControls(props) {
  const {
    api,
    config = {},
    scale = 1,
    isFullscreen = false,
    className,
    mapGridVisible = false,
    onToggleMapGrid,
    dockChrome = false,
    dockExpandedTrailing,
    autoCollapseDockMs = 1e4
  } = props;
  const showZoom = config.showZoom !== false;
  const showReset = config.showReset === true;
  const showFitBounds = config.showFitBounds === true;
  const showFullscreen = config.showFullscreen === true;
  const showGridToggle = config.showGridToggle === true && typeof onToggleMapGrid === "function";
  const scalePercent = Math.round(scale * 100);
  const showTools = showReset || showFitBounds || showFullscreen || showGridToggle;
  const hasTrailingSlot = dockExpandedTrailing != null && dockExpandedTrailing !== false;
  const dockHasExpandable = dockChrome && (showTools || hasTrailingSlot);
  const showBar = showZoom || showTools || dockChrome && hasTrailingSlot;
  const [dockExpanded, setDockExpanded] = (0, import_react.useState)(false);
  const [dockPanelMounted, setDockPanelMounted] = (0, import_react.useState)(false);
  const dockExpandedRef = (0, import_react.useRef)(dockExpanded);
  dockExpandedRef.current = dockExpanded;
  const idleTimerRef = (0, import_react.useRef)(null);
  const clearIdleTimer = (0, import_react.useCallback)(() => {
    if (idleTimerRef.current != null) {
      clearTimeout(idleTimerRef.current);
      idleTimerRef.current = null;
    }
  }, []);
  const scheduleDockCollapse = (0, import_react.useCallback)(() => {
    clearIdleTimer();
    if (!dockChrome || !dockHasExpandable || !dockExpanded || autoCollapseDockMs <= 0) {
      return;
    }
    idleTimerRef.current = setTimeout(() => {
      setDockExpanded(false);
      idleTimerRef.current = null;
    }, autoCollapseDockMs);
  }, [
    dockChrome,
    dockHasExpandable,
    dockExpanded,
    autoCollapseDockMs,
    clearIdleTimer
  ]);
  (0, import_react.useEffect)(() => {
    return () => clearIdleTimer();
  }, [clearIdleTimer]);
  (0, import_react.useEffect)(() => {
    if (dockExpanded && dockHasExpandable) {
      scheduleDockCollapse();
    }
  }, [dockExpanded, dockHasExpandable, scheduleDockCollapse]);
  const handleDockSlideTransitionEnd = (0, import_react.useCallback)(
    (e) => {
      if (e.propertyName !== "max-width" || e.target !== e.currentTarget) {
        return;
      }
      if (!dockExpandedRef.current) {
        setDockPanelMounted(false);
      }
    },
    []
  );
  const handleDockExpand = (0, import_react.useCallback)(() => {
    setDockPanelMounted(true);
    requestAnimationFrame(() => {
      requestAnimationFrame(() => {
        setDockExpanded(true);
      });
    });
  }, []);
  const handleDockCollapseClick = (0, import_react.useCallback)(() => {
    clearIdleTimer();
    setDockExpanded(false);
  }, [clearIdleTimer]);
  const handleDockBarPointerDown = (0, import_react.useCallback)(() => {
    if (dockExpanded && autoCollapseDockMs > 0) {
      scheduleDockCollapse();
    }
  }, [dockExpanded, autoCollapseDockMs, scheduleDockCollapse]);
  const renderToolButtons = () => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, showReset ? /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: () => api.resetTransform(),
      "aria-label": import_utils.locales.getText(`${I18N_VC}.reset-aria`)
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.ReloadOutlined, null)
  ) : null, showFitBounds && api.fitBounds ? /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: () => api.fitBounds(),
      "aria-label": import_utils.locales.getText(`${I18N_VC}.fit-bounds-aria`)
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.ExpandOutlined, null)
  ) : null, showGridToggle ? /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: (0, import_classnames.default)(`${PREFIX}-view-controls-tool-btn`, {
        [`${PREFIX}-view-controls-tool-btn--active`]: mapGridVisible
      }),
      onClick: () => onToggleMapGrid(),
      "aria-pressed": mapGridVisible,
      "aria-label": import_utils.locales.getText(
        mapGridVisible ? `${I18N_VC}.grid-hide-aria` : `${I18N_VC}.grid-show-aria`
      )
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.BorderInnerOutlined, null)
  ) : null, showFullscreen && api.toggleFullscreen ? /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: () => api.toggleFullscreen(),
      "aria-label": import_utils.locales.getText(
        isFullscreen ? `${I18N_VC}.fullscreen-exit-aria` : `${I18N_VC}.fullscreen-aria`
      )
    },
    isFullscreen ? /* @__PURE__ */ import_react.default.createElement(import_icons.FullscreenExitOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.FullscreenOutlined, null)
  ) : null);
  const renderDockExpandableBarContents = () => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, showZoom ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: () => api.zoomOut(),
      "aria-label": import_utils.locales.getText(`${I18N_VC}.zoom-out-aria`)
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.MinusOutlined, null)
  ), /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX}-view-controls-zoom-value` }, scalePercent, "%"), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: () => api.zoomIn(),
      "aria-label": import_utils.locales.getText(`${I18N_VC}.zoom-in-aria`)
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
  )) : null, showZoom && (showTools || hasTrailingSlot) ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-view-controls-bar-divider`, "aria-hidden": true }) : null, showTools ? renderToolButtons() : null, hasTrailingSlot ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-view-controls-dock-trailing` }, dockExpandedTrailing) : null, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: `${PREFIX}-view-controls-tool-btn`,
      onClick: handleDockCollapseClick,
      "aria-expanded": dockExpanded,
      "aria-label": import_utils.locales.getText(`${I18N_VC}.collapse-tools-aria`)
    },
    /* @__PURE__ */ import_react.default.createElement(import_icons.LeftOutlined, null)
  ));
  if (!showBar) {
    return null;
  }
  if (dockChrome && dockHasExpandable) {
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          `${PREFIX}-view-controls`,
          `${PREFIX}-view-controls--dock`,
          className
        )
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-view-controls-dock-row` }, /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: (0, import_classnames.default)(`${PREFIX}-view-controls-dock-expand-btn`, {
            [`${PREFIX}-view-controls-dock-expand-btn--panel-open`]: dockExpanded
          }),
          onClick: handleDockExpand,
          "aria-expanded": dockExpanded,
          "aria-hidden": dockExpanded,
          tabIndex: dockExpanded ? -1 : 0,
          "aria-label": import_utils.locales.getText(`${I18N_VC}.expand-tools-aria`)
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.RightOutlined, null)
      ), dockPanelMounted ? /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)(`${PREFIX}-view-controls-dock-slide`, {
            [`${PREFIX}-view-controls-dock-slide--open`]: dockExpanded
          }),
          onTransitionEnd: handleDockSlideTransitionEnd
        },
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: (0, import_classnames.default)(
              `${PREFIX}-view-controls-bar`,
              `${PREFIX}-view-controls-bar--dock`
            ),
            role: "group",
            onPointerDown: handleDockBarPointerDown
          },
          renderDockExpandableBarContents()
        )
      ) : null)
    );
  }
  const barClass = (0, import_classnames.default)(`${PREFIX}-view-controls-bar`, {
    [`${PREFIX}-view-controls-bar--dock`]: dockChrome
  });
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(`${PREFIX}-view-controls`, className, {
        [`${PREFIX}-view-controls--dock`]: dockChrome
      })
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: barClass,
        role: "group",
        onPointerDown: dockChrome ? handleDockBarPointerDown : void 0
      },
      showZoom ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: `${PREFIX}-view-controls-tool-btn`,
          onClick: () => api.zoomOut(),
          "aria-label": import_utils.locales.getText(`${I18N_VC}.zoom-out-aria`)
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.MinusOutlined, null)
      ), /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX}-view-controls-zoom-value` }, scalePercent, "%"), /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: `${PREFIX}-view-controls-tool-btn`,
          onClick: () => api.zoomIn(),
          "aria-label": import_utils.locales.getText(`${I18N_VC}.zoom-in-aria`)
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
      )) : null,
      !dockChrome && showTools ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, showZoom ? /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `${PREFIX}-view-controls-bar-divider`,
          "aria-hidden": true
        }
      ) : null, renderToolButtons()) : null
    )
  );
}
var ViewControls_default = ViewControls;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ViewControls
});
