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/scanOrder/components/Footer/index.tsx
function Footer(props) {
	const { cartItems, summary, actionText, onAction, disabled = false } = props;
	const [cartOpen, setCartOpen] = useState(false);
	const totalAmount = useMemo(() => {
		var _ref, _ref2, _ref3, _ref4, _ref5, _summary$total_amount;
		const rawAmount = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_summary$total_amount = summary === null || summary === void 0 ? void 0 : summary.total_amount) !== null && _summary$total_amount !== void 0 ? _summary$total_amount : summary === null || summary === void 0 ? void 0 : summary.expect_amount) !== null && _ref5 !== void 0 ? _ref5 : summary === null || summary === void 0 ? void 0 : summary.amount) !== null && _ref4 !== void 0 ? _ref4 : summary === null || summary === void 0 ? void 0 : summary.total) !== null && _ref3 !== void 0 ? _ref3 : summary === null || summary === void 0 ? void 0 : summary.totalAmount) !== null && _ref2 !== void 0 ? _ref2 : summary === null || summary === void 0 ? void 0 : summary.payable_amount) !== null && _ref !== void 0 ? _ref : 0;
		const parsedAmount = Number(rawAmount);
		if (Number.isNaN(parsedAmount)) return "0.00";
		return parsedAmount.toFixed(2);
	}, [summary]);
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-footer" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-footer-left" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-footer-total-label" }, locales.getText("pisell2.event.total")), /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-footer-total-amount" }, "$", totalAmount)), /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-footer-right" }, /* @__PURE__ */ React.createElement(Badge, {
		count: (cartItems === null || cartItems === void 0 ? void 0 : cartItems.length) || 0,
		id: "scan-order-v2-cart-btn"
	}, /* @__PURE__ */ React.createElement(Button, {
		size: "large",
		className: "pisell-scan-order-footer-cart-btn",
		onClick: () => setCartOpen(true)
	}, /* @__PURE__ */ React.createElement(Image, {
		src: shoppingCartSvg,
		preview: false
	}))), /* @__PURE__ */ React.createElement(Button, {
		type: "primary",
		size: "large",
		className: `pisell-scan-order-footer-btn${disabled ? " pisell-scan-order-footer-btn-disabled" : ""}`,
		onClick: onAction
	}, actionText))), /* @__PURE__ */ React.createElement(Cart, {
		open: cartOpen,
		items: cartItems || [],
		summary: summary || {},
		onCancel: () => {
			setCartOpen(false);
		},
		onNext: () => {
			setCartOpen(false);
			onAction();
		}
	}));
}
//#endregion
export { Footer as default };
