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/plus/pisellReservation/components/PisellReservationSubcomponents.tsx
var PisellReservationSubcomponents_exports = {};
__export(PisellReservationSubcomponents_exports, {
  PisellReservationScheduleEndActions: () => PisellReservationScheduleEndActions,
  PisellReservationToolbarTabs: () => PisellReservationToolbarTabs,
  RecordBoardBodyViewCapture: () => RecordBoardBodyViewCapture,
  ReservationDefaultScheduleStart: () => ReservationDefaultScheduleStart,
  ReservationFloorMapCanvasTabsTrailing: () => ReservationFloorMapCanvasTabsTrailing,
  ReservationFloorMapDockToolButtons: () => ReservationFloorMapDockToolButtons,
  ReservationGridTopRight: () => ReservationGridTopRight,
  ReservationMobileToolbarBodyViewSelect: () => ReservationMobileToolbarBodyViewSelect,
  ReservationVenueScheduleStart: () => ReservationVenueScheduleStart,
  ScheduleSyncOnFloorEnter: () => ScheduleSyncOnFloorEnter
});
module.exports = __toCommonJS(PisellReservationSubcomponents_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("@pisell/utils");
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_reservationDataUtils = require("../data/reservationDataUtils");
var import_reservationConstants = require("../reservationConstants");
var import_ReservationFloorMapDockAppearanceToggle = require("./ReservationFloorMapDockAppearanceToggle");
function RecordBoardBodyViewCapture(props) {
  const { bodyView } = (0, import_materials.useRecordBoardContext)();
  (0, import_react.useEffect)(() => {
    var _a;
    props.bodyViewRef.current = bodyView;
    (_a = props.onBodyViewChange) == null ? void 0 : _a.call(props, bodyView);
  }, [bodyView, props.bodyViewRef, props.onBodyViewChange]);
  return null;
}
function ScheduleSyncOnFloorEnter(props) {
  const { bodyView } = (0, import_materials.useRecordBoardContext)();
  const prevRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    const prev = prevRef.current;
    if (props.isInternalListData && (bodyView === "floorMap" || bodyView === "calendar" || bodyView === "resourceWall") && prev !== null && prev !== "floorMap" && prev !== "calendar" && prev !== "resourceWall") {
      props.patchSearchParams(
        (p) => (0, import_reservationDataUtils.stripCalendarOnlyFlags)(
          (0, import_reservationDataUtils.mergeSearchParamsBookingWindow)(
            p,
            props.schedule.date,
            props.operatingDayBoundary,
            props.timelineRange,
            (0, import_dayjs.default)()
          )
        )
      );
    }
    if (props.isInternalListData && (prev === "calendar" || prev === "resourceWall") && bodyView === "floorMap") {
      props.patchSearchParams(
        (p) => (0, import_reservationDataUtils.stripCalendarOnlyFlags)(
          (0, import_reservationDataUtils.mergeSearchParamsBookingWindow)(
            p,
            props.schedule.date,
            props.operatingDayBoundary,
            props.timelineRange,
            (0, import_dayjs.default)()
          )
        )
      );
    }
    if (props.isInternalListData && prev === "calendar" && (bodyView === "grid" || bodyView === "resourceWall")) {
      props.patchSearchParams(
        (p) => (0, import_reservationDataUtils.stripCalendarOnlyFlags)(
          (0, import_reservationDataUtils.mergeSearchParamsBookingWindow)(
            p,
            props.schedule.date,
            props.operatingDayBoundary,
            props.timelineRange,
            (0, import_dayjs.default)()
          )
        )
      );
    }
    prevRef.current = bodyView;
  }, [
    bodyView,
    props.schedule.date.valueOf(),
    props.isInternalListData,
    props.patchSearchParams,
    props.schedule.date,
    props.operatingDayBoundary,
    props.timelineRange
  ]);
  return null;
}
function useReservationBodyViewToggleState() {
  const { bodyViewSwitchable } = (0, import_materials.useRecordBoardContext)();
  const shellMeta = (0, import_materials.useRecordBoardShellBodyMeta)();
  const hasGrid = (shellMeta == null ? void 0 : shellMeta.hasGridContent) ?? true;
  const hasFloor = shellMeta == null ? void 0 : shellMeta.hasFloorMapSlot;
  const hasCalendar = shellMeta == null ? void 0 : shellMeta.hasCalendarSlot;
  const hasResourceWall = shellMeta == null ? void 0 : shellMeta.hasResourceWallSlot;
  const floorForToggle = shellMeta == null ? void 0 : shellMeta.effectiveFloorMapProps;
  const canFloor = Boolean(hasFloor && floorForToggle != null);
  const canCalendar = Boolean(hasCalendar);
  const canResourceWall = Boolean(hasResourceWall);
  const bodyViewOptionCount = (hasGrid ? 1 : 0) + (canFloor ? 1 : 0) + (canCalendar ? 1 : 0) + (canResourceWall ? 1 : 0);
  const allowBodyViewToggle = bodyViewOptionCount >= 2 && bodyViewSwitchable !== false;
  const bodyViewSegmentedOptions = (0, import_react.useMemo)(() => {
    const opts = [];
    if (canFloor) {
      opts.push({ label: import_utils.locales.getText(import_reservationConstants.I18N_VIEW_FLOOR), value: "floorMap" });
    }
    if (canCalendar) {
      opts.push({
        label: import_utils.locales.getText(import_reservationConstants.I18N_VIEW_CALENDAR),
        value: "calendar"
      });
    }
    if (canResourceWall) {
      opts.push({
        label: import_utils.locales.getText(import_reservationConstants.I18N_VIEW_RESOURCE_WALL),
        value: "resourceWall"
      });
    }
    if (hasGrid) {
      opts.push({ label: import_utils.locales.getText(import_reservationConstants.I18N_VIEW_GRID), value: "grid" });
    }
    return opts;
  }, [canFloor, canCalendar, canResourceWall, hasGrid]);
  return {
    allowBodyViewToggle,
    bodyViewSegmentedOptions
  };
}
function ReservationMobileToolbarBodyViewSelect() {
  const { bodyView, setBodyView } = (0, import_materials.useRecordBoardContext)();
  const { allowBodyViewToggle, bodyViewSegmentedOptions } = useReservationBodyViewToggleState();
  if (!allowBodyViewToggle) return null;
  if (bodyView !== "grid" && bodyView !== "resourceWall") return null;
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      className: "pisell-reservation-mobile-toolbar-body-view-select",
      popupClassName: "pisell-reservation-body-view-select-dropdown",
      popupMatchSelectWidth: false,
      size: "small",
      value: bodyView,
      onChange: (v) => setBodyView(v),
      options: bodyViewSegmentedOptions.map((o) => ({
        label: o.label,
        value: o.value
      }))
    }
  );
}
function PisellReservationToolbarTabs(props) {
  var _a, _b, _c, _d, _e, _f, _g;
  const { bodyView, setBodyView } = (0, import_materials.useRecordBoardContext)();
  const { allowBodyViewToggle, bodyViewSegmentedOptions } = useReservationBodyViewToggleState();
  if (bodyView === "grid") {
    return props.extraTabs ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.extraTabs) : null;
  }
  if (bodyView === "resourceWall") {
    return props.extraTabs ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.extraTabs) : null;
  }
  const segmentedSize = props.phoneLayout ? "middle" : "large";
  const bodyViewToggle = allowBodyViewToggle ? props.phoneLayout ? /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      className: "pisell-reservation-body-view-select",
      popupClassName: "pisell-reservation-body-view-select-dropdown",
      popupMatchSelectWidth: false,
      size: "middle",
      value: bodyView,
      onChange: (v) => setBodyView(v),
      options: bodyViewSegmentedOptions.map((o) => ({
        label: o.label,
        value: o.value
      }))
    }
  ) : /* @__PURE__ */ import_react.default.createElement(
    import_antd.Segmented,
    {
      className: "pisell-reservation-body-view-segmented",
      size: segmentedSize,
      value: bodyView,
      onChange: (v) => setBodyView(v),
      options: bodyViewSegmentedOptions
    }
  ) : null;
  const scheduleStartMerged = /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-start-merge" }, props.scheduleStartSlot, bodyViewToggle);
  const afterDateSlot = /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-follow-time-slot" }, props.phoneLayout ? props.followWallClock ? /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: "pisell-reservation-follow-current-chip pisell-reservation-follow-current-chip--on",
      "aria-live": "polite",
      "aria-label": import_utils.locales.getText(import_reservationConstants.I18N_AT_CURRENT_TIME)
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-follow-current-chip-dot" }),
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-follow-current-chip-label" }, import_utils.locales.getText(import_reservationConstants.I18N_AT_CURRENT_TIME_SHORT))
  ) : /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: "pisell-reservation-follow-current-chip pisell-reservation-follow-current-chip--off",
      onClick: props.onFollowWallClockToggle,
      "aria-pressed": false,
      "aria-label": import_utils.locales.getText(import_reservationConstants.I18N_GO_CURRENT)
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-follow-current-chip-label" }, import_utils.locales.getText(import_reservationConstants.I18N_GO_CURRENT))
  ) : props.followWallClock ? /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: "pisell-reservation-follow-time-hint pisell-reservation-follow-time-hint--at-current",
      "aria-live": "polite"
    },
    import_utils.locales.getText(import_reservationConstants.I18N_AT_CURRENT_TIME)
  ) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "span",
    {
      className: "pisell-reservation-follow-time-hint pisell-reservation-follow-time-hint--off-current",
      "aria-live": "polite"
    },
    import_utils.locales.getText(import_reservationConstants.I18N_NON_CURRENT_HINT)
  ), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: "pisell-reservation-follow-current-btn pisell-reservation-follow-current-btn--go-current",
      onClick: props.onFollowWallClockToggle,
      "aria-pressed": false
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-follow-current-btn-label" }, import_utils.locales.getText(import_reservationConstants.I18N_GO_CURRENT))
  )));
  const calendarNavUnit = bodyView === "calendar" ? props.calendarGranularity === "resource" ? "month" : props.calendarGranularity ?? "day" : "day";
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellReservationScheduleBand,
    {
      value: props.schedule,
      onChange: props.onScheduleChange,
      scheduleRowClassName: props.phoneLayout && !allowBodyViewToggle ? "pisell-reservation-schedule-band-schedule-row--phone-single-line" : void 0,
      hideTimeNavigator: bodyView === "calendar",
      scheduleProps: {
        ...props.scheduleProps,
        navigationLocked: Boolean((_a = props.scheduleProps) == null ? void 0 : _a.navigationLocked),
        ...bodyView === "calendar" ? { navigationUnit: calendarNavUnit } : {}
      },
      timeNavigatorProps: {
        range: import_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE,
        businessHours: import_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE,
        ...props.timeNavigatorProps,
        showNowButton: ((_b = props.timeNavigatorProps) == null ? void 0 : _b.showNowButton) ?? false,
        /**
         * 预约场景禁用时间轴吸附：松手后保留指针停留位置对应的连续时间，
         * 不再回弹到最近的 0/15/30/45 step 刻度。即使外层把 `snapToStep` 透传为 true，
         * 也在此被强制覆盖为 false，与 PisellReservation.tsx 的合并层形成双保险。
         */
        snapToStep: false,
        /**
         * 桌面：`cursor-moves`（拖指针）。手机：`axis-moves`（拖刻度轴，指针固定视口中央）。
         */
        cursorMode: props.phoneLayout ? "axis-moves" : "cursor-moves",
        onUserInteraction: () => {
          var _a2, _b2;
          props.onTimeNavigatorUserInteraction();
          (_b2 = (_a2 = props.timeNavigatorProps) == null ? void 0 : _a2.onUserInteraction) == null ? void 0 : _b2.call(_a2);
        },
        userInteractionLocked: Boolean(
          (_c = props.timeNavigatorProps) == null ? void 0 : _c.userInteractionLocked
        ),
        loadDensity: props.loadDensity,
        horizontalAxisCellSizePx: props.phoneLayout ? ((_d = props.timeNavigatorProps) == null ? void 0 : _d.horizontalAxisCellSizePx) ?? import_reservationConstants.PISELL_RESERVATION_PHONE_TIME_AXIS_CELL_PX : (_e = props.timeNavigatorProps) == null ? void 0 : _e.horizontalAxisCellSizePx,
        horizontalTrackHeightPx: props.phoneLayout ? ((_f = props.timeNavigatorProps) == null ? void 0 : _f.horizontalTrackHeightPx) ?? import_reservationConstants.PISELL_RESERVATION_PHONE_TIME_NAVIGATOR_HEIGHT_PX : (_g = props.timeNavigatorProps) == null ? void 0 : _g.horizontalTrackHeightPx
      },
      scheduleStartSlot: scheduleStartMerged,
      scheduleAfterDateSlot: afterDateSlot,
      scheduleEndSlot: props.scheduleEndSlot
    }
  ), props.extraTabs);
}
function ReservationGridTopRight(props) {
  const { bodyView } = (0, import_materials.useRecordBoardContext)();
  if (bodyView === "floorMap" || bodyView === "calendar") return null;
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.extra ?? null);
}
function PisellReservationScheduleEndActions(props) {
  const { bodyView } = (0, import_materials.useRecordBoardContext)();
  const shellMeta = (0, import_materials.useRecordBoardShellBodyMeta)();
  const showGranularity = bodyView === "calendar" && Boolean(shellMeta == null ? void 0 : shellMeta.hasCalendarSlot) && props.calendarGranularity != null && props.onCalendarGranularityChange != null;
  const segmentedSize = props.phoneLayout ? "middle" : "large";
  const granularityOpts = [
    {
      label: import_utils.locales.getText(import_reservationConstants.I18N_CALENDAR_RESOURCE),
      value: "resource"
    },
    { label: import_utils.locales.getText(import_reservationConstants.I18N_CALENDAR_DAY), value: "day" },
    { label: import_utils.locales.getText(import_reservationConstants.I18N_CALENDAR_WEEK), value: "week" },
    { label: import_utils.locales.getText(import_reservationConstants.I18N_CALENDAR_MONTH), value: "month" }
  ];
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-schedule-end-slots" }, showGranularity ? props.phoneLayout ? /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      className: "pisell-reservation-body-view-select pisell-reservation-calendar-granularity-select",
      popupClassName: "pisell-reservation-body-view-select-dropdown pisell-reservation-calendar-granularity-select-dropdown",
      popupMatchSelectWidth: false,
      size: "middle",
      value: props.calendarGranularity,
      onChange: (v) => {
        var _a;
        return (_a = props.onCalendarGranularityChange) == null ? void 0 : _a.call(props, v);
      },
      options: granularityOpts.map((o) => ({
        label: o.label,
        value: o.value
      }))
    }
  ) : /* @__PURE__ */ import_react.default.createElement(
    import_antd.Segmented,
    {
      className: "pisell-reservation-body-view-segmented pisell-reservation-calendar-granularity-segmented",
      size: segmentedSize,
      value: props.calendarGranularity,
      onChange: (v) => {
        var _a;
        return (_a = props.onCalendarGranularityChange) == null ? void 0 : _a.call(
          props,
          v
        );
      },
      options: granularityOpts
    }
  ) : null, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: props.phoneLayout ? "pisell-reservation-new-btn pisell-reservation-new-btn--phone" : "pisell-reservation-new-btn",
      onClick: () => {
        var _a;
        return (_a = props.onNewReservation) == null ? void 0 : _a.call(props);
      }
    },
    import_utils.locales.getText(import_reservationConstants.I18N_NEW)
  ));
}
function ReservationFloorMapDockToolButtons(props) {
  return /* @__PURE__ */ import_react.default.createElement(
    import_ReservationFloorMapDockAppearanceToggle.ReservationFloorMapDockAppearanceToggle,
    {
      mode: props.appearanceMode,
      onToggle: props.onToggleAppearanceMode
    }
  );
}
function ReservationFloorMapCanvasTabsTrailing(props) {
  const { bodyView } = (0, import_materials.useRecordBoardContext)();
  (0, import_react.useEffect)(() => {
    if (bodyView !== "floorMap" && props.mapEditInternal) {
      props.setMapEditInternal(false);
    }
  }, [bodyView, props.mapEditInternal, props.setMapEditInternal]);
  if (bodyView !== "floorMap") return null;
  if (props.isFloorModeControlled) return null;
  const editLabel = import_utils.locales.getText(
    props.mapEditInternal ? import_reservationConstants.I18N_EDIT_MAP_DONE : import_reservationConstants.I18N_EDIT_MAP
  );
  const handleToggleMapEdit = () => {
    var _a, _b;
    if (props.mapEditInternal) {
      (_b = (_a = props.floorMapLayoutRef.current) == null ? void 0 : _a.saveLayout) == null ? void 0 : _b.call(_a);
    }
    props.setMapEditInternal((v) => !v);
  };
  if (props.phoneLayout) {
    return /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        type: "button",
        className: props.mapEditInternal ? "pisell-floor-map-layout-view-controls-tool-btn pisell-floor-map-layout-view-controls-tool-btn--active" : "pisell-floor-map-layout-view-controls-tool-btn",
        title: editLabel,
        "aria-label": editLabel,
        "aria-pressed": props.mapEditInternal,
        onClick: handleToggleMapEdit
      },
      props.mapEditInternal ? /* @__PURE__ */ import_react.default.createElement(import_icons.CheckOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, null)
    );
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-reservation-floor-map-dock-actions" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      type: "primary",
      size: "middle",
      className: "pisell-reservation-topbar-edit-btn",
      onClick: handleToggleMapEdit
    },
    editLabel
  ));
}
function ReservationDefaultScheduleStart() {
  return /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-page-title" }, import_utils.locales.getText(import_reservationConstants.I18N_PAGE_TITLE));
}
function ReservationVenueScheduleStart() {
  return /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-reservation-page-title" }, import_utils.locales.getText(import_reservationConstants.I18N_PAGE_TITLE_VENUE));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PisellReservationScheduleEndActions,
  PisellReservationToolbarTabs,
  RecordBoardBodyViewCapture,
  ReservationDefaultScheduleStart,
  ReservationFloorMapCanvasTabsTrailing,
  ReservationFloorMapDockToolButtons,
  ReservationGridTopRight,
  ReservationMobileToolbarBodyViewSelect,
  ReservationVenueScheduleStart,
  ScheduleSyncOnFloorEnter
});
