import { _objectSpread2 } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import { _asyncToGenerator } from "../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import Select from "../../../../../select/index.js";
import React, { forwardRef, useCallback, useEffect, useState } from "react";
import { useDebounceFn } from "ahooks";
//#region src/components/table/Table/fields/select/Edit/index.tsx
const _excluded = [
	"value",
	"onChange",
	"onBlur",
	"style",
	"bordered",
	"options",
	"waitTime"
];
const Edit = (props, ref) => {
	const { value, onChange, onBlur, style, bordered, options, waitTime = 500 } = props, others = _objectWithoutProperties(props, _excluded);
	const [resolvedOptions, setResolvedOptions] = useState([]);
	const fetchOptions = useCallback(function() {
		var _ref = _asyncToGenerator(function* (searchValue) {
			if (typeof options === "function") try {
				setResolvedOptions((yield options(searchValue)) || []);
			} catch (error) {}
			else setResolvedOptions(options || []);
		});
		return function(_x) {
			return _ref.apply(this, arguments);
		};
	}(), [options]);
	const { run: debouncedFetchOptions } = useDebounceFn(fetchOptions, { wait: waitTime || 500 });
	useEffect(() => {
		fetchOptions();
	}, [options]);
	return /* @__PURE__ */ React.createElement(Select, _objectSpread2(_objectSpread2({}, others), {}, {
		options: resolvedOptions,
		bordered,
		onSearch: debouncedFetchOptions,
		ref,
		value,
		onChange,
		style,
		onBlur,
		onClick: (e) => e.stopPropagation()
	}));
};
var Edit_default = forwardRef(Edit);
//#endregion
export { Edit_default as default };
