const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_pisell_components = require("../../theme/pisell-components.js");
const require_EditView = require("./components/EditView.js");
const require_DisabledView = require("./components/DisabledView.js");
const require_ReadOnlyView = require("./components/ReadOnlyView.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let antd = require("antd");
require("./PisellMultipleSelect.less");
//#region src/components/pisellMultipleSelect/PisellMultipleSelect.tsx
/**
* PisellMultipleSelect - 多选下拉组件
* 基于 Ant Design Select 封装，提供符合 Pisell 设计规范的多选功能
*/
const PisellMultipleSelect = (0, react.forwardRef)((props, ref) => {
	const { value, defaultValue, onChange, options, disabled, readOnly, maxCount } = props;
	const selectRef = (0, react.useRef)(null);
	const state = (0, _pisell_utils.useMultipleSelectState)({
		value,
		defaultValue,
		onChange,
		mode: "multiple"
	});
	const handleChange = (0, react.useCallback)((newValue) => {
		if (maxCount && newValue.length > maxCount) {
			antd.message.warning(`最多只能选择 ${maxCount} 项`);
			return;
		}
		const selectedOptions = newValue.map((v) => options.find((opt) => opt.value === v)).filter(Boolean);
		state.setValue(newValue);
		onChange === null || onChange === void 0 || onChange(newValue, selectedOptions);
	}, [
		maxCount,
		onChange,
		options,
		state
	]);
	(0, react.useImperativeHandle)(ref, () => ({
		focus: () => {
			var _selectRef$current;
			return (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.focus();
		},
		blur: () => {
			var _selectRef$current2;
			return (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 ? void 0 : _selectRef$current2.blur();
		},
		getValue: () => state.value,
		setValue: (newValue) => state.setValue(newValue),
		clearValue: () => state.clearValue(),
		addValue: (val) => state.addValue(val),
		removeValue: (val) => state.removeValue(val)
	}));
	const theme = require_pisell_components.getPisellComponentsThemeConfig();
	if (disabled) return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme }, /* @__PURE__ */ react.default.createElement(require_DisabledView.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { ref: selectRef })));
	if (readOnly) return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme }, /* @__PURE__ */ react.default.createElement(require_ReadOnlyView.default, props));
	return /* @__PURE__ */ react.default.createElement(antd.ConfigProvider, { theme }, /* @__PURE__ */ react.default.createElement(require_EditView.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, {
		value: state.value,
		state,
		onChangeInternal: handleChange,
		ref: selectRef
	})));
});
PisellMultipleSelect.displayName = "PisellMultipleSelect";
//#endregion
exports.default = PisellMultipleSelect;
