const require_runtime = require("../../../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_serve = require("../serve.js");
const require_utils = require("../utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/pay/toC/PaymentMethods/WalletPass/List/index.tsx
const WalletPassList = (0, react.forwardRef)((props, ref) => {
	const { title, onChange, data: propsData, value, walletSetting, onLoadingChange, loading: propsLoading, onChangeDebounce } = props;
	const [data, setData] = (0, react.useState)(propsData || []);
	const [loading, setLoading] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		if (propsData) setData(propsData);
	}, [propsData]);
	(0, react.useEffect)(() => {
		setLoading(!!propsLoading);
	}, [propsLoading]);
	const getList = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (params, formatList) {
			setLoading(true);
			try {
				let list = (yield require_serve.getMachineCodeList(params)) || [];
				if ((0, _pisell_utils.isFunction)(formatList)) list = formatList(list);
				setData(require_utils.formatMachineCodeServer2CardList(list, value));
			} catch (err) {
				console.error(err);
			}
			setLoading(false);
		});
		return function getList(_x, _x2) {
			return _ref.apply(this, arguments);
		};
	}();
	const init = (params, formatList) => {
		getList(params, formatList);
	};
	(0, react.useImperativeHandle)(ref, () => ({ init }));
	(0, react.useEffect)(() => {
		onLoadingChange === null || onLoadingChange === void 0 || onLoadingChange(loading);
	}, [loading]);
	/**
	* 拆分出可用的和不可用的列表
	*/
	const { availableList, disabledList } = (0, react.useMemo)(() => {
		const _disabledList = [];
		const _availableList = [];
		data.forEach((item) => {
			if (item.disabled) _disabledList.push(item);
			else _availableList.push(item);
		});
		return {
			disabledList: _disabledList,
			availableList: _availableList
		};
	}, [data]);
	const handleChange = (0, ahooks.useMemoizedFn)((val) => {
		onChange === null || onChange === void 0 || onChange(val, require_utils.getDataByIds(data, val));
	});
	const empty = (0, react.useMemo)(() => {
		return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellEmpty, {
			icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-a-wallet-021",
				style: { color: "#667085" }
			}),
			description: _pisell_utils.locales.getText("tocPay.text.walletPassEmpty")(walletSetting === null || walletSetting === void 0 ? void 0 : walletSetting.name)
		});
	}, []);
	return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellLoading, { loading }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-walletPass-list-wrap" }, title && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-walletPass-list-title" }, title), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellCardList, {
		data: availableList,
		hasMore: false,
		value,
		onChange: handleChange,
		showEmpty: data.length === 0,
		empty,
		onChangeDebounce
	}), !!disabledList.length && /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-walletPass-list-disabled" }, _pisell_utils.locales.getText("tocPay.text.walletPassDisabled")), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellCardList, {
		mode: void 0,
		data: disabledList,
		hasMore: false
	}))));
});
var List_default = (0, react.memo)(WalletPassList);
//#endregion
exports.default = List_default;
