function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/**
 * 预约页拆出的轻量子组件（无业务数据请求）：
 * - `RecordBoardBodyViewCapture`：把当前 grid/floorMap 同步到父组件 ref，供 debounce effect 读 bodyView；
 * - `ScheduleSyncOnFloorEnter`：从表格回到平面图时，用当前营业日 patch 预约列表时间窗口；
 * - `PisellReservationToolbarTabs`：平面图下的日程带 + 表格/平面图 Segmented；
 * - `ReservationGridTopRight` / `PisellReservationScheduleEndActions` / `ReservationFloorMapCanvasTabsTrailing`：工具栏与画布尾区。
 */
import React, { useEffect, useRef } from 'react';
import { locales } from '@pisell/utils';
import { Button, Segmented } from 'antd';
import { PisellReservationScheduleBand, useRecordBoardContext, useRecordBoardShellBodyMeta } from '@pisell/materials';
import { mergeSearchParamsBookingWindow } from "../data/reservationDataUtils";
import { I18N_AT_CURRENT_TIME, I18N_EDIT_MAP, I18N_EDIT_MAP_DONE, I18N_GO_CURRENT, I18N_NEW, I18N_NON_CURRENT_HINT, I18N_PAGE_TITLE, I18N_PAGE_TITLE_VENUE, I18N_VIEW_FLOOR, I18N_VIEW_GRID, RESERVATION_TIMELINE_BUSINESS_RANGE } from "../reservationConstants";

/** 无 UI：仅将 RecordBoard Context 中的 `bodyView` 写入 ref */
export function RecordBoardBodyViewCapture(props) {
  var _useRecordBoardContex = useRecordBoardContext(),
    bodyView = _useRecordBoardContex.bodyView;
  useEffect(function () {
    props.bodyViewRef.current = bodyView;
  }, [bodyView, props.bodyViewRef]);
  return null;
}

/** 从表格切回平面图时，用当前日程把列表区间同步到平面图维度 */
export function ScheduleSyncOnFloorEnter(props) {
  var _useRecordBoardContex2 = useRecordBoardContext(),
    bodyView = _useRecordBoardContex2.bodyView;
  var prevRef = useRef(null);
  useEffect(function () {
    var prev = prevRef.current;
    if (props.isInternalListData && bodyView === 'floorMap' && prev !== null && prev !== 'floorMap') {
      props.patchSearchParams(function (p) {
        return mergeSearchParamsBookingWindow(p, props.schedule.date);
      });
    }
    prevRef.current = bodyView;
  }, [bodyView, props.schedule.date.valueOf(), props.isInternalListData, props.patchSearchParams, props.schedule.date]);
  return null;
}
/**
 * 顶栏 tabs：平面图下为日程带 + 时间轴 + 标题旁切换；表格下不展示 ScheduleBand，
 * 切换器由 RecordBoard 工具栏顶行（Find 左侧）承担，与历史行为一致。
 */
