const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../../components/subTotal/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
require("./index.less");
//#region src/plus/saleDetail/components/AmountDetails/index.tsx
const EMPTY_AMOUNT_VIEW = {
	totalText: "",
	arrearsText: "",
	subTotalList: [],
	orderTotalList: [],
	hasOrderTotal: false
};
function AmountDetails({ dataSource }) {
	var _context$appHelper, _dataSource$sales, _dataSource$summary;
	const context = require_useEngineContext.default();
	const { getData } = (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils;
	const [showDetail, setShowDetail] = (0, react.useState)(false);
	const amountView = (0, react.useMemo)(() => {
		var _getData;
		const tempOrder = dataSource.sales.tempOrder;
		const summary = dataSource.summary.summary;
		if (!tempOrder || !summary) return EMPTY_AMOUNT_VIEW;
		const symbol = context.appHelper.utils.getSymbolic();
		const translationOriginal = context.appHelper.utils.translationOriginal;
		const hasPayment = tempOrder.payments.length > 0;
		const parsedTaxRate = Number((_getData = getData("tax_rate")) !== null && _getData !== void 0 ? _getData : 10);
		const surchargeList = (summary.surcharges ? summary.surcharges : []).filter((surcharge) => surcharge.name).map((surcharge) => ({
			key: `custom_surcharge_${surcharge.surcharge_id}`,
			value: surcharge.amount,
			label: translationOriginal(surcharge.name)
		}));
		const subTotalList = [
			{
				key: "sub_total",
				value: summary.product_amount
			},
			...surchargeList,
			{
				key: "tax",
				value: summary.tax_fee,
				tax: {
					is_price_include_tax: getData("is_price_include_tax"),
					rate: Number.isNaN(parsedTaxRate) ? .1 : parsedTaxRate / 100,
					title: getData("tax_title") || "GST"
				}
			},
			{
				key: "discount",
				value: summary.discount_amount
			},
			{
				key: "expect_amount",
				value: summary.expect_amount,
				label: _pisell_utils.locales.getText("pisell2.sale-detail.total")
			},
			{
				hidden: !Number(summary.rounding_amount),
				key: "custom_roundingAmount",
				value: summary.rounding_amount,
				label: _pisell_utils.locales.getText("pisell2.sale-detail.rounding")
			}
		];
		const orderTotalList = [
			{
				hidden: !hasPayment,
				key: "custom_orderPaidAmount",
				value: summary.order_paid_amount,
				label: _pisell_utils.locales.getText("pisell2.text.amount-paid-on-order")
			},
			{
				hidden: !hasPayment,
				key: "custom_actualPaidAmount",
				value: summary.customer_paid_amount,
				label: _pisell_utils.locales.getText("pisell2.text.amount-actually-paid-by-the-customer")
			},
			{
				hidden: !hasPayment || !Number(summary.total_refund_amount),
				key: "custom_totalRefundAmount",
				value: summary.total_refund_amount,
				label: _pisell_utils.locales.getText("pisell2.text.refunded-amount")
			}
		];
		return {
			totalText: `${_pisell_utils.locales.getText("pisell2.sale-detail.to-pay")}: ${(0, _pisell_utils.formatAmount)(summary.total_amount, 2, symbol)}`,
			arrearsText: "",
			subTotalList,
			orderTotalList,
			hasOrderTotal: hasPayment
		};
	}, [
		context,
		(_dataSource$sales = dataSource.sales) === null || _dataSource$sales === void 0 ? void 0 : _dataSource$sales.tempOrder,
		(_dataSource$summary = dataSource.summary) === null || _dataSource$summary === void 0 ? void 0 : _dataSource$summary.summary
	]);
	return /* @__PURE__ */ react.default.createElement("section", { className: (0, classnames.default)("pisell-sale-detail-amount-details", { "pisell-sale-detail-amount-details--open": showDetail }) }, /* @__PURE__ */ react.default.createElement(antd.Skeleton, {
		title: false,
		round: true,
		loading: false,
		active: true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-amount-details__summary" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-left" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-total" }, amountView.totalText), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-arrears" }, amountView.arrearsText)), /* @__PURE__ */ react.default.createElement("span", {
		className: "pisell-sale-detail-amount-details__details-trigger",
		onClick: () => setShowDetail(!showDetail)
	}, _pisell_utils.locales.getText("pisell2.sale-detail.details"), " ", /* @__PURE__ */ react.default.createElement("span", { className: (0, classnames.default)("pisell-sale-detail-amount-details__details-icon", { "pisell-sale-detail-amount-details__details-icon--open": showDetail }) }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, { type: "pisell2-chevron-down" })))), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("pisell-sale-detail-amount-details__details", { "pisell-sale-detail-amount-details__details--open": showDetail }) }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		mode: "column1",
		list: amountView.subTotalList,
		style: { padding: 0 }
	}), amountView.hasOrderTotal ? /* @__PURE__ */ react.default.createElement("div", { className: "pisell-sale-detail-amount-details__divider" }) : null, amountView.hasOrderTotal ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		mode: "column1",
		list: amountView.orderTotalList,
		style: { padding: " 0 0 16px" }
	}) : null)));
}
//#endregion
exports.AmountDetails = AmountDetails;
