const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_locales = require("../../locales.js");
const require_index = require("../ScrollableList/index.js");
const require_PaymentMethodItem = require("./PaymentMethodItem.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/checkout/components/PaymentOptionsModule/index.tsx
const SHOW_METHODS_CODE = [
	"EFTPOS_LINKLY",
	"EFTPOS",
	"EFTPOS_TYRO",
	"EFTPOS_WINDCAVE",
	"EFTPOS_PAYO",
	"EFTPOS_HUIFU"
];
function PaymentOptionsModule({ amountSymbol, orderInfo, onClick, paymentMethods = [], customAmount, title, disabled = false, showCashPayment = false }) {
	var _context$appHelper, _context$appHelper$ge, _context$appHelper$ge2, _context$appHelper$ut;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_locales.default, ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.call(_context$appHelper)) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge = _context$appHelper$ge.locales) === null || _context$appHelper$ge === void 0 || (_context$appHelper$ge2 = _context$appHelper$ge.getLocale) === null || _context$appHelper$ge2 === void 0 ? void 0 : _context$appHelper$ge2.call(_context$appHelper$ge)) || ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut = _context$appHelper$ut.storage) === null || _context$appHelper$ut === void 0 ? void 0 : _context$appHelper$ut.get("umi_locale")) || "en");
	const getText = (key, fallback) => {
		var _context$appHelper2, _context$appHelper2$g, _context$appHelper2$g2, _context$appHelper$ut2, _checkoutLocales;
		const checkoutText = (_checkoutLocales = require_locales.default[((_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$g = _context$appHelper2.getApp) === null || _context$appHelper2$g === void 0 || (_context$appHelper2$g = _context$appHelper2$g.call(_context$appHelper2)) === null || _context$appHelper2$g === void 0 || (_context$appHelper2$g = _context$appHelper2$g.locales) === null || _context$appHelper2$g === void 0 || (_context$appHelper2$g2 = _context$appHelper2$g.getLocale) === null || _context$appHelper2$g2 === void 0 ? void 0 : _context$appHelper2$g2.call(_context$appHelper2$g)) || ((_context$appHelper$ut2 = context.appHelper.utils) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.storage) === null || _context$appHelper$ut2 === void 0 ? void 0 : _context$appHelper$ut2.get("umi_locale")) || "en"]) === null || _checkoutLocales === void 0 ? void 0 : _checkoutLocales[key];
		if (checkoutText) return checkoutText;
		return _pisell_utils.locales.getText(key) || fallback;
	};
	const displayTitle = typeof title === "string" ? title : title ? String(title) : getText("cards.and.digitals", "Cards & Digitals");
	const filteredPaymentMethods = paymentMethods.filter((item) => !(item.type === "app" && item.code === "EFTPOS_LINKLY") && (["custom"].includes(item.type) || SHOW_METHODS_CODE.includes(item.code)));
	const { run: handlePaymentClick } = (0, ahooks.useDebounceFn)((method) => {
		if (disabled) return;
		if (typeof onClick === "function") onClick(method);
	}, {
		wait: 1e3,
		leading: true,
		trailing: false
	});
	return /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module", { "payment-options-module-disabled": disabled }) }, /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-title") }, /* @__PURE__ */ react.default.createElement("span", null, displayTitle)), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("payment-options-module-list-container") }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		height: "100%",
		maxHeight: 314,
		gradientColor: "rgba(139, 92, 246, 0.1)",
		gradientHeight: 50,
		columnCount: showCashPayment ? 1 : 2,
		rowGap: 7,
		columnGap: 8,
		containerStyle: {
			width: "100%",
			flex: 1,
			minHeight: 0,
			position: "relative",
			paddingBottom: 8
		}
	}, filteredPaymentMethods.map((method) => /* @__PURE__ */ react.default.createElement(require_PaymentMethodItem.default, {
		size: (filteredPaymentMethods === null || filteredPaymentMethods === void 0 ? void 0 : filteredPaymentMethods.length) === 2 ? "large" : "default",
		key: method.id,
		method,
		amountSymbol,
		customAmount,
		disabled,
		onClick: handlePaymentClick,
		getText
	})))));
}
//#endregion
exports.SHOW_METHODS_CODE = SHOW_METHODS_CODE;
exports.default = PaymentOptionsModule;
