"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickSearchInput = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_redux_1 = require("react-redux");
const QuickSearchRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/QuickSearchRedux"));
const AdaptableFormControlTextClear_1 = require("../Components/Forms/AdaptableFormControlTextClear");
const useQuickSearchDebounced_1 = require("./useQuickSearchDebounced");
const AdaptableContext_1 = require("../AdaptableContext");
const SimpleButton_1 = tslib_1.__importDefault(require("../../components/SimpleButton"));
const join_1 = tslib_1.__importDefault(require("../../components/utils/join"));
const rebass_1 = require("rebass");
const QuickSearchInput = (props) => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const QuickSearchText = (0, react_redux_1.useSelector)((state) => state.QuickSearch.QuickSearchText);
    const dispatch = (0, react_redux_1.useDispatch)();
    const onRunQuickSearch = react_1.default.useCallback((newQuickSearchText) => dispatch(QuickSearchRedux.QuickSearchRun(newQuickSearchText)), []);
    const isServerSideRowModel = adaptable.api.gridApi.getAgGridRowModelType() === 'serverSide';
    const [searchText, search] = (0, useQuickSearchDebounced_1.useQuickSearchDebounced)({
        QuickSearchText,
        onRunQuickSearch,
    });
    return (react_1.default.createElement(AdaptableFormControlTextClear_1.AdaptableFormControlTextClear, { "aria-label": 'Quick Search', type: "text", autoFocus: props.autoFocus, placeholder: adaptable.api.optionsApi.getQuickSearchOptions().quickSearchPlaceholder, className: (0, join_1.default)('ab-DashboardToolbar__QuickSearch__text', props.className), value: searchText, OnTextChange: search, style: { height: '100%' }, inputStyle: { width: props.width ?? '10rem' }, actionTools: isServerSideRowModel ? null : (react_1.default.createElement(rebass_1.Box, { display: "flex", flexDirection: "row", alignItems: "center", flex: 'none' },
            react_1.default.createElement(SimpleButton_1.default, { "aria-label": 'Previous Match', icon: "arrow-up", px: 0, py: 0, mr: 1, disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoPreviousMatch() }),
            react_1.default.createElement(SimpleButton_1.default, { "aria-label": 'Next Match', icon: "arrow-down", px: 0, py: 0, mr: 1, disabled: !searchText, variant: "text", onClick: () => adaptable.api.quickSearchApi.gotoNextMatch() }))) }));
};
exports.QuickSearchInput = QuickSearchInput;
