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 { Flex } from '../../components/Flex';
import { twMerge } from '../../twMerge';
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 isServerSideRowModel = adaptable.api.gridApi.getAgGridRowModelType() === 'serverSide';
    const [searchText, search] = useQuickSearchDebounced({
        QuickSearchText,
        onRunQuickSearch,
    });
    return (React.createElement(AdaptableFormControlTextClear, { onClick: props.onClick, "aria-label": 'Quick Search', type: "text", autoFocus: props.autoFocus, placeholder: adaptable.api.optionsApi.getQuickSearchOptions().quickSearchPlaceholder, className: twMerge('ab-QuickSearch__control twa:h-full', props.className), value: searchText, OnTextChange: search, inputClassName: twMerge('twa:w-[10rem]', props.inputClassName), actionTools: isServerSideRowModel ? null : (React.createElement(Flex, { flexDirection: "row", alignItems: "center", className: "twa:flex-none" },
            React.createElement(SimpleButton, { "aria-label": 'Previous Match', icon: "arrow-up", className: "twa:px-0 twa:py-0 twa:mr-1", disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoPreviousMatch() }),
            React.createElement(SimpleButton, { "aria-label": 'Next Match', icon: "arrow-down", className: "twa:px-0 twa:py-0 twa:mr-1", disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoNextMatch() }))) }));
};
