import useEngineContext from "../../../hooks/useEngineContext.js";
import React, { createContext } from "react";
//#region src/components/Sales/Customer/index.tsx
const CustomerContext = createContext(void 0);
const CustomerProvider = ({ children }) => {
	const context = useEngineContext();
	const utils = context.appHelper.utils || {};
	const isLogin = () => {
		var _utils$token, _utils$token$get;
		return !!(utils === null || utils === void 0 || (_utils$token = utils.token) === null || _utils$token === void 0 || (_utils$token$get = _utils$token.get) === null || _utils$token$get === void 0 ? void 0 : _utils$token$get.call(_utils$token));
	};
	const openLoginModal = (params) => {
		const { callback } = params || {};
		utils.action({
			type: "pisell1.login",
			data: { type: "plugin" },
			callback
		});
	};
	const getUserInfo = () => {
		var _utils$getStore$getSt;
		const userInfo = (_utils$getStore$getSt = utils.getStore().getState()) === null || _utils$getStore$getSt === void 0 || (_utils$getStore$getSt = _utils$getStore$getSt.global) === null || _utils$getStore$getSt === void 0 ? void 0 : _utils$getStore$getSt.userInfo;
		const localUserInfo = JSON.parse(utils.storage.get("customer") || "{}");
		return (userInfo === null || userInfo === void 0 ? void 0 : userInfo.id) ? userInfo : localUserInfo;
	};
	const contextValue = {
		appContext: context,
		appUtils: utils,
		isLogin,
		openLoginModal,
		getUserInfo
	};
	return /* @__PURE__ */ React.createElement(CustomerContext.Provider, { value: contextValue }, children);
};
/**
* 使用步骤管理的Hook
* @throws {Error} 如果在StepProvider外部使用会抛出错误
* @returns {StepContextType} 步骤管理上下文
*/
const useCustomer = () => {
	const context = React.useContext(CustomerContext);
	if (!context) throw new Error("useCustomer must be used within a CustomerContext");
	return context;
};
//#endregion
export { CustomerProvider, useCustomer };
