var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/ecocup/hooks.ts
var hooks_exports = {};
__export(hooks_exports, {
  useGetApp: () => useGetApp,
  useGetGoalShopInfo: () => useGetGoalShopInfo,
  useGetShare: () => useGetShare,
  useGetShopId: () => useGetShopId,
  useIsApp: () => useIsApp,
  useLanguage: () => useLanguage,
  useModal: () => useModal,
  useRequest: () => useRequest,
  useScanListener: () => useScanListener
});
module.exports = __toCommonJS(hooks_exports);
var import_react = require("react");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_useLocale = __toESM(require("../../hooks/useLocale"));
var import_scanListener = __toESM(require("./utils/scanListener"));
var useLanguage = () => {
  const locale = (0, import_useLocale.default)();
  return locale || "en";
};
var useScanListener = () => {
  var _a;
  const context = (0, import_useEngineContext.default)();
  const { interaction } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
  const addListener = (key, callback) => {
    import_scanListener.default.addListener(interaction, key, callback);
  };
  const removeListener = (key) => {
    import_scanListener.default.removeListener(key);
  };
  const setActiveListener = (key) => {
    import_scanListener.default.setActiveListener(key);
  };
  return {
    addListener,
    removeListener,
    setActiveListener
  };
};
var useGetApp = () => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  return (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp;
};
var useModal = (key) => {
  const [modalProps, setModalProps] = (0, import_react.useState)(null);
  const open = (props) => {
    setModalProps({
      key,
      ...props || {},
      visible: true,
      onCancel: () => {
        var _a;
        close();
        (_a = props == null ? void 0 : props.onCancel) == null ? void 0 : _a.call(props);
      },
      onOk: (values) => {
        var _a;
        console.log(`${key}_onOk`, values);
        close();
        (_a = props == null ? void 0 : props.onOk) == null ? void 0 : _a.call(props, values);
      }
    });
  };
  const close = () => {
    setModalProps({ visible: false });
  };
  return {
    modalProps: modalProps || {},
    visible: modalProps == null ? void 0 : modalProps.visible,
    open,
    close
  };
};
var useRequest = () => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  const request = ((_b = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.request) || {};
  const get = (url, data, config) => {
    return request == null ? void 0 : request.get(url, data, config);
  };
  const post = (url, data, config) => {
    return request == null ? void 0 : request.post(url, data, config);
  };
  const put = (url, data, config) => {
    return request == null ? void 0 : request.put(url, data, config);
  };
  const remove = (url, data, config) => {
    return request == null ? void 0 : request.remove(url, data, config);
  };
  return {
    get,
    post,
    put,
    remove
  };
};
var useGetGoalShopInfo = () => {
  var _a;
  const context = (0, import_useEngineContext.default)();
  const search = ((_a = window == null ? void 0 : window.location) == null ? void 0 : _a.search) || {};
  const goalShopId = new URLSearchParams(search).get("goal_shop_id");
  return {
    goalShopId: goalShopId ? Number(goalShopId) : void 0,
    isNormalShop: !!goalShopId
  };
};
var useGetShopId = () => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
  const context = (0, import_useEngineContext.default)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const shopId = ((_g = (_f = (_e = (_d = (_c = (_b = utils == null ? void 0 : utils.getStore) == null ? void 0 : _b.call(utils)) == null ? void 0 : _c.getState) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.global) == null ? void 0 : _f.shop) == null ? void 0 : _g.id) || ((_h = utils == null ? void 0 : utils.getData) == null ? void 0 : _h.call(utils, "shop_id")) || ((_m = (_l = (_k = (_j = (_i = utils.store) == null ? void 0 : _i.getState) == null ? void 0 : _j.call(_i)) == null ? void 0 : _k.global) == null ? void 0 : _l.globalConfig) == null ? void 0 : _m.id) || void 0;
  return shopId;
};
var useIsApp = () => {
  const platform = (0, import_useEngineContext.usePlatform)();
  return platform === "h5" || platform === "pc";
};
var useGetShare = () => {
  var _a;
  const search = ((_a = window == null ? void 0 : window.location) == null ? void 0 : _a.search) || {};
  const source = new URLSearchParams(search).get("source");
  return {
    source,
    isEcoShare: source ? source === "ecoShare" : false
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useGetApp,
  useGetGoalShopInfo,
  useGetShare,
  useGetShopId,
  useIsApp,
  useLanguage,
  useModal,
  useRequest,
  useScanListener
});
