import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { getPisellComponentsThemeConfig } from "../../theme/pisell-components.js";
import EditView from "./components/EditView.js";
import DisabledView from "./components/DisabledView.js";
import ReadOnlyView from "./components/ReadOnlyView.js";
import React, { forwardRef, useImperativeHandle, useRef } from "react";
import { useSelectState } from "@pisell/utils";
import { ConfigProvider } from "antd";
import "./PisellSingleSelect.less";
//#region src/components/pisellSingleSelect/PisellSingleSelect.tsx
/**
* PisellSingleSelect - 单选下拉组件
* 基于 Ant Design Select 封装，提供符合 Pisell 设计规范的单选功能
*/
const PisellSingleSelect = forwardRef((props, ref) => {
	const { value, defaultValue, onChange, disabled, readOnly } = props;
	const selectRef = useRef(null);
	const state = useSelectState({
		value,
		defaultValue,
		onChange,
		mode: "single"
	});
	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: () => {
			var _state$value;
			return (_state$value = state.value) !== null && _state$value !== void 0 ? _state$value : null;
		},
		setValue: (newValue) => state.setValue(newValue),
		clearValue: () => state.clearValue()
	}));
	const theme = getPisellComponentsThemeConfig();
	if (disabled) return /* @__PURE__ */ React.createElement(ConfigProvider, { theme }, /* @__PURE__ */ React.createElement(DisabledView, _objectSpread2(_objectSpread2({}, props), {}, { ref: selectRef })));
	if (readOnly) return /* @__PURE__ */ React.createElement(ConfigProvider, { theme }, /* @__PURE__ */ React.createElement(ReadOnlyView, props));
	return /* @__PURE__ */ React.createElement(ConfigProvider, { theme }, /* @__PURE__ */ React.createElement(EditView, _objectSpread2(_objectSpread2({}, props), {}, {
		state,
		ref: selectRef
	})));
});
PisellSingleSelect.displayName = "PisellSingleSelect";
//#endregion
export { PisellSingleSelect as default };