export function PisellReservationToolbarTabs(props) {
  var _shellMeta$hasGridCon, _props$scheduleProps, _props$timeNavigatorP, _props$timeNavigatorP2, _props$timeNavigatorP3, _props$timeNavigatorP4, _props$timeNavigatorP7;
  var _useRecordBoardContex3 = useRecordBoardContext(),
    bodyView = _useRecordBoardContex3.bodyView,
    setBodyView = _useRecordBoardContex3.setBodyView,
    bodyViewSwitchable = _useRecordBoardContex3.bodyViewSwitchable;
  var shellMeta = useRecordBoardShellBodyMeta();
  var hasGrid = (_shellMeta$hasGridCon = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasGridContent) !== null && _shellMeta$hasGridCon !== void 0 ? _shellMeta$hasGridCon : true;
  var hasFloor = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasFloorMapSlot;
  var floorForToggle = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.effectiveFloorMapProps;
  var showTableFloorToggle = hasGrid && hasFloor && floorForToggle != null;
  var allowBodyViewToggle = showTableFloorToggle && bodyViewSwitchable !== false;
  if (bodyView === 'grid') {
    return props.extraTabs ? /*#__PURE__*/React.createElement(React.Fragment, null, props.extraTabs) : null;
  }
  var bodyViewToggle = allowBodyViewToggle ? /*#__PURE__*/React.createElement(Segmented, {
    className: "pisell-reservation-body-view-segmented",
    size: "large",
    value: bodyView,
    onChange: function onChange(v) {
      return setBodyView(v);
    },
    options: [{
      label: locales.getText(I18N_VIEW_FLOOR),
      value: 'floorMap'
    }, {
      label: locales.getText(I18N_VIEW_GRID),
      value: 'grid'
    }]
  }) : null;
  var scheduleStartMerged = /*#__PURE__*/React.createElement("div", {
    className: "pisell-reservation-schedule-start-merge"
  }, props.scheduleStartSlot, bodyViewToggle);
  var afterDateSlot = /*#__PURE__*/React.createElement("div", {
    className: "pisell-reservation-follow-time-slot"
  }, props.followWallClock ? /*#__PURE__*/React.createElement("span", {
    className: "pisell-reservation-follow-time-hint pisell-reservation-follow-time-hint--at-current",
    "aria-live": "polite"
  }, locales.getText(I18N_AT_CURRENT_TIME)) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
    className: "pisell-reservation-follow-time-hint pisell-reservation-follow-time-hint--off-current",
    "aria-live": "polite"
  }, locales.getText(I18N_NON_CURRENT_HINT)), /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: "pisell-reservation-follow-current-btn pisell-reservation-follow-current-btn--go-current",
    onClick: props.onFollowWallClockToggle,
    "aria-pressed": false
  }, /*#__PURE__*/React.createElement("span", {
    className: "pisell-reservation-follow-current-btn-label"
  }, locales.getText(I18N_GO_CURRENT)))));
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PisellReservationScheduleBand, {
    value: props.schedule,
    onChange: props.onScheduleChange,
    scheduleProps: _objectSpread(_objectSpread({}, props.scheduleProps), {}, {
      navigationLocked: Boolean((_props$scheduleProps = props.scheduleProps) === null || _props$scheduleProps === void 0 ? void 0 : _props$scheduleProps.navigationLocked)
    }),
    timeNavigatorProps: _objectSpread(_objectSpread({
      range: RESERVATION_TIMELINE_BUSINESS_RANGE,
      businessHours: RESERVATION_TIMELINE_BUSINESS_RANGE
    }, props.timeNavigatorProps), {}, {
      showNowButton: (_props$timeNavigatorP = (_props$timeNavigatorP2 = props.timeNavigatorProps) === null || _props$timeNavigatorP2 === void 0 ? void 0 : _props$timeNavigatorP2.showNowButton) !== null && _props$timeNavigatorP !== void 0 ? _props$timeNavigatorP : false,
      snapToStep: false,
      cursorMode: (_props$timeNavigatorP3 = (_props$timeNavigatorP4 = props.timeNavigatorProps) === null || _props$timeNavigatorP4 === void 0 ? void 0 : _props$timeNavigatorP4.cursorMode) !== null && _props$timeNavigatorP3 !== void 0 ? _props$timeNavigatorP3 : 'cursor-moves',
      onUserInteraction: function onUserInteraction() {
        var _props$timeNavigatorP5, _props$timeNavigatorP6;
        props.onTimeNavigatorUserInteraction();
        (_props$timeNavigatorP5 = props.timeNavigatorProps) === null || _props$timeNavigatorP5 === void 0 || (_props$timeNavigatorP6 = _props$timeNavigatorP5.onUserInteraction) === null || _props$timeNavigatorP6 === void 0 || _props$timeNavigatorP6.call(_props$timeNavigatorP5);
      },
      userInteractionLocked: Boolean((_props$timeNavigatorP7 = props.timeNavigatorProps) === null || _props$timeNavigatorP7 === void 0 ? void 0 : _props$timeNavigatorP7.userInteractionLocked),
      loadDensity: props.loadDensity
    }),
    scheduleStartSlot: scheduleStartMerged,
    scheduleAfterDateSlot: afterDateSlot,
    scheduleEndSlot: props.scheduleEndSlot
  }), props.extraTabs);
}

/** 表格视图时展示工具栏右上角透传；平面图时收起（编辑入口在画布 Tab 行右侧） */
export function ReservationGridTopRight(props) {
  var _props$extra;
  var _useRecordBoardContex4 = useRecordBoardContext(),
    bodyView = _useRecordBoardContex4.bodyView;
  if (bodyView === 'floorMap') return null;
  return /*#__PURE__*/React.createElement(React.Fragment, null, (_props$extra = props.extra) !== null && _props$extra !== void 0 ? _props$extra : null);
}
/** 顶栏日程带右侧：新建 */
export function PisellReservationScheduleEndActions(props) {
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-reservation-schedule-end-slots"
  }, /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: "pisell-reservation-new-btn",
    onClick: function onClick() {
      var _props$onNewReservati;
      return (_props$onNewReservati = props.onNewReservation) === null || _props$onNewReservati === void 0 ? void 0 : _props$onNewReservati.call(props);
    }
  }, locales.getText(I18N_NEW)));
}
/** 平面图左下 Dock 展开区：编辑 / 完成编辑（经 PisellFloorMapLayout.viewportDockTrailing） */
export function ReservationFloorMapCanvasTabsTrailing(props) {
  var _useRecordBoardContex5 = useRecordBoardContext(),
    bodyView = _useRecordBoardContex5.bodyView;
  useEffect(function () {
    if (bodyView !== 'floorMap' && props.mapEditInternal) {
      props.setMapEditInternal(false);
    }
  }, [bodyView, props.mapEditInternal, props.setMapEditInternal]);
  if (props.isFloorModeControlled || bodyView !== 'floorMap') return null;
  return /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    size: "middle",
    className: "pisell-reservation-topbar-edit-btn",
    onClick: function onClick() {
      if (props.mapEditInternal) {
        var _props$floorMapLayout, _props$floorMapLayout2;
        (_props$floorMapLayout = props.floorMapLayoutRef.current) === null || _props$floorMapLayout === void 0 || (_props$floorMapLayout2 = _props$floorMapLayout.saveLayout) === null || _props$floorMapLayout2 === void 0 || _props$floorMapLayout2.call(_props$floorMapLayout);
      }
      props.setMapEditInternal(function (v) {
        return !v;
      });
    }
  }, locales.getText(props.mapEditInternal ? I18N_EDIT_MAP_DONE : I18N_EDIT_MAP));
}

/** 默认顶栏标题 slot */
export function ReservationDefaultScheduleStart() {
  return /*#__PURE__*/React.createElement("span", {
    className: "pisell-reservation-page-title"
  }, locales.getText(I18N_PAGE_TITLE));
}

/** 场控页顶栏标题 slot */
export function ReservationVenueScheduleStart() {
  return /*#__PURE__*/React.createElement("span", {
    className: "pisell-reservation-page-title"
  }, locales.getText(I18N_PAGE_TITLE_VENUE));
}