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/pisellRecordBoard/shellFrame/index.tsx
var shellFrame_exports = {};
__export(shellFrame_exports, {
  RecordBoardBatchActionBar: () => import_BatchActionBar.default,
  RecordBoardCalendar: () => import_RecordBoardCalendar.default,
  RecordBoardFloorMap: () => import_FloorMap.default,
  RecordBoardPagination: () => import_Pagination.default,
  RecordBoardResourceWall: () => import_RecordBoardResourceWall.default,
  RecordBoardSearch: () => import_Search.default,
  RecordBoardToolBar: () => import_ToolBar.default,
  ToolBarQuickFilter: () => import_ToolBarQuickFilter.default,
  ToolBarReset: () => import_ToolBarReset.default,
  default: () => shellFrame_default,
  useRecordBoardShellBodyMeta: () => import_ShellBodyMetaContext2.useRecordBoardShellBodyMeta
});
module.exports = __toCommonJS(shellFrame_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_pisellShellFrame = require("../../pisellShellFrame");
var import_pisellFloorMapLayout = require("../../pisellFloorMapLayout");
var import_useRecordBoardContext = require("../hooks/useRecordBoardContext");
var import_partitionShellFrameChildren = require("../utils/partitionShellFrameChildren");
var import_ToolBar = __toESM(require("./ToolBar"));
var import_BatchActionBar = __toESM(require("./BatchActionBar"));
var import_Pagination = __toESM(require("./Pagination"));
var import_Search = __toESM(require("./Search"));
var import_shellFrameFloorMap = require("./shellFrameFloorMap.less");
var import_ToolBarReset = __toESM(require("./ToolBarReset"));
var import_ToolBarQuickFilter = __toESM(require("./ToolBarQuickFilter"));
var import_FloorMap = __toESM(require("./FloorMap"));
var import_RecordBoardCalendar = __toESM(require("./Calendar/RecordBoardCalendar"));
var import_PisellRecordBoardCalendarView = require("./Calendar/PisellRecordBoardCalendarView");
var import_RecordBoardResourceWall = __toESM(require("./ResourceWall/RecordBoardResourceWall"));
var import_PisellRecordBoardResourceWallView = require("./ResourceWall/PisellRecordBoardResourceWallView");
var import_ShellBodyMetaContext = require("./ShellBodyMetaContext");
var import_ShellBodyMetaContext2 = require("./ShellBodyMetaContext");
function mergeRecordBoardSlotProps(root, child) {
  if (!child || Object.keys(child).length === 0) {
    return root;
  }
  const base = { ...root ?? {} };
  for (const [key, val] of Object.entries(child)) {
    if (val !== void 0) {
      base[key] = val;
    }
  }
  return base;
}
var FILL_HEIGHT_SCROLL_STYLE = {
  flex: 1,
  minHeight: 0,
  overflow: "auto"
};
function ScrollAreaMeasurer({
  children,
  onHeight,
  autoCalc
}) {
  const ref = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    const el = ref.current;
    if (!el) return;
    const ro = new ResizeObserver((entries) => {
      const entry = entries[0];
      if (entry) onHeight(entry.contentRect.height);
    });
    ro.observe(el);
    onHeight(el.getBoundingClientRect().height);
    return () => {
      ro.disconnect();
      onHeight(null);
    };
  }, [onHeight]);
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref,
      className: "pisell-record-board-scroll-body",
      style: {
        ...FILL_HEIGHT_SCROLL_STYLE,
        overflow: autoCalc ? "hidden" : "auto"
      }
    },
    children
  );
}
var FILL_HEIGHT_WRAPPER_STYLE = {
  flex: 1,
  minHeight: 0,
  display: "flex",
  flexDirection: "column"
};
var RecordBoardShellFrame = ({ children, className, style, belowToolbar }) => {
  var _a, _b, _c;
  const ctx = (0, import_useRecordBoardContext.useRecordBoardContext)();
  const fillHeight = (ctx == null ? void 0 : ctx.fillHeight) === true;
  const {
    gridChildren,
    floorMapPropsFromChild,
    calendarPropsFromChild,
    resourceWallPropsFromChild,
    hasGridContent,
    hasFloorMapChild,
    hasCalendarChild,
    hasResourceWallChild
  } = (0, import_react.useMemo)(() => (0, import_partitionShellFrameChildren.partitionShellFrameChildren)(children), [children]);
  const effectiveFloorMapProps = (0, import_react.useMemo)(() => {
    if (hasFloorMapChild) {
      return mergeRecordBoardSlotProps(
        ctx.floorMapProps,
        floorMapPropsFromChild
      );
    }
    return ctx.floorMapProps;
  }, [hasFloorMapChild, floorMapPropsFromChild, ctx.floorMapProps]);
  const effectiveCalendarProps = (0, import_react.useMemo)(() => {
    if (hasCalendarChild) {
      return mergeRecordBoardSlotProps(
        ctx.calendarProps,
        calendarPropsFromChild
      );
    }
    return ctx.calendarProps;
  }, [hasCalendarChild, calendarPropsFromChild, ctx.calendarProps]);
  const effectiveResourceWallProps = (0, import_react.useMemo)(() => {
    if (hasResourceWallChild) {
      return mergeRecordBoardSlotProps(
        ctx.resourceWallProps,
        resourceWallPropsFromChild
      );
    }
    return ctx.resourceWallProps;
  }, [hasResourceWallChild, resourceWallPropsFromChild, ctx.resourceWallProps]);
  const mergedFloorMapDataSources = (0, import_react.useMemo)(() => {
    const root = ctx.dataSources;
    const fromFloor = effectiveFloorMapProps == null ? void 0 : effectiveFloorMapProps.dataSources;
    if (root == null && fromFloor == null) return void 0;
    return { ...root ?? {}, ...fromFloor ?? {} };
  }, [ctx.dataSources, effectiveFloorMapProps == null ? void 0 : effectiveFloorMapProps.dataSources]);
  const hasFloorMapSlot = hasFloorMapChild || ctx.floorMapProps != null;
  const hasCalendarSlot = hasCalendarChild || ctx.calendarProps != null;
  const hasResourceWallSlot = hasResourceWallChild || ctx.resourceWallProps != null;
  const shellBodyMeta = (0, import_react.useMemo)(
    () => ({
      effectiveFloorMapProps,
      effectiveCalendarProps,
      effectiveResourceWallProps,
      hasGridContent,
      hasFloorMapSlot,
      hasCalendarSlot,
      hasResourceWallSlot
    }),
    [
      effectiveFloorMapProps,
      effectiveCalendarProps,
      effectiveResourceWallProps,
      hasGridContent,
      hasFloorMapSlot,
      hasCalendarSlot,
      hasResourceWallSlot
    ]
  );
  const showGrid = (0, import_react.useMemo)(
    () => hasGridContent && ctx.bodyView === "grid",
    [hasGridContent, ctx.bodyView]
  );
  const showGridPagination = showGrid && ctx.gridInfiniteScroll !== true;
  const showFloorMap = (0, import_react.useMemo)(
    () => hasFloorMapSlot && effectiveFloorMapProps != null && ctx.bodyView === "floorMap",
    [hasFloorMapSlot, effectiveFloorMapProps, ctx.bodyView]
  );
  const showCalendar = (0, import_react.useMemo)(
    () => hasCalendarSlot && ctx.bodyView === "calendar",
    [hasCalendarSlot, ctx.bodyView]
  );
  const showResourceWall = (0, import_react.useMemo)(
    () => hasResourceWallSlot && ctx.bodyView === "resourceWall",
    [hasResourceWallSlot, ctx.bodyView]
  );
  (0, import_react.useLayoutEffect)(() => {
    if (!ctx.setBodyView) return;
    const hasG = hasGridContent;
    const hasF = hasFloorMapSlot;
    const hasC = hasCalendarSlot;
    const hasR = hasResourceWallSlot;
    const n = [hasG, hasF, hasC, hasR].filter(Boolean).length;
    if (n !== 1) return;
    if (hasF && !hasG && !hasC && !hasR) {
      ctx.setBodyView("floorMap");
      return;
    }
    if (hasC && !hasG && !hasF && !hasR) {
      ctx.setBodyView("calendar");
      return;
    }
    if (hasR && !hasG && !hasF && !hasC) {
      ctx.setBodyView("resourceWall");
      return;
    }
    if (hasG && !hasF && !hasC && !hasR) {
      ctx.setBodyView("grid");
    }
  }, [
    hasFloorMapSlot,
    hasGridContent,
    hasCalendarSlot,
    hasResourceWallSlot,
    ctx.setBodyView
  ]);
  const floorMapLayoutProviderValue = (0, import_react.useMemo)(
    () => ctx.floorMapLayoutContext ?? import_pisellFloorMapLayout.EMPTY_FLOOR_MAP_LAYOUT_CONTEXT,
    [ctx.floorMapLayoutContext]
  );
  const floorMapNode = showFloorMap && effectiveFloorMapProps ? /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-record-board-floor-map-viewport",
      style: {
        flex: 1,
        minHeight: 0,
        display: "flex",
        flexDirection: "column",
        overflow: "hidden",
        position: "relative"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_pisellFloorMapLayout.FloorMapLayoutProvider, { value: floorMapLayoutProviderValue }, /* @__PURE__ */ import_react.default.createElement(
      import_pisellFloorMapLayout.PisellFloorMapLayout,
      {
        ref: ctx.floorMapLayoutRef ?? void 0,
        ...effectiveFloorMapProps,
        ...mergedFloorMapDataSources !== void 0 ? { dataSources: mergedFloorMapDataSources } : {},
        items: effectiveFloorMapProps.items ?? [],
        renderItem: effectiveFloorMapProps.renderItem ?? (() => null),
        style: {
          flex: 1,
          minHeight: 0,
          ...effectiveFloorMapProps.style ?? {}
        }
      }
    )),
    ctx.floorMapFooter ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-record-board-floor-map-floating-slot" }, ctx.floorMapFooter) : null
  ) : null;
  const calendarNode = showCalendar && effectiveCalendarProps ? /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-record-board-calendar-viewport",
      style: {
        flex: 1,
        minHeight: 0,
        display: "flex",
        flexDirection: "column",
        overflow: "hidden",
        position: "relative"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_PisellRecordBoardCalendarView.PisellRecordBoardCalendarView, { ...effectiveCalendarProps })
  ) : null;
  const resourceWallNode = showResourceWall && effectiveResourceWallProps ? /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-record-board-resource-wall-viewport",
      style: {
        flex: 1,
        minHeight: 0,
        display: "flex",
        flexDirection: "column",
        overflow: "hidden",
        position: "relative"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(import_PisellRecordBoardResourceWallView.PisellRecordBoardResourceWallView, { ...effectiveResourceWallProps })
  ) : null;
  const bodyContent = fillHeight ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, showGrid ? /* @__PURE__ */ import_react.default.createElement(
    ScrollAreaMeasurer,
    {
      onHeight: (ctx == null ? void 0 : ctx.setScrollAreaHeight) ?? (() => {
      }),
      autoCalc: (_c = (_b = (_a = ctx == null ? void 0 : ctx.childComponentProps) == null ? void 0 : _a.grid) == null ? void 0 : _b.scroll) == null ? void 0 : _c.autoCalc
    },
    gridChildren
  ) : showResourceWall ? resourceWallNode : showCalendar ? calendarNode : floorMapNode, showGridPagination ? /* @__PURE__ */ import_react.default.createElement(import_Pagination.default, null) : null) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, showGrid ? gridChildren : showResourceWall ? resourceWallNode : showCalendar ? calendarNode : floorMapNode, showGridPagination ? /* @__PURE__ */ import_react.default.createElement(import_Pagination.default, null) : null);
  const shellStyle = fillHeight && style ? { ...style, ...FILL_HEIGHT_WRAPPER_STYLE } : fillHeight ? FILL_HEIGHT_WRAPPER_STYLE : style;
  const wrapper = /* @__PURE__ */ import_react.default.createElement(import_ShellBodyMetaContext.RecordBoardShellBodyMetaContext.Provider, { value: shellBodyMeta }, /* @__PURE__ */ import_react.default.createElement(
    import_pisellShellFrame.PisellShellFrame,
    {
      className: (0, import_classnames.default)(className, {
        /** 非表格主区：工具栏与内容区无缝（与 PisellShellFrame.less body-subview 配对） */
        "pisell-shell-frame--body-subview": !showGrid,
        "pisell-shell-frame--grid-view": showGrid,
        "pisell-shell-frame--floor-map-view": showFloorMap,
        "pisell-shell-frame--calendar-view": showCalendar,
        "pisell-shell-frame--resource-wall-view": showResourceWall
      }),
      style: shellStyle,
      config: {
        showToolbar: true,
        showBatchActionBar: true
      },
      toolbar: /* @__PURE__ */ import_react.default.createElement(import_ToolBar.default, null),
      belowToolbar,
      batchActionBar: /* @__PURE__ */ import_react.default.createElement(import_BatchActionBar.default, null)
    },
    bodyContent
  ));
  if (fillHeight) {
    return /* @__PURE__ */ import_react.default.createElement("div", { style: FILL_HEIGHT_WRAPPER_STYLE }, wrapper);
  }
  return wrapper;
};
RecordBoardShellFrame.displayName = "RecordBoard.ShellFrame";
var shellFrame_default = RecordBoardShellFrame;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RecordBoardBatchActionBar,
  RecordBoardCalendar,
  RecordBoardFloorMap,
  RecordBoardPagination,
  RecordBoardResourceWall,
  RecordBoardSearch,
  RecordBoardToolBar,
  ToolBarQuickFilter,
  ToolBarReset,
  useRecordBoardShellBodyMeta
});
