var _excluded = ["x"];
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 _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); }
import classNames from 'classnames';
import { PisellMobileDateRangePicker, adaptColumnsForPhoneLayout } from '@pisell/materials';
var MOBILE_BOOKING_BRIEF_CELL_CLASS = 'pisell-reservation-mobile-table-col--booking-brief';
var MOBILE_ORDER_INFO_CELL_CLASS = 'pisell-reservation-mobile-table-col--order-info';
var MOBILE_CUSTOMER_CELL_CLASS = 'pisell-reservation-mobile-table-col--customer';
var MOBILE_CONTACT_CELL_CLASS = 'pisell-reservation-mobile-table-col--contact';
var MOBILE_HOLDER_DATA_CELL_CLASS = 'pisell-reservation-mobile-table-col--holder-data';

/** Customer / Contact / Holder：手机端允许邮箱、电话在列宽内折行 */
var MOBILE_PERSON_COLUMN_CLASS_BY_KEY = {
  customer: MOBILE_CUSTOMER_CELL_CLASS,
  contact: MOBILE_CONTACT_CELL_CLASS,
  holder_data: MOBILE_HOLDER_DATA_CELL_CLASS
};

/**
 * 预约手机 Table 列宽上限（px）。与 `adaptColumnsForPhoneLayout` 联用：
 * 先按 `MOBILE_RESERVATION_WIDTH_RATIO` 缩放桌面 width，再取 min(cap)。
 * booking_brief 勿低于 ~120，避免堆叠行整格变省略号。
 */
var MOBILE_RESERVATION_COLUMN_WIDTH_CAPS = {
  booking_brief: 124,
  relation_form_name: 88,
  service_time: 128,
  order_info: 100,
  customer: 96,
  contact: 100,
  holder_data: 88,
  services: 88,
  number: 72,
  appointment_form: 92,
  booking_id: 72,
  order_origin: 96,
  updated: 88,
  actions: 72
};
var MOBILE_RESERVATION_WIDTH_RATIO = 0.78;

/** 预约手机列：附加 className / ellipsis，列宽在 buildReservationMobileTableGridConfig 内统一收窄 */
function narrowBookingBriefColumn(column) {
  var _ref, _column$key;
  var key = String((_ref = (_column$key = column.key) !== null && _column$key !== void 0 ? _column$key : column.dataIndex) !== null && _ref !== void 0 ? _ref : '');
  if (key !== 'booking_brief') return column;
  return _objectSpread(_objectSpread({}, column), {}, {
    /** 自定义 render 含多行内容，关闭 antd 单元格单行省略 */
    ellipsis: false,
    className: classNames(typeof column.className === 'string' ? column.className : undefined, MOBILE_BOOKING_BRIEF_CELL_CLASS),
    onCell: function onCell() {
      return {
        className: MOBILE_BOOKING_BRIEF_CELL_CLASS
      };
    }
  });
}
function narrowOrderInfoColumn(column) {
  var _ref2, _column$key2;
  var key = String((_ref2 = (_column$key2 = column.key) !== null && _column$key2 !== void 0 ? _column$key2 : column.dataIndex) !== null && _ref2 !== void 0 ? _ref2 : '');
  if (key !== 'order_info') return column;
  return _objectSpread(_objectSpread({}, column), {}, {
    /** 纵向多行 render；关闭 antd 整格单行省略，由列 class CSS 对每行子元素单独省略 */
    ellipsis: false,
    className: classNames(typeof column.className === 'string' ? column.className : undefined, MOBILE_ORDER_INFO_CELL_CLASS),
    onCell: function onCell() {
      return {
        className: MOBILE_ORDER_INFO_CELL_CLASS
      };
    }
  });
}
function narrowServiceTimeColumn(column) {
  var _ref3, _column$key3;
  var key = String((_ref3 = (_column$key3 = column.key) !== null && _column$key3 !== void 0 ? _column$key3 : column.dataIndex) !== null && _ref3 !== void 0 ? _ref3 : '');
  if (key !== 'service_time') return column;
  return _objectSpread(_objectSpread({}, column), {}, {
    className: classNames(typeof column.className === 'string' ? column.className : undefined, 'pisell-reservation-mobile-table-col--service-time')
  });
}
function narrowPersonInfoColumn(column) {
  var _ref4, _column$key4;
  var key = String((_ref4 = (_column$key4 = column.key) !== null && _column$key4 !== void 0 ? _column$key4 : column.dataIndex) !== null && _ref4 !== void 0 ? _ref4 : '');
  var cellClass = MOBILE_PERSON_COLUMN_CLASS_BY_KEY[key];
  if (!cellClass) return column;
  return _objectSpread(_objectSpread({}, column), {}, {
    ellipsis: false,
    className: classNames(typeof column.className === 'string' ? column.className : undefined, cellClass),
    onCell: function onCell() {
      return {
        className: cellClass
      };
    }
  });
}
/** 手机 Table 顶栏快筛：改用 antd-mobile CalendarPicker 区间选择，与右侧 32px 控件对齐 */
export var MOBILE_TOOLBAR_RANGE_FILTER_ITEM_CLASS = 'pisell-reservation-mobile-toolbar-range-filter-item';
/**
 * 手机端将 `rangePicker` 筛项统一为 `PisellMobileDateRangePicker`（custom）。
 * 兼容顶栏快筛（placeholder/showTime 在 props）与 Filter 弹层 otherFilter（在 other）。
 */
