var _excluded = ["resourceWallSortFieldKeys", "list"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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); }
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); }
import React, { useCallback, useMemo } from 'react';
import classNames from 'classnames';
import { Button, Space, Segmented } from 'antd';
import SwitchVertical01 from '@pisell/icon/es/SwitchVertical01';
import PisellToolBar from "../../../pisellGridPro/ToolBar";
import { PisellFind } from "../../../pisellFind";
import PisellFilter from "../../../pisellFilter";
import Sort from "../../../sort";
import ToolBarReset from "../ToolBarReset";
import ToolBarQuickFilter from "../ToolBarQuickFilter";
import RecordBoardColumnSetting from "../ColumnSetting";
import { useRecordBoardShellBodyMeta } from "../ShellBodyMetaContext";
import { useRecordBoardContext } from "../../hooks/useRecordBoardContext";
import { locales as utilsLocales } from '@pisell/utils';
import { getText } from "../../../../locales";
import { deriveFilterFromColumns, deriveSortFromColumns } from "../../utils/recordBoardColumns";
import { DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS, matchesResourceWallStatusSortField } from "../ResourceWall/venueWallUtils";
import "./ToolBarFilter.less";
import "./recordBoardToolbar.less";

/** 与 Quick Filter 同源：优先 utils，若 utils 返回 key（未命中）则用 materials 再回退 */
function getSortButtonText() {
  var key = 'pisell2.recordBoard.toolbar.sort';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || getText('sort-button-text');
}
/** 资源墙无状态列派生项时注入：下拉仅「状态 → 空闲优先 / 占用优先」，仍渲染排序按钮 */
function buildResourceWallStatusSortFallbackItem(sortConfig) {
  var extras = _typeof(sortConfig) === 'object' && sortConfig !== null && Array.isArray(sortConfig.resourceWallSortFieldKeys) ? sortConfig.resourceWallSortFieldKeys.map(function (x) {
    return String(x).trim();
  }).filter(Boolean) : [];
  var primaryKey = extras.length > 0 ? extras[0] : DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS[0];
  return {
    name: primaryKey,
    label: getText('pisell2.recordBoard.toolbar.sortStatus'),
    isCustom: true,
    getSortItems: function getSortItems() {
      return [{
        key: "".concat(primaryKey, ":asc:option"),
        label: getText('pisell2.recordBoard.toolbar.sortStatusFreeFirst')
      }, {
        key: "".concat(primaryKey, ":desc:option"),
        label: getText('pisell2.recordBoard.toolbar.sortStatusOccupiedFirst')
      }];
    }
  };
}
function getFilterButtonText() {
  var key = 'pisell2.recordBoard.toolbar.filter';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || getText('table-action-filter-button');
}
function getViewGridLabel() {
  var key = 'pisell2.recordBoard.toolbar.viewGrid';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || 'Table';
}
function getViewFloorMapLabel() {
  var key = 'pisell2.recordBoard.toolbar.viewFloorMap';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || 'Floor map';
}
function getViewCalendarLabel() {
  var key = 'pisell2.recordBoard.toolbar.viewCalendar';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || 'Calendar';
}
function getViewResourceWallLabel() {
  var key = 'pisell2.recordBoard.toolbar.viewResourceWall';
  var u = utilsLocales.getText(key);
  return u && u !== key ? u : getText(key) || 'Wall';
}

/** 默认搜索参数字段名，与 context.searchParams 对应 */
var DEFAULT_SEARCH_FIELD = 'keyword';

/** 筛选在 searchParams 中的字段名 */
var FILTER_PARAMS_FIELD = 'filter';

/** 排序在 searchParams 中的字段名 */
var SORT_PARAMS_FIELD = 'sort';

/** 与 ResourceWall 默认 `filterFieldKey` 一致；预约等场景下快筛仅此一项时仅服务资源墙视图 */
var RESOURCE_WALL_QUICK_FILTER_KEY = 'resource_wall_resource_ids';

