'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _omit = require('omit.js');

var _omit2 = _interopRequireDefault(_omit);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _rcSelect = require('rc-select');

var _rcSelect2 = _interopRequireDefault(_rcSelect);

var _context = require('antd/lib/config-provider/context');

var _iconUtil = require('./utils/iconUtil');

var _iconUtil2 = _interopRequireDefault(_iconUtil);

var _SizeContext = require('../config-provider/SizeContext');

var _SizeContext2 = _interopRequireDefault(_SizeContext);

require('@whalecloud/fdx-theme-fdx/select');

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

// We still use class here since `forwardRef` not support generic in typescript
// TODO: 4.0 - codemod should help to change `filterOption` to support node props.
var Select = function (_React$Component) {
    (0, _inherits3['default'])(Select, _React$Component);

    function Select() {
        (0, _classCallCheck3['default'])(this, Select);

        var _this = (0, _possibleConstructorReturn3['default'])(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 = (0, _iconUtil2['default'])((0, _extends3['default'])((0, _extends3['default'])({}, _this.props), { multiple: isMultiple, prefixCls: prefixCls })),
                suffixIcon = _getIcons.suffixIcon,
                menuItemSelectedIcon = _getIcons.menuItemSelectedIcon,
                removeIcon = _getIcons.removeIcon,
                clearIcon = _getIcons.clearIcon;

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

                    var mergedSize = customizeSize || size;
                    var mergedClassName = (0, _classnames2['default'])((_classNames = {}, (0, _defineProperty3['default'])(_classNames, prefixCls + '-lg', mergedSize === 'large'), (0, _defineProperty3['default'])(_classNames, prefixCls + '-sm', mergedSize === 'small'), (0, _defineProperty3['default'])(_classNames, prefixCls + '-borderless', !bordered), _classNames), className);
                    return React.createElement(_rcSelect2['default'], (0, _extends3['default'])({ 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;
    }

    (0, _createClass3['default'])(Select, [{
        key: 'render',
        value: function render() {
            return React.createElement(
                _context.ConfigConsumer,
                null,
                this.renderSelect
            );
        }
    }]);
    return Select;
}(React.Component);

Select.Option = _rcSelect.Option;
Select.OptGroup = _rcSelect.OptGroup;
Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
Select.defaultProps = {
    transitionName: 'slide-up',
    choiceTransitionName: '',
    bordered: true
};
exports['default'] = Select;
module.exports = exports['default'];