import { useVenueBookingSymbol } from "../../hooks.js";
import { useVenueBookingContext } from "../../context.js";
import Cart from "../Cart/index.js";
import React, { useMemo, useState } from "react";
import { locales } from "@pisell/utils";
import { Badge, Button, Image } from "@pisell/materials";
import shoppingCartSvg from "../../../appointmentBooking/assets/shopping-cart.svg";
import "./index.less";
//#region src/components/venueBooking/components/Footer/index.tsx
/**
* venueBooking 移动端底栏
* 参照 scanOrder/Footer 实现：总价显示 + Badge 购物车按钮 + 操作按钮
* 购物车抽屉（Cart drawer）由此组件内部管理状态
*/
function Footer() {
	var _viewModel$cartItems;
	const symbol = useVenueBookingSymbol();
	const { currentStep, viewModel, handlePrimaryAction, isSubmittingOrder } = useVenueBookingContext();
	const [cartOpen, setCartOpen] = useState(false);
	/** 从 OS summary 中提取总金额 */
	const totalAmount = useMemo(() => {
		var _ref, _ref2, _ref3, _ref4, _ref5, _viewModel$summary$to, _viewModel$summary, _viewModel$summary2, _viewModel$summary3, _viewModel$summary4, _viewModel$summary5, _viewModel$summary6;
		const rawAmount = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_viewModel$summary$to = (_viewModel$summary = viewModel.summary) === null || _viewModel$summary === void 0 ? void 0 : _viewModel$summary.total_amount) !== null && _viewModel$summary$to !== void 0 ? _viewModel$summary$to : (_viewModel$summary2 = viewModel.summary) === null || _viewModel$summary2 === void 0 ? void 0 : _viewModel$summary2.expect_amount) !== null && _ref5 !== void 0 ? _ref5 : (_viewModel$summary3 = viewModel.summary) === null || _viewModel$summary3 === void 0 ? void 0 : _viewModel$summary3.amount) !== null && _ref4 !== void 0 ? _ref4 : (_viewModel$summary4 = viewModel.summary) === null || _viewModel$summary4 === void 0 ? void 0 : _viewModel$summary4.total) !== null && _ref3 !== void 0 ? _ref3 : (_viewModel$summary5 = viewModel.summary) === null || _viewModel$summary5 === void 0 ? void 0 : _viewModel$summary5.totalAmount) !== null && _ref2 !== void 0 ? _ref2 : (_viewModel$summary6 = viewModel.summary) === null || _viewModel$summary6 === void 0 ? void 0 : _viewModel$summary6.payable_amount) !== null && _ref !== void 0 ? _ref : 0;
		const parsedAmount = Number(rawAmount);
		if (Number.isNaN(parsedAmount)) return "0.00";
		return parsedAmount.toFixed(2);
	}, [viewModel.summary]);
	/** 操作按钮文案：最后一步显示"立即支付"，其余步骤统一显示"下一步" */
	const actionText = useMemo(() => currentStep === "checkout" ? String(locales.getText("pisell2.venue.action.pay.now") || "立即支付") : String(locales.getText("pisell2.venue.action.next") || "下一步"), [currentStep]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-venue-booking-footer" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-venue-booking-footer-left" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-venue-booking-footer-total-label" }, locales.getText("pisell2.event.total") || "合计"), /* @__PURE__ */ React.createElement("div", { className: "pisell-venue-booking-footer-total-amount" }, symbol, totalAmount)), /* @__PURE__ */ React.createElement("div", { className: "pisell-venue-booking-footer-right" }, /* @__PURE__ */ React.createElement(Badge, {
		count: ((_viewModel$cartItems = viewModel.cartItems) === null || _viewModel$cartItems === void 0 ? void 0 : _viewModel$cartItems.length) || 0,
		id: "venue-booking-cart-btn"
	}, /* @__PURE__ */ React.createElement(Button, {
		size: "large",
		className: "pisell-venue-booking-footer-cart-btn",
		onClick: () => setCartOpen(true)
	}, /* @__PURE__ */ React.createElement(Image, {
		src: shoppingCartSvg,
		preview: false
	}))), /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		size: "large",
		className: "pisell-venue-booking-footer-btn",
		onClick: handlePrimaryAction,
		loading: isSubmittingOrder
	}, actionText))), /* @__PURE__ */ React.createElement(Cart, {
		open: cartOpen,
		items: viewModel.cartItems || [],
		summary: viewModel.summary || {},
		onCancel: () => setCartOpen(false),
		onNext: () => {
			setCartOpen(false);
			handlePrimaryAction();
		},
		confirmLoading: isSubmittingOrder
	}));
}
//#endregion
export { Footer as default };