export function adaptFilterListForMobile(filterList, options) {
  return filterList.map(function (item) {
    if (String(item.type) !== 'rangePicker') return item;
    var props = _typeof(item.props) === 'object' && item.props !== null ? _objectSpread({}, item.props) : {};
    var other = _typeof(item.other) === 'object' && item.other !== null ? _objectSpread({}, item.other) : {};
    var priorFormItemProps = _typeof(other.formItemProps) === 'object' && other.formItemProps !== null ? other.formItemProps : {};
    var placeholder = typeof props.placeholder === 'string' ? props.placeholder : typeof other.placeholder === 'string' ? other.placeholder : undefined;
    delete props.placeholder;
    delete other.placeholder;
    /** 手机端仅展示日期（DD/MM/YYYY）；值仍输出 dayjs[] 与 rangePicker 一致 */
    delete props.showTime;
    delete other.showTime;
    var priorStyle = _typeof(priorFormItemProps.style) === 'object' && priorFormItemProps.style !== null ? priorFormItemProps.style : {};
    return _objectSpread(_objectSpread({}, item), {}, {
      type: 'custom',
      other: _objectSpread(_objectSpread({}, other), {}, {
        component: PisellMobileDateRangePicker,
        formItemProps: _objectSpread(_objectSpread(_objectSpread({}, priorFormItemProps), options !== null && options !== void 0 && options.rangeFormItemClassName ? {
          className: classNames(options.rangeFormItemClassName, typeof priorFormItemProps.className === 'string' ? priorFormItemProps.className : undefined)
        } : {}), options !== null && options !== void 0 && options.compactFormItem ? {
          style: _objectSpread({
            marginBottom: 0
          }, priorStyle)
        } : {})
      }),
      props: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props), {}, {
        format: 'DD/MM/YYYY'
      }, placeholder ? {
        placeholder: placeholder
      } : {}), options !== null && options !== void 0 && options.rangePickerVariant ? {
        variant: options.rangePickerVariant
      } : {}), {}, {
        style: _objectSpread({
          width: '100%',
          minWidth: 0,
          maxWidth: '100%'
        }, _typeof(props.style) === 'object' && props.style !== null ? props.style : {})
      })
    });
  });
}
export function adaptQuickFiltersForMobileToolbar(filterList) {
  return adaptFilterListForMobile(filterList, {
    rangeFormItemClassName: MOBILE_TOOLBAR_RANGE_FILTER_ITEM_CLASS,
    compactFormItem: true
  });
}

/** 手机 Filter 弹层：`toolBar.filter.defaultFilterValue.otherFilter` 中的 rangePicker 适配 */
export function adaptFilterConfigForMobile(filterConfig) {
  var defaultFilterValue = filterConfig.defaultFilterValue;
  if (_typeof(defaultFilterValue) !== 'object' || defaultFilterValue === null) {
    return filterConfig;
  }
  var rawOther = defaultFilterValue.otherFilter;
  if (!Array.isArray(rawOther)) return filterConfig;
  return _objectSpread(_objectSpread({}, filterConfig), {}, {
    defaultFilterValue: _objectSpread(_objectSpread({}, defaultFilterValue), {}, {
      otherFilter: adaptFilterListForMobile(rawOther, {
        rangePickerVariant: 'filter'
      })
    })
  });
}
/**
 * 手机日程类视图（日历 / 平面图）：仅补 narrow-stack，不套用 Table 顶栏密度与 padding 类。
 */
