const require_runtime = require("../../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
require("./index.less");
//#region src/components/booking/info2/service/editService/Capacity/index.tsx
const getName = (name, locale) => {
	return name[locale] || name["original"] || name["en"] || "";
};
const getSelectOptions = (min, max) => {
	let arr = [];
	for (let i = min; i <= max; i++) arr.push({
		label: `${i}`,
		value: i
	});
	return arr;
};
const Capacity = ({ state, cacheItem, value, onChange }, ref) => {
	var _cacheItem$_data;
	const data = cacheItem === null || cacheItem === void 0 || (_cacheItem$_data = cacheItem._data) === null || _cacheItem$_data === void 0 ? void 0 : _cacheItem$_data.capacitys;
	const _value = (0, react.useMemo)(() => {
		return value || [];
	}, [value]);
	const _onChange = (val, index) => {
		let _val = [..._value];
		_val = _val.map((item) => {
			if (item.id === index) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { value: val });
			return item;
		});
		console.log(_val);
		onChange === null || onChange === void 0 || onChange(_val);
	};
	if ((data === null || data === void 0 ? void 0 : data.type) !== "custom") return null;
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, data.custom.map((item) => {
		var _value$find;
		return /* @__PURE__ */ react.default.createElement(antd.Col, {
			span: 24,
			key: item.id
		}, /* @__PURE__ */ react.default.createElement(antd.Form.Item, {
			label: getName(item.name, state.locale),
			required: true
		}, /* @__PURE__ */ react.default.createElement(antd.Select, {
			size: "large",
			className: "capacity-select",
			onChange: (e) => {
				_onChange(e, item.id);
			},
			showSearch: !state.isTerminal,
			value: (_value$find = _value.find((d) => d.id === item.id)) === null || _value$find === void 0 ? void 0 : _value$find.value,
			options: getSelectOptions(item.min, item.max),
			onSearch: (e) => {
				if (!e) return;
				const num = Number(e);
				if (isNaN(num)) return;
				if (num >= item.min && num <= item.max) _onChange(num, item.id);
			}
		})));
	}));
};
var Capacity_default = (0, react.forwardRef)(Capacity);
//#endregion
exports.default = Capacity_default;
