import { usePisellOS } from "../../../hooks/useEngineContext.js";
import { useCart } from "../Cart/index.js";
import { calculatePriceDetails } from "./utils.js";
import { useInit } from "../Init/index.js";
import { getDepositProtocolApi } from "./serve.js";
import React, { createContext, useMemo, useState } from "react";
//#region src/components/Sales/Summary/index.tsx
const defaultState = {};
const SummaryContext = createContext(void 0);
const SummaryProvider = ({ children }) => {
	const pisellos = usePisellOS();
	const { cartData } = useCart();
	const { initData } = useInit();
	const [isAgreeDepositPolicy, setIsAgreeDepositPolicy] = useState(false);
	const summaryModule = pisellos.getModule("summary");
	const summaryData = useMemo(() => {
		return calculatePriceDetails((initData === null || initData === void 0 ? void 0 : initData.shop) || {}, cartData.cartItems, summaryModule);
	}, [
		cartData.cartItems,
		initData === null || initData === void 0 ? void 0 : initData.shop,
		summaryModule
	]);
	const contextValue = {
		subtotal: summaryData.subtotal,
		total: summaryData.total,
		taxTitle: summaryData.taxTitle,
		totalTaxFee: summaryData.totalTaxFee,
		isPriceIncludeTax: summaryData.isPriceIncludeTax,
		taxRate: summaryData.taxRate,
		surcharge: summaryData.surcharge,
		deposit: summaryData.deposit,
		isAgreeDepositPolicy,
		setIsAgreeDepositPolicy,
		getDepositProtocol: getDepositProtocolApi
	};
	return /* @__PURE__ */ React.createElement(SummaryContext.Provider, { value: contextValue }, children);
};
/**
* 使用步骤管理的Hook
* @throws {Error} 如果在StepProvider外部使用会抛出错误
* @returns {StepContextType} 步骤管理上下文
*/
const useSummary = () => {
	const context = React.useContext(SummaryContext);
	if (!context) throw new Error("useSummary must be used within a SummaryProvider");
	return context;
};
var Summary_default = { defaultState };
//#endregion
export { SummaryProvider, Summary_default as default, useSummary };
