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 { PisellMobileDateRangePicker, adaptColumnsForPhoneLayout } from "@pisell/materials";
import classNames from "classnames";
//#region src/plus/pisellReservation/mobileTable/buildReservationMobileTableConfig.ts
const _excluded = ["x"];
const MOBILE_BOOKING_BRIEF_CELL_CLASS = "pisell-reservation-mobile-table-col--booking-brief";
const MOBILE_ORDER_INFO_CELL_CLASS = "pisell-reservation-mobile-table-col--order-info";
/** Customer / Contact / Holder：手机端允许邮箱、电话在列宽内折行 */
const MOBILE_PERSON_COLUMN_CLASS_BY_KEY = {
	customer: "pisell-reservation-mobile-table-col--customer",
	contact: "pisell-reservation-mobile-table-col--contact",
	holder_data: "pisell-reservation-mobile-table-col--holder-data"
};
/**
* 预约手机 Table 列宽上限（px）。与 `adaptColumnsForPhoneLayout` 联用：
* 先按 `MOBILE_RESERVATION_WIDTH_RATIO` 缩放桌面 width，再取 min(cap)。
* booking_brief 勿低于 ~120，避免堆叠行整格变省略号。
*/
const 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
};
const MOBILE_RESERVATION_WIDTH_RATIO = .78;
/** 预约手机列：附加 className / ellipsis，列宽在 buildReservationMobileTableGridConfig 内统一收窄 */
function narrowBookingBriefColumn(column) {
	var _ref, _column$key;
	if (String((_ref = (_column$key = column.key) !== null && _column$key !== void 0 ? _column$key : column.dataIndex) !== null && _ref !== void 0 ? _ref : "") !== "booking_brief") return column;
	return _objectSpread2(_objectSpread2({}, column), {}, {
		ellipsis: false,
		className: classNames(typeof column.className === "string" ? column.className : void 0, MOBILE_BOOKING_BRIEF_CELL_CLASS),
		onCell: () => ({ className: MOBILE_BOOKING_BRIEF_CELL_CLASS })
	});
}
function narrowOrderInfoColumn(column) {
	var _ref2, _column$key2;
	if (String((_ref2 = (_column$key2 = column.key) !== null && _column$key2 !== void 0 ? _column$key2 : column.dataIndex) !== null && _ref2 !== void 0 ? _ref2 : "") !== "order_info") return column;
	return _objectSpread2(_objectSpread2({}, column), {}, {
		ellipsis: false,
		className: classNames(typeof column.className === "string" ? column.className : void 0, MOBILE_ORDER_INFO_CELL_CLASS),
		onCell: () => ({ className: MOBILE_ORDER_INFO_CELL_CLASS })
	});
}
function narrowServiceTimeColumn(column) {
	var _ref3, _column$key3;
	if (String((_ref3 = (_column$key3 = column.key) !== null && _column$key3 !== void 0 ? _column$key3 : column.dataIndex) !== null && _ref3 !== void 0 ? _ref3 : "") !== "service_time") return column;
	return _objectSpread2(_objectSpread2({}, column), {}, { className: classNames(typeof column.className === "string" ? column.className : void 0, "pisell-reservation-mobile-table-col--service-time") });
}
function narrowPersonInfoColumn(column) {
	var _ref4, _column$key4;
	const cellClass = MOBILE_PERSON_COLUMN_CLASS_BY_KEY[String((_ref4 = (_column$key4 = column.key) !== null && _column$key4 !== void 0 ? _column$key4 : column.dataIndex) !== null && _ref4 !== void 0 ? _ref4 : "")];
	if (!cellClass) return column;
	return _objectSpread2(_objectSpread2({}, column), {}, {
		ellipsis: false,
		className: classNames(typeof column.className === "string" ? column.className : void 0, cellClass),
		onCell: () => ({ className: cellClass })
	});
}
/** 手机 Table 顶栏快筛：改用 antd-mobile CalendarPicker 区间选择，与右侧 32px 控件对齐 */
const MOBILE_TOOLBAR_RANGE_FILTER_ITEM_CLASS = "pisell-reservation-mobile-toolbar-range-filter-item";
/**
* 手机端将 `rangePicker` 筛项统一为 `PisellMobileDateRangePicker`（custom）。
* 兼容顶栏快筛（placeholder/showTime 在 props）与 Filter 弹层 otherFilter（在 other）。
*/
function adaptFilterListForMobile(filterList, options) {
	return filterList.map((item) => {
		if (String(item.type) !== "rangePicker") return item;
		const props = typeof item.props === "object" && item.props !== null ? _objectSpread2({}, item.props) : {};
		const other = typeof item.other === "object" && item.other !== null ? _objectSpread2({}, item.other) : {};
		const priorFormItemProps = typeof other.formItemProps === "object" && other.formItemProps !== null ? other.formItemProps : {};
		const placeholder = typeof props.placeholder === "string" ? props.placeholder : typeof other.placeholder === "string" ? other.placeholder : void 0;
		delete props.placeholder;
		delete other.placeholder;
		/** 手机端仅展示日期（DD/MM/YYYY）；值仍输出 dayjs[] 与 rangePicker 一致 */
		delete props.showTime;
		delete other.showTime;
		const priorStyle = typeof priorFormItemProps.style === "object" && priorFormItemProps.style !== null ? priorFormItemProps.style : {};
		return _objectSpread2(_objectSpread2({}, item), {}, {
			type: "custom",
			other: _objectSpread2(_objectSpread2({}, other), {}, {
				component: PisellMobileDateRangePicker,
				formItemProps: _objectSpread2(_objectSpread2(_objectSpread2({}, priorFormItemProps), (options === null || options === void 0 ? void 0 : options.rangeFormItemClassName) ? { className: classNames(options.rangeFormItemClassName, typeof priorFormItemProps.className === "string" ? priorFormItemProps.className : void 0) } : {}), (options === null || options === void 0 ? void 0 : options.compactFormItem) ? { style: _objectSpread2({ marginBottom: 0 }, priorStyle) } : {})
			}),
			props: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, props), {}, { format: "DD/MM/YYYY" }, placeholder ? { placeholder } : {}), (options === null || options === void 0 ? void 0 : options.rangePickerVariant) ? { variant: options.rangePickerVariant } : {}), {}, { style: _objectSpread2({
				width: "100%",
				minWidth: 0,
				maxWidth: "100%"
			}, typeof props.style === "object" && props.style !== null ? props.style : {}) })
		});
	});
}
function adaptQuickFiltersForMobileToolbar(filterList) {
	return adaptFilterListForMobile(filterList, {
		rangeFormItemClassName: MOBILE_TOOLBAR_RANGE_FILTER_ITEM_CLASS,
		compactFormItem: true
	});
}
/** 手机 Filter 弹层：`toolBar.filter.defaultFilterValue.otherFilter` 中的 rangePicker 适配 */
function adaptFilterConfigForMobile(filterConfig) {
	const defaultFilterValue = filterConfig.defaultFilterValue;
	if (typeof defaultFilterValue !== "object" || defaultFilterValue === null) return filterConfig;
	const rawOther = defaultFilterValue.otherFilter;
	if (!Array.isArray(rawOther)) return filterConfig;
	return _objectSpread2(_objectSpread2({}, filterConfig), {}, { defaultFilterValue: _objectSpread2(_objectSpread2({}, defaultFilterValue), {}, { otherFilter: adaptFilterListForMobile(rawOther, { rangePickerVariant: "filter" }) }) });
}
/**
* 手机日程类视图（日历 / 平面图）：仅补 narrow-stack，不套用 Table 顶栏密度与 padding 类。
*/
function buildReservationPhoneNarrowStackToolbarConfig(baseToolBar) {
	const base = baseToolBar !== null && baseToolBar !== void 0 ? baseToolBar : {};
	const baseClassName = typeof base.className === "string" ? base.className : void 0;
	return _objectSpread2(_objectSpread2({}, base), {}, { className: classNames(baseClassName, "pisell-record-board-toolbar--narrow-stack") });
}
function buildReservationMobileTableToolbarConfig(params) {
	var _params$baseToolBar;
	const base = (_params$baseToolBar = params.baseToolBar) !== null && _params$baseToolBar !== void 0 ? _params$baseToolBar : {};
	const baseClassName = typeof base.className === "string" ? base.className : void 0;
	const baseSearch = typeof base.search === "object" && base.search !== null ? base.search : {};
	return _objectSpread2(_objectSpread2({}, base), {}, {
		toolbarDensity: "compact-narrow",
		filter: typeof base.filter === "object" && base.filter !== null ? _objectSpread2(_objectSpread2({}, base.filter), {}, { phoneLayout: true }) : { phoneLayout: true },
		quickFilter: params.quickFilterFilterList && params.quickFilterFilterList.length > 0 ? { filterList: params.quickFilterFilterList } : false,
		search: params.searchGetContainer ? _objectSpread2(_objectSpread2({}, baseSearch), {}, {
			getContainer: params.searchGetContainer,
			modalWidth: "min(calc(100% - 24px), 360px)",
			modalStyle: _objectSpread2(_objectSpread2({}, 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")
	});
}
function buildReservationMobileTableGridConfig(grid) {
	const base = grid !== null && grid !== void 0 ? grid : {};
	const columns = adaptColumnsForPhoneLayout((Array.isArray(base.columns) ? base.columns : []).map((column) => narrowOrderInfoColumn(narrowServiceTimeColumn(narrowPersonInfoColumn(narrowBookingBriefColumn(column))))), {
		widthCapsByKey: MOBILE_RESERVATION_COLUMN_WIDTH_CAPS,
		defaultWidthRatio: MOBILE_RESERVATION_WIDTH_RATIO
	});
	const scrollBase = typeof base.scroll === "object" && base.scroll !== null ? base.scroll : {};
	const { x: _dropHorizontalScroll } = scrollBase, scrollWithoutX = _objectWithoutProperties(scrollBase, _excluded);
	return _objectSpread2(_objectSpread2({}, base), {}, {
		columns,
		infiniteScroll: true,
		size: "small",
		className: classNames(typeof base.className === "string" ? base.className : void 0, "pisell-reservation-mobile-table-grid"),
		scroll: _objectSpread2(_objectSpread2({}, scrollWithoutX), {}, { autoCalc: true })
	});
}
function buildReservationHudDrawerToolbarConfig(params) {
	const 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 } }
			}
		}]
	});
	const builtClass = typeof built.className === "string" ? built.className : void 0;
	const builtSearch = typeof built.search === "object" && built.search !== null ? built.search : void 0;
	const priorModalStyle = builtSearch && typeof builtSearch.modalStyle === "object" && builtSearch.modalStyle !== null && !Array.isArray(builtSearch.modalStyle) ? builtSearch.modalStyle : {};
	return _objectSpread2(_objectSpread2({}, built), {}, {
		mergeCompactNarrowTrailingWithQuickFilterRow: true,
		search: params.searchGetContainer && builtSearch ? _objectSpread2(_objectSpread2({}, builtSearch), {}, {
			modalWidth: "100%",
			modalStyle: _objectSpread2(_objectSpread2({}, priorModalStyle), {}, {
				marginLeft: 0,
				marginRight: 0,
				width: "100%",
				maxWidth: "100%"
			})
		}) : built.search,
		className: classNames(builtClass, "pisell-reservation-hud-table-toolbar")
	});
}
//#endregion
export { adaptFilterConfigForMobile, adaptQuickFiltersForMobileToolbar, buildReservationHudDrawerToolbarConfig, buildReservationMobileTableGridConfig, buildReservationMobileTableToolbarConfig, buildReservationPhoneNarrowStackToolbarConfig };
