import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _extends from 'babel-runtime/helpers/extends';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
// TODO: 4.0 - codemod should help to change `filterOption` to support node props.
import * as React from 'react';
import omit from 'omit.js';
import classNames from 'classnames';
import RcSelect, { Option, OptGroup } from 'rc-select';
import { ConfigConsumer } from 'antd/es/config-provider/context';
import getIcons from './utils/iconUtil';
import SizeContext from '../config-provider/SizeContext';
import "@whalecloud/fdx-theme-fdx/select";
// We still use class here since `forwardRef` not support generic in typescript

var Select = function (_React$Component) {
    _inherits(Select, _React$Component);

    function Select() {
        _classCallCheck(this, Select);

        var _this = _possibleConstructorReturn(this, (Select.__proto__ || Object.getPrototypeOf(Select)).apply(this, arguments));

        _this.selectRef = React.createRef();
        _this.focus = function () {
            if (_this.selectRef.current) {
                _this.selectRef.current.focus();
            }
        };
        _this.blur = function () {
            if (_this.selectRef.current) {
                _this.selectRef.current.blur();
            }
        };
        _this.getMode = function () {
            var mode = _this.props.mode;

            if (mode === 'combobox') {
                return undefined;
            }
            if (mode === Select.SECRET_COMBOBOX_MODE_DO_NOT_USE) {
                return 'combobox';
            }
            return mode;
        };
        _this.renderSelect = function (_ref) {
            var getContextPopupContainer = _ref.getPopupContainer,
                getPrefixCls = _ref.getPrefixCls,
                renderEmpty = _ref.renderEmpty;
            var _this$props = _this.props,
                customizePrefixCls = _this$props.prefixCls,
                notFoundContent = _this$props.notFoundContent,
                className = _this$props.className,
                customizeSize = _this$props.size,
                _this$props$listHeigh = _this$props.listHeight,
                listHeight = _this$props$listHeigh === undefined ? 256 : _this$props$listHeigh,
                _this$props$listItemH = _this$props.listItemHeight,
                listItemHeight = _this$props$listItemH === undefined ? 24 : _this$props$listItemH,
                getPopupContainer = _this$props.getPopupContainer,
                dropdownClassName = _this$props.dropdownClassName,
                bordered = _this$props.bordered,
                _this$props$dropdownM = _this$props.dropdownMatchSelectWidth,
                dropdownMatchSelectWidth = _this$props$dropdownM === undefined ? true : _this$props$dropdownM;

            var prefixCls = getPrefixCls('select', customizePrefixCls);
            var mode = _this.getMode();
            var isMultiple = mode === 'multiple' || mode === 'tags';
            // ===================== Empty =====================
            var mergedNotFound = void 0;
            if (notFoundContent !== undefined) {
                mergedNotFound = notFoundContent;
            } else if (mode === 'combobox') {
                mergedNotFound = null;
            } else {
                mergedNotFound = renderEmpty('Select');
            }
            // ===================== Icons =====================

            var _getIcons = getIcons(_extends(_extends({}, _this.props), { multiple: isMultiple, prefixCls: prefixCls })),
                suffixIcon = _getIcons.suffixIcon,
                menuItemSelectedIcon = _getIcons.menuItemSelectedIcon,
                removeIcon = _getIcons.removeIcon,
                clearIcon = _getIcons.clearIcon;

            var selectProps = omit(_this.props, ['prefixCls', 'suffixIcon', 'menuItemSelectedIcon', 'removeIcon', 'clearIcon', 'size', 'bordered']);
            // const rcSelectRtlDropDownClassName = classNames(dropdownClassName, {
            //   [`${prefixCls}-dropdown-${direction}`]: direction === 'rtl',
            // });
            return React.createElement(
                SizeContext.Consumer,
                null,
                function (size) {
                    var _classNames;

                    var mergedSize = customizeSize || size;
                    var mergedClassName = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls + '-lg', mergedSize === 'large'), _defineProperty(_classNames, prefixCls + '-sm', mergedSize === 'small'), _defineProperty(_classNames, prefixCls + '-borderless', !bordered), _classNames), className);
                    return React.createElement(RcSelect, _extends({ ref: _this.selectRef
                        // virtual={virtual}
                        , dropdownMatchSelectWidth: dropdownMatchSelectWidth }, selectProps, { listHeight: listHeight, listItemHeight: listItemHeight, mode: mode, prefixCls: prefixCls
                        // direction={direction}
                        , inputIcon: suffixIcon, menuItemSelectedIcon: menuItemSelectedIcon, removeIcon: removeIcon, clearIcon: clearIcon, notFoundContent: mergedNotFound, className: mergedClassName, getPopupContainer: getPopupContainer || getContextPopupContainer, dropdownClassName: dropdownClassName }));
                }
            );
        };
        return _this;
    }

    _createClass(Select, [{
        key: 'render',
        value: function render() {
            return React.createElement(
                ConfigConsumer,
                null,
                this.renderSelect
            );
        }
    }]);

    return Select;
}(React.Component);

Select.Option = Option;
Select.OptGroup = OptGroup;
Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
Select.defaultProps = {
    transitionName: 'slide-up',
    choiceTransitionName: '',
    bordered: true
};
export default Select;