var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import ConfigProvider from '../config-provider';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import cls from 'classnames';
import { Search as NextSearch } from '@alifd/next';
import { getTheme } from '../utils/getTheme';
class Search extends Component {
    constructor(props) {
        super(props);
        this.onFocus = e => {
            this.setState({
                focus: true,
            });
            const { onFocus } = this.props;
            onFocus && onFocus(e);
        };
        this.onBlur = e => {
            this.setState({
                focus: false,
            });
            const { onBlur } = this.props;
            onBlur && onBlur(e);
        };
        this.state = {
            focus: false,
        };
    }
    render() {
        const _a = this.props, { prefix = 'next-', size = 'medium', type = 'normal', shape, popupClassName } = _a, otherProps = __rest(_a, ["prefix", "size", "type", "shape", "popupClassName"]);
        const theme = getTheme(this.context, this.props);
        return React.createElement(NextSearch, Object.assign({ size: size }, otherProps, { className: cls(this.props.className, {
                [`${prefix}search-normal`]: shape === 'simple',
                [`${prefix}contain-focus`]: this.state.focus === true,
                [`${prefix}small`]: size === 'small',
                [`${prefix}xs`]: size === 'xs',
                [`${prefix}grey`]: theme === 'grey',
                [`${prefix}white`]: theme === 'white',
                [`${prefix}brand`]: type === 'brand',
                [`${prefix}search-with-no-title`]: !this.props.searchText,
            }), popupClassName: cls(popupClassName, {
                [`${prefix}white`]: theme === 'white',
                [`${prefix}grey`]: theme === 'grey',
            }), filterProps: { popupClassName: cls(popupClassName, {
                    [`${prefix}white`]: theme === 'white',
                    [`${prefix}grey`]: theme === 'grey',
                }) }, onBlur: this.onBlur, onFocus: this.onFocus }));
    }
}
// contextTypes
Search.contextTypes = {
    theme: PropTypes.string,
};
export default ConfigProvider.config(Search);
