var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/ecocup/components/CupStatusModal/hooks.ts
var hooks_exports = {};
__export(hooks_exports, {
  useBatchCupAction: () => useBatchCupAction,
  useCupAction: () => useCupAction,
  useCupListStatistics: () => useCupListStatistics
});
module.exports = __toCommonJS(hooks_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_hooks = require("../../hooks");
var useCupAction = () => {
  const { put } = (0, import_hooks.useRequest)();
  const [loading, setLoading] = (0, import_react.useState)(false);
  const { goalShopId } = (0, import_hooks.useGetGoalShopInfo)();
  const run = (0, import_ahooks.useMemoizedFn)(async (cupId, action) => {
    try {
      setLoading(true);
      const res = await put(`/shop/wallet/eco/cup/action/${cupId}`, { action, goal_shop_id: goalShopId });
      if ((res == null ? void 0 : res.code) == 200) {
        return true;
      }
      return false;
    } catch (error) {
      console.error(error);
      return false;
    } finally {
      setLoading(false);
    }
  });
  return {
    run,
    loading
  };
};
var useBatchCupAction = () => {
  const { post } = (0, import_hooks.useRequest)();
  const [loading, setLoading] = (0, import_react.useState)(false);
  const run = (0, import_ahooks.useMemoizedFn)(async (eco_cup_ids) => {
    try {
      setLoading(true);
      const res = await post("/shop/wallet/eco/cups-return", { eco_cup_ids });
      if ((res == null ? void 0 : res.code) == 200) {
        return true;
      }
      return false;
    } catch (error) {
      console.error(error);
      return false;
    } finally {
      setLoading(false);
    }
  });
  return {
    run,
    loading
  };
};
var useCupListStatistics = (cupList) => {
  return (0, import_react.useMemo)(() => {
    var _a, _b, _c;
    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 ? void 0 : cup.customer_id).filter((id) => id)
    );
    const shopIds = new Set(
      cupList.map((cup) => cup == null ? void 0 : cup.current_shop_id).filter((id) => id)
    );
    const times = new Set(
      cupList.map((cup) => cup == null ? void 0 : cup.operated_at).filter((time) => time)
    );
    const result = {
      hasMultipleCustomers: customerIds.size > 1,
      hasMultipleShops: shopIds.size > 1,
      hasMultipleTimes: times.size > 1,
      uniqueCustomer: (_a = cupList[0]) == null ? void 0 : _a.customer,
      uniqueShop: (_b = cupList[0]) == null ? void 0 : _b.current_shop,
      uniqueTime: (_c = cupList[0]) == null ? void 0 : _c.operated_at
    };
    return result;
  }, [cupList]);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useBatchCupAction,
  useCupAction,
  useCupListStatistics
});
