const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_index = require("../components/tabPane/index.js");
const require_index$1 = require("../components/emptyBooking/index.js");
const require_index$2 = require("../components/footer/index.js");
const require_model = require("./model.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/components/booking/payments/index.tsx
const paymentStatusMap = {
	paid: {
		text: _pisell_utils.locales.getText("pisell2.text.paid"),
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.CheckCircleFilled, { style: {
			color: "#16B364",
			fontSize: 20
		} })
	},
	voided: {
		text: _pisell_utils.locales.getText("pisell2.text.voided_pay"),
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.CloseCircleFilled, { style: {
			color: "#F04438",
			fontSize: 20
		} })
	},
	payment_processing: {
		text: _pisell_utils.locales.getText("pisell2.text.processing_pay"),
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.ExclamationCircleFilled, { style: {
			color: "#EAAA08",
			fontSize: 20
		} })
	}
};
const PaymentStatusTitle = (props) => {
	const { type, extra } = props;
	return /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-status-title" }, /* @__PURE__ */ react.default.createElement("span", { className: "payment-list-item-status-title-left" }, paymentStatusMap[type].icon || null, /* @__PURE__ */ react.default.createElement("span", { className: "payment-list-item-type" }, paymentStatusMap[type].text)), extra);
};
const Payments = require_model.Provider((props) => {
	const { globalState } = props;
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const [loading, setLoading] = (0, react.useState)(false);
	const [paymentList, setPaymentList] = (0, react.useState)([]);
	const [refundAmount, setRefundAmount] = (0, react.useState)();
	const init = () => {
		getPayments();
		getRefundInfo();
	};
	(0, react.useEffect)(() => {
		if (state.bookingDetail) init();
	}, [state.bookingDetail]);
	const getRefundInfo = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			setRefundAmount((yield state.apis.getRefundInfo()).total_refund_amount);
		});
		return function getRefundInfo() {
			return _ref.apply(this, arguments);
		};
	}();
	const getPayments = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* () {
			setLoading(true);
			const res = yield state.apis.getPaymentList({
				skip: 1,
				num: 100,
				order_id: state.bookingId,
				status: [
					"voided",
					"payment_processing",
					"paid"
				]
			});
			setPaymentList((res === null || res === void 0 ? void 0 : res.list) || []);
			setLoading(false);
		});
		return function getPayments() {
			return _ref2.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		document.body.id = "body";
		dispatch({
			type: "setState",
			payload: { setGlobalState: props.setGlobalState }
		});
	}, []);
	(0, react.useEffect)(() => {
		dispatch({
			type: "setState",
			payload: require_objectSpread2._objectSpread2({}, globalState)
		});
	}, [globalState]);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_index.default, {
		header: _pisell_utils.locales.getText("pisell2.text.payments"),
		footer: state.bookingId && /* @__PURE__ */ react.default.createElement(require_index$2.default, {
			state,
			dispatch,
			source: "payment"
		}),
		loading: loading && state.bookingId
	}, /* @__PURE__ */ react.default.createElement("div", { className: "payment-customer-pay-title" }, _pisell_utils.locales.getText("pisell2.text.customerpay")), state.bookingId && paymentList.length ? /* @__PURE__ */ react.default.createElement(antd.List, {
		dataSource: paymentList,
		renderItem: (item) => /* @__PURE__ */ react.default.createElement(antd.List.Item, null, /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item" }, /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-left" }, /* @__PURE__ */ react.default.createElement("div", {
			className: "payment-record",
			key: item.id
		}, /* @__PURE__ */ react.default.createElement(PaymentStatusTitle, {
			type: item.status,
			extra: /* @__PURE__ */ react.default.createElement("span", { className: "payment-list-item-pay-amount" }, (0, _pisell_utils.formatAmount)(item.amount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$"))
		}), /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-pay-methods" }, /* @__PURE__ */ react.default.createElement("span", { className: "payment-list-item-pay-name" }, item.payment_method_name || "-")), Number(item.service_fee) ? /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-surcharge" }, "(", _pisell_utils.locales.getText("pisell2.text.surcharge"), " ", (0, _pisell_utils.formatAmount)(item.service_fee, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$"), ")") : null, /* @__PURE__ */ react.default.createElement("div", { className: "payment-list-item-date" }, (0, dayjs.default)(item.payment_time || item.created_at).format("HH:mm YYYY/MM/DD"), /* @__PURE__ */ react.default.createElement("span", { className: "payment-list-item-platform-type" }, item.platform && _pisell_utils.locales.getText("pisell2.text.platform.type")(item.platform))))))))
	}) : /* @__PURE__ */ react.default.createElement(require_index$1.default, { description: state.bookingId ? _pisell_utils.locales.getText("pisell1.text.no-payments") : void 0 }), !!state.bookingId && !!Number(refundAmount) && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(antd.Divider, { className: "payment-divider" }), /* @__PURE__ */ react.default.createElement("div", { className: "payment-refund-wrap" }, /* @__PURE__ */ react.default.createElement("div", { className: "payment-refund-title" }, _pisell_utils.locales.getText("pisell2.text.refund"), ":"), /* @__PURE__ */ react.default.createElement("div", { className: "payment-refund-amount" }, /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell2.text.refund-amount")), /* @__PURE__ */ react.default.createElement("span", null, (0, _pisell_utils.formatAmount)(refundAmount, 2, (state === null || state === void 0 ? void 0 : state.amountSymbol) || "$")))), /* @__PURE__ */ react.default.createElement(antd.Divider, { className: "payment-divider" }))));
});
//#endregion
exports.default = Payments;
