import React, { Component } from 'react';
import classNames from 'classnames';
// @ts-ignore
import { SoftFieldSearch } from '../../Form';
import { getMatchingOptions } from '../matching_options';
export class SoftSelectableSearch extends Component {
    constructor(props) {
        super(props);
        this.state = {
            searchValue: null
        };
        this.onSearchChange = (value) => {
            this.setState({ searchValue: value });
            const { options } = this.props;
            const matchingOptions = getMatchingOptions(options, value);
            this.passUpMatches(matchingOptions, value);
        };
        this.passUpMatches = (matches, searchValue) => {
            if (this.props.onChange) {
                this.props.onChange(matches, searchValue);
            }
        };
        this.state = {
            searchValue: props.defaultValue,
        };
    }
    componentDidMount() {
        const { options } = this.props;
        const { searchValue } = this.state;
        const matchingOptions = getMatchingOptions(options, searchValue);
        this.passUpMatches(matchingOptions, searchValue);
    }
    render() {
        const { className, onChange, options, defaultValue, ...rest } = this.props;
        const classes = classNames('softSelectableSearch', className);
        return (React.createElement(SoftFieldSearch, Object.assign({ className: classes, placeholder: "Filter options", onSearch: this.onSearchChange, incremental: true, defaultValue: defaultValue, fullWidth: true }, rest)));
    }
}
SoftSelectableSearch.defaultProps = {
    defaultValue: '',
};
//# sourceMappingURL=SoftSelectableSearch.js.map