/**
 * FloorMapEditTopBar - 编辑态顶栏
 * - `mode="compact"`：画布 Tab + 可选 `canvasTabsBarTrailing`（全屏入口在左下 Dock）
 * - `mode="full"`：画布 Tab + `canvasTabsBarTrailing` + 保存（仅非浏览器全屏时）+ 扩展操作
 */
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import useEngineContext from "../../../hooks/useEngineContext";
import { initFloorMapLayoutLocales } from "../utils/floorMapCanvasDisplay";
import { CanvasTabs } from "./CanvasTabs";
import "./FloorMapEditTopBar.less";
var PREFIX = 'pisell-floor-map-layout';
var I18N_TB = 'pisell-floor-map-layout.edit-top-bar';
export function FloorMapEditTopBar(props) {
  var _engineCtx$engine;
  var _props$mode = props.mode,
    mode = _props$mode === void 0 ? 'full' : _props$mode,
    config = props.config,
    canvases = props.canvases,
    currentCanvasId = props.currentCanvasId,
    onTabChange = props.onTabChange,
    _props$canEditTabs = props.canEditTabs,
    canEditTabs = _props$canEditTabs === void 0 ? false : _props$canEditTabs,
    onAddCanvas = props.onAddCanvas,
    onRemoveCanvas = props.onRemoveCanvas,
    onRenameCanvas = props.onRenameCanvas,
    onSave = props.onSave,
    saving = props.saving,
    saveError = props.saveError,
    layoutDirty = props.layoutDirty,
    _props$isFullscreen = props.isFullscreen,
    isFullscreen = _props$isFullscreen === void 0 ? false : _props$isFullscreen,
    extraActions = props.extraActions,
    canvasTabsBarTrailing = props.canvasTabsBarTrailing,
    _props$hideCanvasTabs = props.hideCanvasTabs,
    hideCanvasTabs = _props$hideCanvasTabs === void 0 ? false : _props$hideCanvasTabs,
    className = props.className;
  var engineCtx = useEngineContext();
  var engineLocale = (engineCtx === null || engineCtx === void 0 || (_engineCtx$engine = engineCtx.engine) === null || _engineCtx$engine === void 0 || (_engineCtx$engine = _engineCtx$engine.props) === null || _engineCtx$engine === void 0 ? void 0 : _engineCtx$engine.locale) || 'zh-CN';
  var topBarLabels = useMemo(function () {
    initFloorMapLayoutLocales(engineLocale);
    return {
      aria: locales.getText("".concat(I18N_TB, ".aria")),
      unsaved: locales.getText("".concat(I18N_TB, ".unsaved")),
      save: locales.getText("".concat(I18N_TB, ".save")),
      saving: locales.getText("".concat(I18N_TB, ".saving"))
    };
  }, [engineLocale]);

  /** 浏览器全屏时顶栏不展示保存，改由侧栏承担（见 PisellFloorMapLayout 对 Toolbar onSave 的互斥逻辑） */
  var showSave = Boolean(onSave && config.canvasUi.canEdit) && !isFullscreen;
  var hasTrailing = canvasTabsBarTrailing != null && canvasTabsBarTrailing !== false;
  var hasFullActions = showSave || Boolean(saveError) || extraActions != null && extraActions !== false || hasTrailing;
  var tabsHiddenClass = hideCanvasTabs ? "".concat(PREFIX, "-edit-top-bar--tabs-hidden") : undefined;
  if (mode === 'compact') {
    var showCompactActions = hasTrailing;
    return /*#__PURE__*/React.createElement("div", {
      className: classNames("".concat(PREFIX, "-edit-top-bar"), "".concat(PREFIX, "-edit-top-bar--compact"), tabsHiddenClass, className),
      role: "toolbar",
      "aria-label": topBarLabels.aria
    }, !hideCanvasTabs ? /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "-edit-top-bar-tabs")
    }, /*#__PURE__*/React.createElement(CanvasTabs, {
      canvases: canvases,
      currentCanvasId: currentCanvasId,
      onTabChange: onTabChange,
      canEdit: canEditTabs,
      onAddCanvas: onAddCanvas,
      onRemoveCanvas: onRemoveCanvas,
      onRenameCanvas: onRenameCanvas,
      className: "".concat(PREFIX, "-edit-top-bar-canvas-tabs")
    })) : null, showCompactActions ? /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "-edit-top-bar-actions")
    }, canvasTabsBarTrailing) : null);
  }
  if (hideCanvasTabs && !hasFullActions) {
    return null;
  }
  return /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(PREFIX, "-edit-top-bar"), "".concat(PREFIX, "-edit-top-bar--full-chrome"), tabsHiddenClass, className),
    role: "toolbar",
    "aria-label": topBarLabels.aria
  }, !hideCanvasTabs ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "-edit-top-bar-tabs")
  }, /*#__PURE__*/React.createElement(CanvasTabs, {
    canvases: canvases,
    currentCanvasId: currentCanvasId,
    onTabChange: onTabChange,
    canEdit: canEditTabs,
    onAddCanvas: onAddCanvas,
    onRemoveCanvas: onRemoveCanvas,
    onRenameCanvas: onRenameCanvas,
    className: "".concat(PREFIX, "-edit-top-bar-canvas-tabs")
  })) : null, hasFullActions ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "-edit-top-bar-actions")
  }, saveError ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "-edit-top-bar-error"),
    title: typeof saveError === 'string' ? saveError : saveError === null || saveError === void 0 ? void 0 : saveError.message
  }, typeof saveError === 'string' ? saveError : saveError === null || saveError === void 0 ? void 0 : saveError.message) : null, canvasTabsBarTrailing, extraActions, showSave ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "-edit-top-bar-save-group")
  }, layoutDirty ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "-edit-top-bar-dirty-badge"),
    role: "status",
    "aria-live": "polite"
  }, topBarLabels.unsaved) : null, /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: classNames("".concat(PREFIX, "-edit-top-bar-btn"), 'primary'),
    disabled: saving,
    onClick: onSave
  }, saving ? topBarLabels.saving : topBarLabels.save)) : null) : null);
}
export default FloorMapEditTopBar;