require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_utils = require("./utils.js");
const require_orderActions = require("./orderActions.js");
require("./types.js");
const require_printActions = require("./printActions.js");
let react = require("react");
//#region src/plus/saleDetail/hooks/saleDetailActions/index.ts
const DEFAULT_SALE_DETAIL_ACTIONS = ["checkout"];
function useMoreActionItem({ printReceiptsAction, printWristbandAction, cancelAction }) {
	return (0, react.useMemo)(() => ({
		id: "more",
		isMore: true,
		buttonProps: {
			block: true,
			className: "pisell-sale-detail-button-actions__button"
		},
		menuData: [
			require_utils.toDropdownMenuItem(printReceiptsAction),
			require_utils.toDropdownMenuItem(printWristbandAction),
			require_utils.toDropdownMenuItem(cancelAction)
		]
	}), [
		cancelAction,
		printReceiptsAction,
		printWristbandAction
	]);
}
function useSaleDetailActions({ dataSource, actions = DEFAULT_SALE_DETAIL_ACTIONS }) {
	var _dataSource$sales$tem;
	const editAction = require_orderActions.useEditActionItem({ dataSource });
	const refundAction = require_orderActions.useRefundActionItem({ dataSource });
	const returnAction = require_orderActions.useReturnActionItem({ dataSource });
	const printAction = require_printActions.usePrintActionItem();
	const printProductVoucherAction = require_printActions.usePrintProductVoucherActionItem({ dataSource });
	const printReceiptsAction = require_printActions.usePrintReceiptsActionItem({ dataSource });
	const printWristbandAction = require_printActions.usePrintWristbandActionItem({ dataSource });
	const printAllAction = require_printActions.usePrintAllActionItem({ dataSource });
	const cancelAction = require_orderActions.useCancelActionItem({ dataSource });
	const noteAction = require_orderActions.useNoteActionItem({ dataSource });
	const saveAction = require_orderActions.useSaveActionItem({ dataSource });
	const checkoutAction = require_orderActions.useCheckoutActionItem({ dataSource });
	const moreAction = useMoreActionItem({
		printReceiptsAction,
		printWristbandAction,
		cancelAction
	});
	const isCancelled = ((_dataSource$sales$tem = dataSource.sales.tempOrder) === null || _dataSource$sales$tem === void 0 ? void 0 : _dataSource$sales$tem.status) === "cancelled";
	return (0, react.useMemo)(() => {
		if (isCancelled) return [];
		const actionItemMap = {
			edit: editAction,
			refund: refundAction,
			return: returnAction,
			print: printAction,
			"print-product-voucher": printProductVoucherAction,
			"print-receipts": printReceiptsAction,
			"print-wristband": printWristbandAction,
			"print-all": printAllAction,
			cancel: cancelAction,
			note: noteAction,
			save: saveAction,
			checkout: checkoutAction,
			more: moreAction
		};
		const resolveActionItem = (action) => {
			var _config$items;
			const actionKey = require_utils.getActionKey(action);
			const actionConfig = require_utils.getActionConfig(action);
			const config = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_utils.DEFAULT_ACTION_CONFIG[actionKey]), actionConfig), {}, { buttonProps: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_utils.DEFAULT_ACTION_CONFIG[actionKey].buttonProps), actionConfig.buttonProps) });
			const actionItem = require_utils.mergeActionItem(actionItemMap[actionKey], config);
			if (!((_config$items = config.items) === null || _config$items === void 0 ? void 0 : _config$items.length)) return actionItem;
			const nestedActionItems = require_utils.getSortedVisibleActionItems(config.items.map(resolveActionItem));
			if (nestedActionItems.length === 1) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, nestedActionItems[0]), {}, {
				row: actionItem.row,
				order: actionItem.order
			});
			const menuData = nestedActionItems.map(require_utils.toDropdownMenuItem);
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, actionItem), {}, {
				isMore: true,
				menuData
			});
		};
		return require_utils.toButtonGroupList(actions.map(resolveActionItem));
	}, [
		actions,
		cancelAction,
		checkoutAction,
		editAction,
		isCancelled,
		moreAction,
		noteAction,
		printAction,
		printAllAction,
		printProductVoucherAction,
		printReceiptsAction,
		printWristbandAction,
		refundAction,
		returnAction,
		saveAction
	]);
}
//#endregion
exports.useSaleDetailActions = useSaleDetailActions;