/** 筛选无值时使用的默认筛选项，避免点开为空；业务可通过 childComponentProps.toolBar.filter.defaultFilterValue 覆盖。文案通过 getText 多语言。 */
function getDefaultFilterValue() {
  return {
    quickFilter: [],
    otherFilter: []
  };
}

/**
 * RecordBoard 下的工具栏：使用 PisellToolBar。
 * 左侧默认 PisellFind（inline）；右侧默认 PisellFilter。通过 childComponentProps.toolBar.search / toolBar.filter 为对象时透传对应组件 props，为 false 时不渲染。
 * 可透传 topLeft、topRight、bottomLeft、bottomRight、tabs。
 */
var RecordBoardToolBar = function RecordBoardToolBar(props) {
  var _ctx$resourceWallProp, _ctx$resourceWallProp2, _shellMeta$hasGridCon, _shellMeta$hasFloorMa, _shellMeta$hasCalenda, _shellMeta$hasResourc, _shellMeta$effectiveF, _ctx$childComponentPr, _ctx$childComponentPr2, _slots$toolbarDensity, _searchParams$DEFAULT, _ctx$childComponentPr3, _formFiltersPrefix, _filterResetKey;
  var ctx = useRecordBoardContext({
    displayName: 'toolBar'
  });
  var shellMeta = useRecordBoardShellBodyMeta();
  var searchParams = ctx.searchParams,
    onSearch = ctx.onSearch,
    bodyView = ctx.bodyView,
    setBodyView = ctx.setBodyView;
  var resourceWallFilterFieldKey = (_ctx$resourceWallProp = (_ctx$resourceWallProp2 = ctx.resourceWallProps) === null || _ctx$resourceWallProp2 === void 0 ? void 0 : _ctx$resourceWallProp2.filterFieldKey) !== null && _ctx$resourceWallProp !== void 0 ? _ctx$resourceWallProp : RESOURCE_WALL_QUICK_FILTER_KEY;
  /** ShellFrame 内解析：多子视图（表格 / 平面图 / 日历）时渲染 Segmented */
  var hasGridInShell = (_shellMeta$hasGridCon = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasGridContent) !== null && _shellMeta$hasGridCon !== void 0 ? _shellMeta$hasGridCon : true;
  var hasFloorInShell = (_shellMeta$hasFloorMa = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasFloorMapSlot) !== null && _shellMeta$hasFloorMa !== void 0 ? _shellMeta$hasFloorMa : ctx.floorMapProps != null;
  var hasCalendarInShell = (_shellMeta$hasCalenda = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasCalendarSlot) !== null && _shellMeta$hasCalenda !== void 0 ? _shellMeta$hasCalenda : ctx.calendarProps != null;
  var hasResourceWallInShell = (_shellMeta$hasResourc = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.hasResourceWallSlot) !== null && _shellMeta$hasResourc !== void 0 ? _shellMeta$hasResourc : ctx.resourceWallProps != null;
  var floorForToggle = (_shellMeta$effectiveF = shellMeta === null || shellMeta === void 0 ? void 0 : shellMeta.effectiveFloorMapProps) !== null && _shellMeta$effectiveF !== void 0 ? _shellMeta$effectiveF : ctx.floorMapProps;
  var canFloor = hasFloorInShell && floorForToggle != null;
  var canCalendar = hasCalendarInShell;
  var canResourceWall = hasResourceWallInShell;
  var canGrid = hasGridInShell;
  var bodyViewOptionCount = (canGrid ? 1 : 0) + (canFloor ? 1 : 0) + (canCalendar ? 1 : 0) + (canResourceWall ? 1 : 0);
  /** 至少两种主区时出现切换器（兼容原「仅表格+平面图」） */
  var showTableFloorToggle = bodyViewOptionCount >= 2;
  /** 业务可关闭多视图切换（如场控仅平面图），此时不渲染 Segmented */
  var allowBodyViewToggle = showTableFloorToggle && ctx.bodyViewSwitchable !== false;
  var slots = (_ctx$childComponentPr = (_ctx$childComponentPr2 = ctx.childComponentProps) === null || _ctx$childComponentPr2 === void 0 ? void 0 : _ctx$childComponentPr2.toolBar) !== null && _ctx$childComponentPr !== void 0 ? _ctx$childComponentPr : {};
  var toolbarDensity = (_slots$toolbarDensity = slots.toolbarDensity) !== null && _slots$toolbarDensity !== void 0 ? _slots$toolbarDensity : 'default';
  /** compact 用 middle：比 50px Figma 略紧凑，又比 small 更易点按；与下方 Less 中 ~38px 工具栏样式一致 */
  var barSize = toolbarDensity === 'compact' ? 'middle' : 'large';
  var keyword = (_searchParams$DEFAULT = searchParams === null || searchParams === void 0 ? void 0 : searchParams[DEFAULT_SEARCH_FIELD]) !== null && _searchParams$DEFAULT !== void 0 ? _searchParams$DEFAULT : '';
  var handleSearch = useCallback(function (value) {
    onSearch(_objectSpread(_objectSpread({}, searchParams), {}, _defineProperty({}, DEFAULT_SEARCH_FIELD, value || undefined)));
  }, [onSearch, searchParams]);
  var gridColumns = (_ctx$childComponentPr3 = ctx.childComponentProps) === null || _ctx$childComponentPr3 === void 0 || (_ctx$childComponentPr3 = _ctx$childComponentPr3.grid) === null || _ctx$childComponentPr3 === void 0 ? void 0 : _ctx$childComponentPr3.columns;
  var derivedFilterFromColumns = useMemo(function () {
    return Array.isArray(gridColumns) && gridColumns.length > 0 ? deriveFilterFromColumns(gridColumns) : null;
  }, [gridColumns]);
  var derivedSortFromColumnsList = useMemo(function () {
    return Array.isArray(gridColumns) && gridColumns.length > 0 ? deriveSortFromColumns(gridColumns) : [];
  }, [gridColumns]);
  var searchConfig = slots.search;
  var hideSearch = searchConfig === false;

  /** 默认 inline：triggerType="input" + displayType="inline"，放在 toolbar 左侧。showConfirmButton 优先取 toolBar.search，未配置时默认 true。 */
  var searchNode = hideSearch ? null : /*#__PURE__*/React.createElement(PisellFind, _extends({
    triggerType: "input",
    displayType: "inline",
    showConfirmButton: _typeof(searchConfig) === 'object' && searchConfig !== null && 'showConfirmButton' in searchConfig ? searchConfig.showConfirmButton : true,
    value: keyword,
    onChange: function onChange(v) {
      return handleSearch(v);
    },
    onSearch: handleSearch
  }, _typeof(searchConfig) === 'object' && searchConfig !== null ? searchConfig : {}, {
    size: toolbarDensity === 'compact' ? barSize : _typeof(searchConfig) === 'object' && searchConfig !== null && 'size' in searchConfig && searchConfig.size != null ? searchConfig.size : barSize
  }));

  // 快筛统一放在左侧 QuickFilter；右侧 Filter 弹层只保留高级筛选，不展示快筛
  var quickFilterConfig = slots.quickFilter;
  var quickFilterList = useMemo(function () {
    var _ref;
    if (quickFilterConfig === false) return [];
    var fromConfig = _typeof(quickFilterConfig) === 'object' && quickFilterConfig !== null && Array.isArray(quickFilterConfig.filterList) ? quickFilterConfig.filterList : null;
    var list = (_ref = fromConfig !== null && fromConfig !== void 0 ? fromConfig : derivedFilterFromColumns === null || derivedFilterFromColumns === void 0 ? void 0 : derivedFilterFromColumns.quickFilter) !== null && _ref !== void 0 ? _ref : [];
    var hideNames = _typeof(quickFilterConfig) === 'object' && quickFilterConfig !== null && Array.isArray(quickFilterConfig.hideFilterNamesOnFloorMap) ? quickFilterConfig.hideFilterNamesOnFloorMap : null;
    if ((bodyView === 'floorMap' || bodyView === 'calendar' || bodyView === 'resourceWall') && showTableFloorToggle && hideNames != null && hideNames.length > 0) {
      var hideSet = new Set(hideNames.map(String));
      list = list.filter(function (item) {
        var _item$name;
        var n = (_item$name = item.name) !== null && _item$name !== void 0 ? _item$name : item.key;
        return n == null || !hideSet.has(String(n));
      });
    }
    return list;
  }, [quickFilterConfig, derivedFilterFromColumns === null || derivedFilterFromColumns === void 0 ? void 0 : derivedFilterFromColumns.quickFilter, bodyView, showTableFloorToggle]);
  /**
   * 资源墙专用快筛不占用顶栏；resourceWall 时顶栏快筛整行收起（改走右侧 Filter）。
   * 资源墙顶栏仅保留 Sort + Filter（Find / Reset 隐藏）。
   * 其它视图从顶栏剔除该字段，避免与表格/平面图等共用 toolBar.quickFilter 时误展示。
   */
  var leftBarQuickFilterList = useMemo(function () {
    var withoutWall = quickFilterList.filter(function (item) {
      var _ref2, _item$key;
      return ((_ref2 = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.name) !== null && _ref2 !== void 0 ? _ref2 : '') !== resourceWallFilterFieldKey;
    });
    if (bodyView === 'resourceWall') return [];
    return withoutWall;
  }, [bodyView, quickFilterList, resourceWallFilterFieldKey]);
  var showQuickFilterLeft = leftBarQuickFilterList.length > 0;
  var quickFilterNode = showQuickFilterLeft ? /*#__PURE__*/React.createElement(ToolBarQuickFilter, {
    filterList: leftBarQuickFilterList,
    formFiltersPrefix: _typeof(quickFilterConfig) === 'object' && quickFilterConfig !== null ? (_formFiltersPrefix = quickFilterConfig.formFiltersPrefix) !== null && _formFiltersPrefix !== void 0 ? _formFiltersPrefix : '' : '',
    size: _typeof(quickFilterConfig) === 'object' && quickFilterConfig !== null ? quickFilterConfig.size : undefined
  }) : null;
  var bodyViewSegmentedOptions = useMemo(function () {
    var opts = [];
    if (canFloor) opts.push({
      label: getViewFloorMapLabel(),
      value: 'floorMap'
    });
    if (canCalendar) opts.push({
      label: getViewCalendarLabel(),
      value: 'calendar'
    });
    if (canResourceWall) {
      opts.push({
        label: getViewResourceWallLabel(),
        value: 'resourceWall'
      });
    }
    if (canGrid) opts.push({
      label: getViewGridLabel(),
      value: 'grid'
    });
    return opts;
  }, [canFloor, canCalendar, canResourceWall, canGrid]);
  var bodyViewToggle = allowBodyViewToggle ? /*#__PURE__*/React.createElement(Segmented, {
    className: "record-board-toolbar-body-view-segmented",
    size: barSize,
    value: bodyView,
    onChange: function onChange(v) {
      return setBodyView(v);
    },
    options: bodyViewSegmentedOptions,
    style: {
      marginRight: 8
    }
  }) : null;

  /** 平面图 / 日历模式：第二行工具（搜索/筛选等）收起；切换器在业务方 tabs 内（如预约 ScheduleBand） */
  var compactFloorMapToolbar = (bodyView === 'floorMap' || bodyView === 'calendar') && showTableFloorToggle;

  /**
   * 仅非表格且 tabs 内含 ScheduleBand（平面图 / 日历）时隐藏顶行切换器；表格 / 资源墙 tabs 无 ScheduleBand，
   * 切换器回到 Find 左侧（与 PisellReservation 表格态一致）。
   */
  var hideBodyViewToggleInToolbarRow = allowBodyViewToggle && Boolean(slots.tabs) && (bodyView === 'floorMap' || bodyView === 'calendar');
  var topLeft = compactFloorMapToolbar ? null : /*#__PURE__*/React.createElement("div", {
    className: "record-board-toolbar-top-left"
  }, !hideBodyViewToggleInToolbarRow ? bodyViewToggle : null, quickFilterNode ? /*#__PURE__*/React.createElement("div", {
    className: "record-board-toolbar-quick-filter-slot"
  }, quickFilterNode) : null, searchNode && bodyView !== 'resourceWall' ? /*#__PURE__*/React.createElement("div", {
    className: "record-board-toolbar-find-wrap"
  }, searchNode) : null, slots.topLeft ? /*#__PURE__*/React.createElement("div", {
    className: "record-board-toolbar-extra-top-left"
  }, slots.topLeft) : null);
  var sortConfig = slots.sort;
  var hideSort = sortConfig === false;
  var sortValue = searchParams === null || searchParams === void 0 ? void 0 : searchParams[SORT_PARAMS_FIELD];
  var handleSortChange = useCallback(function (val) {
    onSearch(_objectSpread(_objectSpread({}, searchParams), {}, _defineProperty({}, SORT_PARAMS_FIELD, val || undefined)));
  }, [onSearch, searchParams]);
  var sortList = useMemo(function () {
    /** `list: []` 若为 `??` 左值会得到空数组，无法回落到列派生；此处显式在非空时使用配置项 */
    var configuredList = _typeof(sortConfig) === 'object' && sortConfig !== null && Array.isArray(sortConfig.list) ? sortConfig.list : null;
    var base = configuredList != null && configuredList.length > 0 ? configuredList : derivedSortFromColumnsList;
    if (bodyView !== 'resourceWall') {
      return base;
    }
    var extraWallKeys = _typeof(sortConfig) === 'object' && sortConfig !== null && Array.isArray(sortConfig.resourceWallSortFieldKeys) ? sortConfig.resourceWallSortFieldKeys.map(String) : [];
    var allowedKeys = [].concat(_toConsumableArray(DEFAULT_RESOURCE_WALL_STATUS_SORT_FIELD_KEYS.map(String)), _toConsumableArray(extraWallKeys));
    var filtered = base.filter(function (item) {
      return item.name != null && matchesResourceWallStatusSortField(String(item.name), allowedKeys);
    });
    if (filtered.length > 0) return filtered;
    return [buildResourceWallStatusSortFallbackItem(sortConfig)];
  }, [sortConfig, derivedSortFromColumnsList, bodyView]);
  var sortSpreadRest = _typeof(sortConfig) === 'object' && sortConfig !== null ? function () {
    var _ref3 = sortConfig,
      _w = _ref3.resourceWallSortFieldKeys,
      _omitList = _ref3.list,
      rest = _objectWithoutProperties(_ref3, _excluded);
    return rest;
  }() : {};
  var sortNode = hideSort ? null : /*#__PURE__*/React.createElement(Sort, _extends({}, sortSpreadRest, {
    list: sortList,
    value: sortValue,
    onChange: handleSortChange,
    placement: "bottomLeft",
    button: /*#__PURE__*/React.createElement(Button, {
      className: "record-board-toolbar-filter-btn",
      icon: /*#__PURE__*/React.createElement(SwitchVertical01, null),
      size: barSize
    }, getSortButtonText())
  }));
  var filterConfig = slots.filter;
  var hideFilter = filterConfig === false;
  var filterValue = searchParams === null || searchParams === void 0 ? void 0 : searchParams[FILTER_PARAMS_FIELD];
  var hasFilterList = Array.isArray(filterValue === null || filterValue === void 0 ? void 0 : filterValue.quickFilter) && filterValue.quickFilter.length > 0 || Array.isArray(filterValue === null || filterValue === void 0 ? void 0 : filterValue.otherFilter) && filterValue.otherFilter.length > 0;
  var hasFilterValues = _typeof(filterValue === null || filterValue === void 0 ? void 0 : filterValue.values) === 'object' && filterValue.values !== null && Object.keys(filterValue.values).length > 0;
  var hasFilterItems = hasFilterList || hasFilterValues;
  var defaultFilterFromConfig = _typeof(filterConfig) === 'object' && filterConfig !== null && filterConfig.defaultFilterValue ? filterConfig.defaultFilterValue : null;
  var effectiveFilterValue = useMemo(function () {
    var _defaultFilterFromCon, _defaultFilterFromCon2, _base$values;
    var base = filterValue != null && hasFilterItems ? filterValue : defaultFilterFromConfig ? defaultFilterFromConfig : derivedFilterFromColumns && (derivedFilterFromColumns.quickFilter.length > 0 || derivedFilterFromColumns.otherFilter.length > 0) ? derivedFilterFromColumns : getDefaultFilterValue();
    var quickFilter = Array.isArray(base.quickFilter) && base.quickFilter.length > 0 ? base.quickFilter : (_defaultFilterFromCon = defaultFilterFromConfig === null || defaultFilterFromConfig === void 0 ? void 0 : defaultFilterFromConfig.quickFilter) !== null && _defaultFilterFromCon !== void 0 ? _defaultFilterFromCon : [];
    var otherFilter = Array.isArray(base.otherFilter) && base.otherFilter.length > 0 ? base.otherFilter : (_defaultFilterFromCon2 = defaultFilterFromConfig === null || defaultFilterFromConfig === void 0 ? void 0 : defaultFilterFromConfig.otherFilter) !== null && _defaultFilterFromCon2 !== void 0 ? _defaultFilterFromCon2 : [];
    // 若 otherFilter 来自 base（如 sessionStorage 恢复），JSON 会丢失函数（如 other.component），导致 custom 项空白；用 config 同 key 项补回 component/label 等
    if (otherFilter === base.otherFilter && Array.isArray(defaultFilterFromConfig === null || defaultFilterFromConfig === void 0 ? void 0 : defaultFilterFromConfig.otherFilter) && defaultFilterFromConfig.otherFilter.length > 0) {
      var configMap = new Map(defaultFilterFromConfig.otherFilter.map(function (c) {
        var _ref4, _c$key;
        return [(_ref4 = (_c$key = c.key) !== null && _c$key !== void 0 ? _c$key : c.name) !== null && _ref4 !== void 0 ? _ref4 : '', c];
      }));
      otherFilter = otherFilter.map(function (item) {
        var _ref5, _item$key2, _configItem$label, _configItem$other$pla, _configItem$other, _item$other;
        var key = (_ref5 = (_item$key2 = item.key) !== null && _item$key2 !== void 0 ? _item$key2 : item.name) !== null && _ref5 !== void 0 ? _ref5 : '';
        var configItem = configMap.get(key);
        if (!configItem) return item;
        // 优先用 config 的 label/placeholder（当前语言），避免 session 恢复的旧语言覆盖
        return _objectSpread(_objectSpread(_objectSpread({}, configItem), item), {}, {
          label: (_configItem$label = configItem.label) !== null && _configItem$label !== void 0 ? _configItem$label : item.label,
          other: _objectSpread(_objectSpread(_objectSpread({}, configItem === null || configItem === void 0 ? void 0 : configItem.other), item === null || item === void 0 ? void 0 : item.other), {}, {
            placeholder: (_configItem$other$pla = configItem === null || configItem === void 0 || (_configItem$other = configItem.other) === null || _configItem$other === void 0 ? void 0 : _configItem$other.placeholder) !== null && _configItem$other$pla !== void 0 ? _configItem$other$pla : item === null || item === void 0 || (_item$other = item.other) === null || _item$other === void 0 ? void 0 : _item$other.placeholder
          })
        });
      });
    }
    var outQuick = quickFilter;
    var outOther = otherFilter;
    /**
     * 资源墙：Filter 弹层只保留「大屏资源多选」一项（与顶栏 quickFilter.filterList 中
     * `resource_wall_resource_ids` 对应），不混入日期快筛 / 业务 otherFilter。
     */
    if (bodyView === 'resourceWall') {
      outQuick = [];
      outOther = quickFilterList.filter(function (item) {
        var _ref6, _item$key3;
        return ((_ref6 = (_item$key3 = item.key) !== null && _item$key3 !== void 0 ? _item$key3 : item.name) !== null && _ref6 !== void 0 ? _ref6 : '') === resourceWallFilterFieldKey;
      }).map(function (item) {
        return _objectSpread({}, item);
      });
    }
    return _objectSpread(_objectSpread({}, base), {}, {
      quickFilter: outQuick,
      otherFilter: outOther,
      values: (_base$values = base.values) !== null && _base$values !== void 0 ? _base$values : {}
    });
  }, [filterValue, hasFilterItems, defaultFilterFromConfig, derivedFilterFromColumns, bodyView, quickFilterList]);

  // 右侧 Filter 只展示高级筛选，快筛全部在左侧
  var filterValueForPisellFilter = useMemo(function () {
    return _objectSpread(_objectSpread({}, effectiveFilterValue), {}, {
      quickFilter: []
    });
  }, [effectiveFilterValue]);
  var handleFilterChange = useCallback(function (value) {
    var _currentFilter$values, _value$values;
    var currentFilter = searchParams === null || searchParams === void 0 ? void 0 : searchParams[FILTER_PARAMS_FIELD];
    var currentValues = (_currentFilter$values = currentFilter === null || currentFilter === void 0 ? void 0 : currentFilter.values) !== null && _currentFilter$values !== void 0 ? _currentFilter$values : {};
    var incomingValues = (_value$values = value === null || value === void 0 ? void 0 : value.values) !== null && _value$values !== void 0 ? _value$values : {};
    var nextFilter = _objectSpread(_objectSpread({}, value), {}, {
      values: _objectSpread(_objectSpread({}, currentValues), incomingValues)
    });
    onSearch(_objectSpread(_objectSpread({}, searchParams), {}, _defineProperty({}, FILTER_PARAMS_FIELD, nextFilter)));
  }, [onSearch, searchParams]);
  var filterResetKey = (_filterResetKey = ctx.filterResetKey) !== null && _filterResetKey !== void 0 ? _filterResetKey : 0;
  var filterNode = hideFilter ? null : /*#__PURE__*/React.createElement(PisellFilter, _extends({
    key: "record-board-filter-".concat(filterResetKey),
    value: filterValueForPisellFilter,
    onChange: handleFilterChange,
    hasForm: true,
    quickFilterMaxLength: 100,
    formFiltersPrefix: "",
    hiddenQuickFilter: true,
    placement: "bottomLeft"
  }, _typeof(filterConfig) === 'object' && filterConfig !== null ? filterConfig : {}, {
    size: barSize,
    buttonClassName: "record-board-toolbar-filter-btn"
  }));
  var showColumnSetting = slots.columnSetting !== false && bodyView !== 'resourceWall' && Array.isArray(gridColumns) && gridColumns.length > 0;
  var topRight = compactFloorMapToolbar ? null : /*#__PURE__*/React.createElement(Space, {
    className: "record-board-toolbar-right-actions"
  }, showColumnSetting ? /*#__PURE__*/React.createElement(RecordBoardColumnSetting, null) : null, sortNode, filterNode, bodyView !== 'resourceWall' ? /*#__PURE__*/React.createElement(ToolBarReset, {
    size: barSize
  }) : null, slots.topRight);
  return /*#__PURE__*/React.createElement(PisellToolBar, {
    className: classNames(bodyView === 'floorMap' && 'pisell-record-board-toolbar--floor-map', bodyView === 'calendar' && 'pisell-record-board-toolbar--calendar', bodyView === 'resourceWall' && 'pisell-record-board-toolbar--resource-wall', bodyView === 'grid' && 'pisell-record-board-toolbar--grid', toolbarDensity === 'compact' && 'pisell-record-board-toolbar--compact', slots.className),
    style: slots.style,
    tabs: slots.tabs,
    topLeft: topLeft,
    topRight: topRight,
    bottomLeft: compactFloorMapToolbar ? null : slots.bottomLeft,
    bottomRight: compactFloorMapToolbar ? null : slots.bottomRight
  });
};
RecordBoardToolBar.displayName = 'RecordBoard.ToolBar';
export default RecordBoardToolBar;