import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import { getRecordBoardColumnKey } from "./recordBoardColumns.js";
import "classnames";
//#region src/components/pisellRecordBoard/utils/recordBoardPhoneGrid.ts
const _excluded = ["fixed"];
/** Grid 根节点在 `layoutVariant="phone"` 时追加的 class，用于收紧单元格 padding 等 */
const RECORD_BOARD_PHONE_GRID_CLASS = "pisell-record-board-grid--phone";
/**
* 手机 Table：收窄列宽并去掉 fixed，供 RecordBoard Grid 在 layoutVariant=phone 时统一调用。
* 业务可通过 grid.phoneColumnWidthCaps / phoneColumnWidthRatioByKey 覆盖特定列。
*/
function adaptColumnsForPhoneLayout(columns, options) {
	var _options$defaultWidth;
	const defaultWidthRatio = (_options$defaultWidth = options === null || options === void 0 ? void 0 : options.defaultWidthRatio) !== null && _options$defaultWidth !== void 0 ? _options$defaultWidth : 5 / 6;
	const unsetFixed = (options === null || options === void 0 ? void 0 : options.unsetFixed) !== false;
	return columns.map((column) => {
		const key = getRecordBoardColumnKey(column);
		let next = _objectSpread2({}, column);
		if (unsetFixed && next.fixed != null && next.fixed !== false) {
			const { fixed: _fixed } = next;
			next = _objectWithoutProperties(next, _excluded);
		}
		if (typeof next.width === "number" && Number.isFinite(next.width)) {
			var _options$widthRatioBy, _options$widthRatioBy2, _options$widthCapsByK;
			const 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;
			let width = Math.round(next.width * ratio);
			const 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 = _objectSpread2(_objectSpread2({}, next), {}, { width });
		}
		return next;
	});
}
/**
* 手机 Table：`scroll.x: 'max-content'` 会按内容撑出比「列宽之和」更宽的滚动区域，
* 列宽已被 adaptColumnsForPhoneLayout 收窄后仍保留 max-content 时，右侧会出现可滚动的空白。
* 与预约 buildReservationMobileTableGridConfig 去掉横向 scroll 的策略一致，改为数值宽度。
*/
function resolveRecordBoardPhoneScrollX(scrollX, sumColumnWidths, options) {
	var _options$selectionCol;
	if (scrollX !== "max-content" && scrollX !== "maxContent") return scrollX;
	return sumColumnWidths + ((_options$selectionCol = options === null || options === void 0 ? void 0 : options.selectionColumnWidth) !== null && _options$selectionCol !== void 0 ? _options$selectionCol : 0);
}
//#endregion
export { RECORD_BOARD_PHONE_GRID_CLASS, adaptColumnsForPhoneLayout, resolveRecordBoardPhoneScrollX };
