function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/**
 * PisellSingleSelect - 单选下拉组件
 * 基于 Ant Design Select 封装，提供符合 Pisell 设计规范的单选功能
 */

import React, { forwardRef, useRef, useImperativeHandle } from 'react';
import { useSelectState } from '@pisell/utils';
import EditView from "./components/EditView";
import DisabledView from "./components/DisabledView";
import ReadOnlyView from "./components/ReadOnlyView";
import "./PisellSingleSelect.less";
var PisellSingleSelect = /*#__PURE__*/forwardRef(function (props, ref) {
  var value = props.value,
    defaultValue = props.defaultValue,
    onChange = props.onChange,
    disabled = props.disabled,
    readOnly = props.readOnly;

  // Select 内部 ref
  var selectRef = useRef(null);

  // 状态管理（从 @pisell/utils 导入）
  var state = useSelectState({
    value: value,
    defaultValue: defaultValue,
    onChange: onChange,
    mode: 'single'
  });

  // 暴露 Ref 方法
  useImperativeHandle(ref, function () {
    return {
      focus: function focus() {
        var _selectRef$current;
        return (_selectRef$current = selectRef.current) === null || _selectRef$current === void 0 ? void 0 : _selectRef$current.focus();
      },
      blur: function blur() {
        var _selectRef$current2;
        return (_selectRef$current2 = selectRef.current) === null || _selectRef$current2 === void 0 ? void 0 : _selectRef$current2.blur();
      },
      getValue: function getValue() {
        var _state$value;
        return (_state$value = state.value) !== null && _state$value !== void 0 ? _state$value : null;
      },
      setValue: function setValue(newValue) {
        return state.setValue(newValue);
      },
      clearValue: function clearValue() {
        return state.clearValue();
      }
    };
  });

  // 根据不同状态渲染不同视图
  if (disabled) {
    return /*#__PURE__*/React.createElement(DisabledView, _extends({}, props, {
      ref: selectRef
    }));
  }
  if (readOnly) {
    return /*#__PURE__*/React.createElement(ReadOnlyView, props);
  }
  return /*#__PURE__*/React.createElement(EditView, _extends({}, props, {
    state: state,
    ref: selectRef
  }));
});
PisellSingleSelect.displayName = 'PisellSingleSelect';
export default PisellSingleSelect;