import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import * as QuickSearchRedux from '../../Redux/ActionsReducers/QuickSearchRedux';
import { AdaptableFormControlTextClear } from '../Components/Forms/AdaptableFormControlTextClear';
import { useQuickSearchDebounced } from './useQuickSearchDebounced';
import { useAdaptable } from '../AdaptableContext';
import SimpleButton from '../../components/SimpleButton';
import join from '../../components/utils/join';
import { Box } from 'rebass';
export const QuickSearchInput = (props) => {
    const adaptable = useAdaptable();
    const QuickSearchText = useSelector((state) => state.QuickSearch.QuickSearchText);
    const dispatch = useDispatch();
    const onRunQuickSearch = React.useCallback((newQuickSearchText) => dispatch(QuickSearchRedux.QuickSearchRun(newQuickSearchText)), []);
    const [searchText, search] = useQuickSearchDebounced({
        QuickSearchText,
        onRunQuickSearch,
    });
    return (React.createElement(AdaptableFormControlTextClear, { "aria-label": 'Quick Search', type: "text", autoFocus: props.autoFocus, placeholder: adaptable.api.optionsApi.getQuickSearchOptions().quickSearchPlaceholder, className: join('ab-DashboardToolbar__QuickSearch__text', props.className), value: searchText, OnTextChange: search, style: { height: '100%' }, inputStyle: { width: props.width ?? '10rem' }, actionTools: React.createElement(Box, { display: "flex", flexDirection: "row", alignItems: "center", flex: 'none' },
            React.createElement(SimpleButton, { "aria-label": 'Previous Match', icon: "arrow-up", px: 0, py: 0, mr: 1, disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoPreviousMatch() }),
            React.createElement(SimpleButton, { "aria-label": 'Next Match', icon: "arrow-down", px: 0, py: 0, mr: 1, disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoNextMatch() })) }));
};
