const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
//#region src/plus/saleDetail/hooks/saleDetailActions/utils.ts
const DEFAULT_ACTION_CONFIG = {
	note: {
		row: 1,
		order: 10,
		buttonProps: { size: "large" }
	},
	save: {
		row: 1,
		order: 20,
		buttonProps: { size: "large" }
	},
	checkout: {
		row: 1,
		order: 30,
		buttonProps: { size: "large" }
	},
	refund: {
		row: 1,
		order: 10,
		buttonProps: { size: "large" }
	},
	return: {
		row: 1,
		order: 20,
		buttonProps: { size: "large" }
	},
	edit: {
		row: 1,
		order: 30,
		buttonProps: { size: "large" }
	},
	print: {
		row: 1,
		order: 20,
		buttonProps: { size: "large" }
	},
	"print-product-voucher": {
		row: 3,
		order: 10,
		buttonProps: { size: "large" }
	},
	"print-receipts": {
		row: 3,
		order: 30,
		buttonProps: { size: "large" }
	},
	"print-wristband": {
		row: 3,
		order: 20,
		buttonProps: { size: "large" }
	},
	"print-all": {
		row: 3,
		order: 40,
		buttonProps: { size: "large" }
	},
	cancel: {
		row: 3,
		order: 30,
		buttonProps: { size: "large" }
	},
	more: {
		row: 2,
		order: 10,
		buttonProps: { size: "large" }
	}
};
function toButtonGroupList(items) {
	const actionRows = items.filter((item) => !item.hidden).sort((prev, next) => {
		var _prev$order, _next$order;
		return ((_prev$order = prev.order) !== null && _prev$order !== void 0 ? _prev$order : 0) - ((_next$order = next.order) !== null && _next$order !== void 0 ? _next$order : 0);
	}).reduce((rows, item) => {
		var _item$row;
		const row = (_item$row = item.row) !== null && _item$row !== void 0 ? _item$row : 1;
		rows[row] = rows[row] || [];
		rows[row].push(item);
		return rows;
	}, {});
	return Object.keys(actionRows).map(Number).sort((prev, next) => prev - next).map((row) => actionRows[row]).filter((rowItems) => rowItems.length > 0);
}
function getActionKey(action) {
	return typeof action === "string" ? action : action.name;
}
function getActionConfig(action) {
	return typeof action === "string" ? {} : action;
}
function mergeActionItem(item, config) {
	return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), config), {}, { buttonProps: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item.buttonProps), config.buttonProps) });
}
function toDropdownMenuItem(item) {
	const { buttonProps } = item;
	return {
		key: item.id,
		label: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.children,
		icon: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.icon,
		danger: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.danger,
		disabled: Boolean((buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled) || (buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.loading)),
		onClick: buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.onClick,
		children: item.isMore ? item.menuData : void 0
	};
}
function getSortedVisibleActionItems(items) {
	return items.filter((item) => !item.hidden).sort((prev, next) => {
		var _prev$order2, _next$order2;
		return ((_prev$order2 = prev.order) !== null && _prev$order2 !== void 0 ? _prev$order2 : 0) - ((_next$order2 = next.order) !== null && _next$order2 !== void 0 ? _next$order2 : 0);
	});
}
function resolveSaleDetailOrderId(dataSource) {
	var _dataSource$sales$tem, _dataSource$sales$tem2, _dataSource$sales$sal;
	const id = (_dataSource$sales$tem = (_dataSource$sales$tem2 = dataSource.sales.tempOrder) === null || _dataSource$sales$tem2 === void 0 ? void 0 : _dataSource$sales$tem2.order_id) !== null && _dataSource$sales$tem !== void 0 ? _dataSource$sales$tem : (_dataSource$sales$sal = dataSource.sales.salesDetail) === null || _dataSource$sales$sal === void 0 || (_dataSource$sales$sal = _dataSource$sales$sal.header) === null || _dataSource$sales$sal === void 0 ? void 0 : _dataSource$sales$sal.order_id;
	if (id == null || id === "") return void 0;
	if (typeof id === "number" && Number.isFinite(id)) return id;
	const value = String(id).trim();
	if (!value) return void 0;
	const numericId = Number(value);
	return Number.isFinite(numericId) && String(numericId) === value ? numericId : value;
}
function getSalesHostModule(pisellos) {
	var _getModule;
	return pisellos === null || pisellos === void 0 || (_getModule = pisellos.getModule) === null || _getModule === void 0 ? void 0 : _getModule.call(pisellos, "sales");
}
function updateLocalOrder(action, orderId) {
	if (orderId == null || typeof action !== "function") return;
	action({
		type: "webpos.updateLocalOrderApi",
		data: { order_id: orderId }
	});
}
//#endregion
exports.DEFAULT_ACTION_CONFIG = DEFAULT_ACTION_CONFIG;
exports.getActionConfig = getActionConfig;
exports.getActionKey = getActionKey;
exports.getSalesHostModule = getSalesHostModule;
exports.getSortedVisibleActionItems = getSortedVisibleActionItems;
exports.mergeActionItem = mergeActionItem;
exports.resolveSaleDetailOrderId = resolveSaleDetailOrderId;
exports.toButtonGroupList = toButtonGroupList;
exports.toDropdownMenuItem = toDropdownMenuItem;
exports.updateLocalOrder = updateLocalOrder;
