var _excluded = ["fixed"];
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 _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 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 { getRecordBoardColumnKey } from "./recordBoardColumns";

/** Grid 根节点在 `layoutVariant="phone"` 时追加的 class，用于收紧单元格 padding 等 */
export var RECORD_BOARD_PHONE_GRID_CLASS = 'pisell-record-board-grid--phone';
/**
 * 手机 Table：收窄列宽并去掉 fixed，供 RecordBoard Grid 在 layoutVariant=phone 时统一调用。
 * 业务可通过 grid.phoneColumnWidthCaps / phoneColumnWidthRatioByKey 覆盖特定列。
 */
export function adaptColumnsForPhoneLayout(columns, options) {
  var _options$defaultWidth;
  var defaultWidthRatio = (_options$defaultWidth = options === null || options === void 0 ? void 0 : options.defaultWidthRatio) !== null && _options$defaultWidth !== void 0 ? _options$defaultWidth : 5 / 6;
  var unsetFixed = (options === null || options === void 0 ? void 0 : options.unsetFixed) !== false;
  return columns.map(function (column) {
    var key = getRecordBoardColumnKey(column);
    var next = _objectSpread({}, column);
    if (unsetFixed && next.fixed != null && next.fixed !== false) {
      var _next = next,
        _fixed = _next.fixed,
        rest = _objectWithoutProperties(_next, _excluded);
      next = rest;
    }
    if (typeof next.width === 'number' && Number.isFinite(next.width)) {
      var _options$widthRatioBy, _options$widthRatioBy2, _options$widthCapsByK;
      var ratio = (_options$widthRatioBy = options === null || options === void 0 || (_options$widthRatioBy2 = options.widthRatioByKey) === null || _options$widthRatioBy2 === void 0 ? void 0 : _options$widthRatioBy2[key]) !== null && _options$widthRatioBy !== void 0 ? _options$widthRatioBy : defaultWidthRatio;
      var width = Math.round(next.width * ratio);
      var cap = options === null || options === void 0 || (_options$widthCapsByK = options.widthCapsByKey) === null || _options$widthCapsByK === void 0 ? void 0 : _options$widthCapsByK[key];
      if (cap != null && Number.isFinite(cap)) {
        width = Math.min(cap, width);
      }
      next = _objectSpread(_objectSpread({}, next), {}, {
        width: width
      });
    }
    return next;
  });
}
export function mergeRecordBoardPhoneGridClassName(className) {
  return classNames(className, RECORD_BOARD_PHONE_GRID_CLASS);
}

/**
 * 手机 Table：`scroll.x: 'max-content'` 会按内容撑出比「列宽之和」更宽的滚动区域，
 * 列宽已被 adaptColumnsForPhoneLayout 收窄后仍保留 max-content 时，右侧会出现可滚动的空白。
 * 与预约 buildReservationMobileTableGridConfig 去掉横向 scroll 的策略一致，改为数值宽度。
 */
export function resolveRecordBoardPhoneScrollX(scrollX, sumColumnWidths, options) {
  var _options$selectionCol;
  if (scrollX !== 'max-content' && scrollX !== 'maxContent') {
    return scrollX;
  }
  var selection = (_options$selectionCol = options === null || options === void 0 ? void 0 : options.selectionColumnWidth) !== null && _options$selectionCol !== void 0 ? _options$selectionCol : 0;
  return sumColumnWidths + selection;
}