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/FloorMapEditTopBar.tsx
var FloorMapEditTopBar_exports = {};
__export(FloorMapEditTopBar_exports, {
  FloorMapEditTopBar: () => FloorMapEditTopBar,
  default: () => FloorMapEditTopBar_default
});
module.exports = __toCommonJS(FloorMapEditTopBar_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_floorMapCanvasDisplay = require("../utils/floorMapCanvasDisplay");
var import_CanvasTabs = require("./CanvasTabs");
var import_FloorMapEditTopBar = require("./FloorMapEditTopBar.less");
var PREFIX = "pisell-floor-map-layout";
var I18N_TB = "pisell-floor-map-layout.edit-top-bar";
function FloorMapEditTopBar(props) {
  var _a, _b;
  const {
    mode = "full",
    config,
    canvases,
    currentCanvasId,
    onTabChange,
    canEditTabs = false,
    onAddCanvas,
    onRemoveCanvas,
    onRenameCanvas,
    onSave,
    saving,
    saveError,
    layoutDirty,
    isFullscreen = false,
    extraActions,
    canvasTabsBarTrailing,
    hideCanvasTabs = false,
    className
  } = props;
  const engineCtx = (0, import_useEngineContext.default)();
  const engineLocale = ((_b = (_a = engineCtx == null ? void 0 : engineCtx.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "zh-CN";
  const topBarLabels = (0, import_react.useMemo)(() => {
    (0, import_floorMapCanvasDisplay.initFloorMapLayoutLocales)(engineLocale);
    return {
      aria: import_utils.locales.getText(`${I18N_TB}.aria`),
      unsaved: import_utils.locales.getText(`${I18N_TB}.unsaved`),
      save: import_utils.locales.getText(`${I18N_TB}.save`),
      saving: import_utils.locales.getText(`${I18N_TB}.saving`)
    };
  }, [engineLocale]);
  const showSave = Boolean(onSave && config.canvasUi.canEdit) && !isFullscreen;
  const hasTrailing = canvasTabsBarTrailing != null && canvasTabsBarTrailing !== false;
  const hasFullActions = showSave || Boolean(saveError) || extraActions != null && extraActions !== false || hasTrailing;
  const tabsHiddenClass = hideCanvasTabs ? `${PREFIX}-edit-top-bar--tabs-hidden` : void 0;
  if (mode === "compact") {
    const showCompactActions = hasTrailing;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)(
          `${PREFIX}-edit-top-bar`,
          `${PREFIX}-edit-top-bar--compact`,
          tabsHiddenClass,
          className
        ),
        role: "toolbar",
        "aria-label": topBarLabels.aria
      },
      !hideCanvasTabs ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-top-bar-tabs` }, /* @__PURE__ */ import_react.default.createElement(
        import_CanvasTabs.CanvasTabs,
        {
          canvases,
          currentCanvasId,
          onTabChange,
          canEdit: canEditTabs,
          onAddCanvas,
          onRemoveCanvas,
          onRenameCanvas,
          className: `${PREFIX}-edit-top-bar-canvas-tabs`
        }
      )) : null,
      showCompactActions ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-top-bar-actions` }, canvasTabsBarTrailing) : null
    );
  }
  if (hideCanvasTabs && !hasFullActions) {
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        `${PREFIX}-edit-top-bar`,
        `${PREFIX}-edit-top-bar--full-chrome`,
        tabsHiddenClass,
        className
      ),
      role: "toolbar",
      "aria-label": topBarLabels.aria
    },
    !hideCanvasTabs ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-top-bar-tabs` }, /* @__PURE__ */ import_react.default.createElement(
      import_CanvasTabs.CanvasTabs,
      {
        canvases,
        currentCanvasId,
        onTabChange,
        canEdit: canEditTabs,
        onAddCanvas,
        onRemoveCanvas,
        onRenameCanvas,
        className: `${PREFIX}-edit-top-bar-canvas-tabs`
      }
    )) : null,
    hasFullActions ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-top-bar-actions` }, saveError ? /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: `${PREFIX}-edit-top-bar-error`,
        title: typeof saveError === "string" ? saveError : saveError == null ? void 0 : saveError.message
      },
      typeof saveError === "string" ? saveError : saveError == null ? void 0 : saveError.message
    ) : null, canvasTabsBarTrailing, extraActions, showSave ? /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}-edit-top-bar-save-group` }, layoutDirty ? /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: `${PREFIX}-edit-top-bar-dirty-badge`,
        role: "status",
        "aria-live": "polite"
      },
      topBarLabels.unsaved
    ) : null, /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: (0, import_classnames.default)(`${PREFIX}-edit-top-bar-btn`, "primary"),
        disabled: saving,
        onClick: onSave
      },
      saving ? topBarLabels.saving : topBarLabels.save
    )) : null) : null
  );
}
var FloorMapEditTopBar_default = FloorMapEditTopBar;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  FloorMapEditTopBar
});