export function buildReservationPhoneNarrowStackToolbarConfig(baseToolBar) {
  var base = baseToolBar !== null && baseToolBar !== void 0 ? baseToolBar : {};
  var baseClassName = typeof base.className === 'string' ? base.className : undefined;
  return _objectSpread(_objectSpread({}, base), {}, {
    className: classNames(baseClassName, 'pisell-record-board-toolbar--narrow-stack')
  });
}
export function buildReservationMobileTableToolbarConfig(params) {
  var _params$baseToolBar;
  var base = (_params$baseToolBar = params.baseToolBar) !== null && _params$baseToolBar !== void 0 ? _params$baseToolBar : {};
  var baseClassName = typeof base.className === 'string' ? base.className : undefined;
  var baseSearch = _typeof(base.search) === 'object' && base.search !== null ? base.search : {};
  return _objectSpread(_objectSpread({}, base), {}, {
    toolbarDensity: 'compact-narrow',
    filter: _typeof(base.filter) === 'object' && base.filter !== null ? _objectSpread(_objectSpread({}, base.filter), {}, {
      phoneLayout: true
    }) : {
      phoneLayout: true
    },
    quickFilter: params.quickFilterFilterList && params.quickFilterFilterList.length > 0 ? {
      filterList: params.quickFilterFilterList
    } : false,
    search: params.searchGetContainer ? _objectSpread(_objectSpread({}, baseSearch), {}, {
      getContainer: params.searchGetContainer,
      /** 相对全宽略收窄并设上限，避免 Find Modal 在手机预约里占满一整屏显得过大 */
      modalWidth: 'min(calc(100% - 24px), 360px)',
      modalStyle: _objectSpread(_objectSpread({}, _typeof(baseSearch.modalStyle) === 'object' && baseSearch.modalStyle !== null && !Array.isArray(baseSearch.modalStyle) ? baseSearch.modalStyle : {}), {}, {
        marginLeft: 'auto',
        marginRight: 'auto'
      })
    }) : baseSearch,
    className: classNames(baseClassName, 'pisell-record-board-toolbar--narrow-stack', 'pisell-reservation-mobile-table-toolbar')
  });
}
export function buildReservationMobileTableGridConfig(grid) {
  var base = grid !== null && grid !== void 0 ? grid : {};
  var rawColumns = Array.isArray(base.columns) ? base.columns : [];
  var columns = adaptColumnsForPhoneLayout(rawColumns.map(function (column) {
    return narrowOrderInfoColumn(narrowServiceTimeColumn(narrowPersonInfoColumn(narrowBookingBriefColumn(column))));
  }), {
    widthCapsByKey: MOBILE_RESERVATION_COLUMN_WIDTH_CAPS,
    defaultWidthRatio: MOBILE_RESERVATION_WIDTH_RATIO
  });
  var scrollBase = _typeof(base.scroll) === 'object' && base.scroll !== null ? base.scroll : {};
  var _dropHorizontalScroll = scrollBase.x,
    scrollWithoutX = _objectWithoutProperties(scrollBase, _excluded);
  return _objectSpread(_objectSpread({}, base), {}, {
    columns: columns,
    infiniteScroll: true,
    size: 'small',
    className: classNames(typeof base.className === 'string' ? base.className : undefined, 'pisell-reservation-mobile-table-grid'),
    scroll: _objectSpread(_objectSpread({}, scrollWithoutX), {}, {
      autoCalc: true
    })
  });
}
export function buildReservationHudDrawerToolbarConfig(params) {
  var built = buildReservationMobileTableToolbarConfig({
    baseToolBar: params.baseToolBar,
    searchGetContainer: params.searchGetContainer,
    quickFilterFilterList: [{
      type: 'custom',
      key: 'hudQuickFiltersRow',
      other: {
        component: params.quickFilterComponent,
        compositeFilterFieldNames: ['appointment_status', 'order_payment_status'],
        formItemProps: {
          style: {
            marginBottom: 0
          }
        }
      }
    }]
  });
  var builtClass = typeof built.className === 'string' ? built.className : undefined;
  var builtSearch = _typeof(built.search) === 'object' && built.search !== null ? built.search : undefined;
  var priorModalStyle = builtSearch && _typeof(builtSearch.modalStyle) === 'object' && builtSearch.modalStyle !== null && !Array.isArray(builtSearch.modalStyle) ? builtSearch.modalStyle : {};
  return _objectSpread(_objectSpread({}, built), {}, {
    mergeCompactNarrowTrailingWithQuickFilterRow: true,
    /** HUD 内嵌表：Find Modal 铺满抽屉内容区；手机 Table 仍保留 360px 上限 */
    search: params.searchGetContainer && builtSearch ? _objectSpread(_objectSpread({}, builtSearch), {}, {
      modalWidth: '100%',
      modalStyle: _objectSpread(_objectSpread({}, priorModalStyle), {}, {
        marginLeft: 0,
        marginRight: 0,
        width: '100%',
        maxWidth: '100%'
      })
    }) : built.search,
    className: classNames(builtClass, 'pisell-reservation-hud-table-toolbar')
  });
}