require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_hooks = require("../../hooks.js");
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/ecocup/components/CupStatusModal/hooks.ts
const useCupAction = () => {
	const { put } = require_hooks.useRequest();
	const [loading, setLoading] = (0, react.useState)(false);
	const { goalShopId } = require_hooks.useGetGoalShopInfo();
	return {
		run: (0, ahooks.useMemoizedFn)(function() {
			var _ref = require_asyncToGenerator._asyncToGenerator(function* (cupId, action) {
				try {
					setLoading(true);
					const res = yield put(`/shop/wallet/eco/cup/action/${cupId}`, {
						action,
						goal_shop_id: goalShopId
					});
					if ((res === null || res === void 0 ? void 0 : res.code) == 200) return true;
					return false;
				} catch (error) {
					console.error(error);
					return false;
				} finally {
					setLoading(false);
				}
			});
			return function(_x, _x2) {
				return _ref.apply(this, arguments);
			};
		}()),
		loading
	};
};
/**
* @description: 批量归还杯子
* @return {*}
*/
const useBatchCupAction = () => {
	const { post } = require_hooks.useRequest();
	const [loading, setLoading] = (0, react.useState)(false);
	return {
		run: (0, ahooks.useMemoizedFn)(function() {
			var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (eco_cup_ids) {
				try {
					setLoading(true);
					const res = yield post("/shop/wallet/eco/cups-return", { eco_cup_ids });
					if ((res === null || res === void 0 ? void 0 : res.code) == 200) return true;
					return false;
				} catch (error) {
					console.error(error);
					return false;
				} finally {
					setLoading(false);
				}
			});
			return function(_x3) {
				return _ref2.apply(this, arguments);
			};
		}()),
		loading
	};
};
/**
* @description: 统计杯子列表中的客户、店铺、时间数量
* @param {ICup[]} cupList - 杯子列表
* @return {object} 返回统计信息和是否为多个的标识
*/
const useCupListStatistics = (cupList) => {
	return (0, react.useMemo)(() => {
		var _cupList$, _cupList$2, _cupList$3;
		if (cupList.length === 0) return {
			hasMultipleCustomers: false,
			hasMultipleShops: false,
			hasMultipleTimes: false,
			uniqueCustomer: null,
			uniqueShop: null,
			uniqueTime: null
		};
		const customerIds = new Set(cupList.map((cup) => cup === null || cup === void 0 ? void 0 : cup.customer_id).filter((id) => id));
		const shopIds = new Set(cupList.map((cup) => cup === null || cup === void 0 ? void 0 : cup.current_shop_id).filter((id) => id));
		const times = new Set(cupList.map((cup) => cup === null || cup === void 0 ? void 0 : cup.operated_at).filter((time) => time));
		return {
			hasMultipleCustomers: customerIds.size > 1,
			hasMultipleShops: shopIds.size > 1,
			hasMultipleTimes: times.size > 1,
			uniqueCustomer: (_cupList$ = cupList[0]) === null || _cupList$ === void 0 ? void 0 : _cupList$.customer,
			uniqueShop: (_cupList$2 = cupList[0]) === null || _cupList$2 === void 0 ? void 0 : _cupList$2.current_shop,
			uniqueTime: (_cupList$3 = cupList[0]) === null || _cupList$3 === void 0 ? void 0 : _cupList$3.operated_at
		};
	}, [cupList]);
};
//#endregion
exports.useBatchCupAction = useBatchCupAction;
exports.useCupAction = useCupAction;
exports.useCupListStatistics = useCupListStatistics;
