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); }
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; }
import classNames from 'classnames';
/** 手机 Table 根 class，限定列内容样式作用域 */
export var MOBILE_SALES_TABLE_GRID_CLASS = 'pisell-sales-grid-mobile-table-grid';
export var MOBILE_SALE_BRIEF_CELL_CLASS = 'pisell-sales-grid-mobile-table-col--sale-brief';

/** 纵向多行 render：由列 CSS 对子行单独省略 */
export var MOBILE_STACK_CELL_CLASS = 'pisell-sales-grid-mobile-table-col--stack';

/** 居中 Tag / PisellTags 列 */
export var MOBILE_TAG_CELL_CLASS = 'pisell-sales-grid-mobile-table-col--tag';

/** 手机端 Sale Brief 列宽（桌面 225） */
export var MOBILE_SALE_BRIEF_COLUMN_WIDTH = 156;

/** 订单 Table（handle perspective）手机列宽 */
var MOBILE_ORDER_COLUMN_WIDTHS = {
  sale_brief: MOBILE_SALE_BRIEF_COLUMN_WIDTH,
  customer: 108,
  contacts_info: 108,
  payment_info: 108,
  product_quantity: 80,
  order_origin: 132,
  payment_status: 108,
  delivery_type: 108,
  status: 104,
  shipping_status: 108,
  last_edit_account: 128,
  order_id: 72
};

/** 预约 Monitor Table 手机列宽（未列出的列按桌面 width × 比例回退） */
var MOBILE_BOOKING_COLUMN_WIDTHS = {
  booking_brief: 136,
  relation_form_name: 72,
  service_time: 120,
  customer: 88,
  contact: 108,
  holder_data: 88,
  services: 88,
  number: 80,
  appointment_form: 96,
  order_info: 92,
  booking_id: 72,
  order_origin: 100,
  updated: 96
};

/** 含自定义多行内容的列 key */
var MOBILE_STACK_COLUMN_KEYS = new Set(['sale_brief', 'booking_brief', 'customer', 'contacts_info', 'contact', 'holder_data', 'services', 'payment_info', 'order_info', 'order_origin', 'last_edit_account', 'updated']);
var MOBILE_TAG_COLUMN_KEYS = new Set(['payment_status', 'delivery_type', 'status', 'shipping_status']);
var MOBILE_WIDTH_SCALE_FALLBACK = 0.72;
var MOBILE_MIN_COLUMN_WIDTH = 64;
function getColumnKey(column) {
  var _ref, _column$key;
  return String((_ref = (_column$key = column.key) !== null && _column$key !== void 0 ? _column$key : column.dataIndex) !== null && _ref !== void 0 ? _ref : '');
}
function toCellClassName(key) {
  return "pisell-sales-grid-mobile-table-col--".concat(key.replace(/_/g, '-'));
}
function resolvePhoneWidth(key, desktopWidth) {
  if (MOBILE_ORDER_COLUMN_WIDTHS[key] != null) {
    return MOBILE_ORDER_COLUMN_WIDTHS[key];
  }
  if (MOBILE_BOOKING_COLUMN_WIDTHS[key] != null) {
    return MOBILE_BOOKING_COLUMN_WIDTHS[key];
  }
  if (typeof desktopWidth === 'number' && desktopWidth > 0) {
    return Math.max(MOBILE_MIN_COLUMN_WIDTH, Math.round(desktopWidth * MOBILE_WIDTH_SCALE_FALLBACK));
  }
  return undefined;
}
function withCellClass(column, cellClassNames) {
  var merged = classNames.apply(void 0, [typeof column.className === 'string' ? column.className : undefined].concat(_toConsumableArray(cellClassNames)));
  return _objectSpread(_objectSpread({}, column), {}, {
    className: merged,
    onCell: function onCell() {
      return {
        className: merged
      };
    }
  });
}
function adaptPhoneColumn(column) {
  var key = getColumnKey(column);
  if (!key) {
    return column;
  }
  var phoneWidth = resolvePhoneWidth(key, column.width);
  if (phoneWidth == null) {
    return column;
  }
  var cellClass = toCellClassName(key);
  var cellClassNames = [cellClass];
  if (MOBILE_STACK_COLUMN_KEYS.has(key)) {
    cellClassNames.push(MOBILE_STACK_CELL_CLASS);
  }
  if (MOBILE_TAG_COLUMN_KEYS.has(key)) {
    cellClassNames.push(MOBILE_TAG_CELL_CLASS);
  }
  var useAntdEllipsis = !MOBILE_STACK_COLUMN_KEYS.has(key) && !MOBILE_TAG_COLUMN_KEYS.has(key);
  return withCellClass(_objectSpread(_objectSpread({}, column), {}, {
    width: phoneWidth,
    ellipsis: useAntdEllipsis
  }), cellClassNames);
}

/**
 * 将 grid.columns 适配为手机 Table：按列收窄宽度，多行/标签列附加 class。
 */
export function applySalesPhoneGridColumns(columns) {
  if (!Array.isArray(columns)) {
    return columns;
  }
  return columns.map(function (column) {
    return adaptPhoneColumn(column);
  });
}

/**
 * 合并手机 Table 的 grid className。
 */
export function mergeSalesPhoneGridClassName(className) {
  return classNames(className, MOBILE_SALES_TABLE_GRID_CLASS);
}

/**
 * 手机 Table：去掉横向 scroll.x（尤其 max-content），避免列宽收窄后仍可滚出右侧空白。
 * 与预约 buildReservationMobileTableGridConfig 一致，仅保留 autoCalc 等纵向滚动配置。
 */
export function buildSalesPhoneGridScroll(scroll) {
  var _autoCalc;
  var base = scroll && _typeof(scroll) === 'object' ? _objectSpread({}, scroll) : {};
  var _dropHorizontalScroll = base.x,
    scrollWithoutX = _objectWithoutProperties(base, _excluded);
  return _objectSpread(_objectSpread({}, scrollWithoutX), {}, {
    autoCalc: (_autoCalc = base.autoCalc) !== null && _autoCalc !== void 0 ? _autoCalc : true
  });
}

/**
 * 手机 Table：取消多选列 fixed，避免横向滚动时固定列与表体错位。
 */
export function buildSalesPhoneRowSelection(rowSelection) {
  if (!rowSelection || _typeof(rowSelection) !== 'object') {
    return rowSelection;
  }
  return _objectSpread(_objectSpread({}, rowSelection), {}, {
    fixed: false
  });
}