const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_objectWithoutProperties = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_PisellSingleSelect = require("../../../pisellSingleSelect/PisellSingleSelect.js");
const require_PisellMultipleSelect = require("../../../pisellMultipleSelect/PisellMultipleSelect.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
//#region src/components/filter/components/FilterItem/AsyncOptionsSelectWrapper.tsx
/**
* 筛选项中 singleSelect/multipleSelect 的异步 options 包装器。
* 当列配置传入 getOptions（同步或异步）时，先解析再渲染 PisellSingleSelect/PisellMultipleSelect。
*/
const _excluded = [
	"getOptions",
	"fieldType",
	"value",
	"onChange"
];
function normalizeOptions(list) {
	if (!Array.isArray(list)) return [];
	return list.map((item) => item && typeof item === "object" && "label" in item && "value" in item ? {
		label: String(item.label),
		value: item.value
	} : {
		label: String(item),
		value: item
	});
}
const AsyncOptionsSelectWrapper = (props) => {
	const { getOptions, fieldType, value, onChange } = props, rest = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
	const [options, setOptions] = (0, react.useState)([]);
	const [loading, setLoading] = (0, react.useState)(true);
	(0, react.useEffect)(() => {
		setLoading(true);
		const result = getOptions();
		Promise.resolve(result).then((list) => {
			setOptions(normalizeOptions(list));
		}).finally(() => {
			setLoading(false);
		});
	}, [getOptions]);
	const commonProps = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, rest), {}, {
		options,
		mode: "edit"
	});
	if (loading) return /* @__PURE__ */ react.default.createElement(antd.Spin, {
		spinning: true,
		size: "small"
	}, /* @__PURE__ */ react.default.createElement("span", { style: {
		display: "inline-block",
		minWidth: 120,
		minHeight: 32
	} }));
	if (fieldType === "multipleSelect") return /* @__PURE__ */ react.default.createElement(require_PisellMultipleSelect.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, commonProps), {}, {
		value,
		onChange
	}));
	return /* @__PURE__ */ react.default.createElement(require_PisellSingleSelect.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, commonProps), {}, {
		value,
		onChange
	}));
};
AsyncOptionsSelectWrapper.displayName = "AsyncOptionsSelectWrapper";
//#endregion
exports.default = AsyncOptionsSelectWrapper;
