import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext, { usePlatform } from "../../hooks/useEngineContext.js";
import useLocale from "../../hooks/useLocale.js";
import scanListener from "./utils/scanListener.js";
import { useState } from "react";
//#region src/components/ecocup/hooks.ts
/**
* 获取当前语言
*/
const useLanguage = () => {
	return useLocale() || "en";
};
/**
* 扫码监听
*/
const useScanListener = () => {
	var _context$appHelper;
	const { interaction } = ((_context$appHelper = useEngineContext().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const addListener = (key, callback) => {
		scanListener.addListener(interaction, key, callback);
	};
	const removeListener = (key) => {
		scanListener.removeListener(key);
	};
	const setActiveListener = (key) => {
		scanListener.setActiveListener(key);
	};
	return {
		addListener,
		removeListener,
		setActiveListener
	};
};
/**
* 获取app
*/
const useGetApp = () => {
	var _context$appHelper2;
	return (_context$appHelper2 = useEngineContext().appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 ? void 0 : _context$appHelper2.getApp;
};
/**
* 获取modal
*/
const useModal = (key) => {
	const [modalProps, setModalProps] = useState(null);
	const open = (props) => {
		setModalProps(_objectSpread2(_objectSpread2({ key }, props || {}), {}, {
			visible: true,
			onCancel: () => {
				var _props$onCancel;
				close();
				props === null || props === void 0 || (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 || _props$onCancel.call(props);
			},
			onOk: (values) => {
				var _props$onOk;
				console.log(`${key}_onOk`, values);
				close();
				props === null || props === void 0 || (_props$onOk = props.onOk) === null || _props$onOk === void 0 || _props$onOk.call(props, values);
			}
		}));
	};
	const close = () => {
		setModalProps({ visible: false });
	};
	return {
		modalProps: modalProps || {},
		visible: modalProps === null || modalProps === void 0 ? void 0 : modalProps.visible,
		open,
		close
	};
};
const useRequest = () => {
	var _context$appHelper3;
	const context = useEngineContext();
	const request = (context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.request) || {};
	const get = (url, data, config) => {
		return request === null || request === void 0 ? void 0 : request.get(url, data, config);
	};
	const post = (url, data, config) => {
		return request === null || request === void 0 ? void 0 : request.post(url, data, config);
	};
	const put = (url, data, config) => {
		return request === null || request === void 0 ? void 0 : request.put(url, data, config);
	};
	const remove = (url, data, config) => {
		return request === null || request === void 0 ? void 0 : request.remove(url, data, config);
	};
	return {
		get,
		post,
		put,
		remove
	};
};
/**
* @description: 获取goal_shop_id和是否是普通店铺
* @return {*}
*/
const useGetGoalShopInfo = () => {
	var _window;
	useEngineContext();
	const search = ((_window = window) === null || _window === void 0 || (_window = _window.location) === null || _window === void 0 ? void 0 : _window.search) || {};
	const goalShopId = new URLSearchParams(search).get("goal_shop_id");
	return {
		goalShopId: goalShopId ? Number(goalShopId) : void 0,
		isNormalShop: !!goalShopId
	};
};
/**
* 获取当前店铺id
*/
const useGetShopId = () => {
	var _context$appHelper4, _utils$getStore, _utils$getStore$getSt, _utils$getData, _utils$store, _utils$store$getState;
	const context = useEngineContext();
	const utils = (context === null || context === void 0 || (_context$appHelper4 = context.appHelper) === null || _context$appHelper4 === void 0 ? void 0 : _context$appHelper4.utils) || {};
	return (utils === null || utils === void 0 || (_utils$getStore = utils.getStore) === null || _utils$getStore === void 0 || (_utils$getStore = _utils$getStore.call(utils)) === null || _utils$getStore === void 0 || (_utils$getStore$getSt = _utils$getStore.getState) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.call(_utils$getStore)) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.global) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.shop) === null || _utils$getStore$getSt === void 0 ? void 0 : _utils$getStore$getSt.id) || (utils === null || utils === void 0 || (_utils$getData = utils.getData) === null || _utils$getData === void 0 ? void 0 : _utils$getData.call(utils, "shop_id")) || ((_utils$store = utils.store) === null || _utils$store === void 0 || (_utils$store$getState = _utils$store.getState) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.call(_utils$store)) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.global) === null || _utils$store$getState === void 0 || (_utils$store$getState = _utils$store$getState.globalConfig) === null || _utils$store$getState === void 0 ? void 0 : _utils$store$getState.id) || void 0;
};
/**
* @description: 是否是app端
* @return {*}
*/
const useIsApp = () => {
	const platform = usePlatform();
	return platform === "h5" || platform === "pc";
};
/**
* @description: 获取分享场景
* @return {*}
*/
const useGetShare = () => {
	var _window2;
	const search = ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.location) === null || _window2 === void 0 ? void 0 : _window2.search) || {};
	const source = new URLSearchParams(search).get("source");
	return {
		source,
		isEcoShare: source ? source === "ecoShare" : false
	};
};
//#endregion
export { useGetApp, useGetGoalShopInfo, useGetShare, useGetShopId, useIsApp, useLanguage, useModal, useRequest, useScanListener };
