"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 Flex_1 = require("../../components/Flex");
const twMerge_1 = require("../../twMerge");
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, { onClick: props.onClick, "aria-label": 'Quick Search', type: "text", autoFocus: props.autoFocus, placeholder: adaptable.api.optionsApi.getQuickSearchOptions().quickSearchPlaceholder, className: (0, twMerge_1.twMerge)('ab-QuickSearch__control twa:h-full twa:min-h-input', props.className), value: searchText, OnTextChange: search, inputClassName: (0, twMerge_1.twMerge)('twa:w-[10rem]', props.inputClassName), actionTools: isServerSideRowModel ? null : (react_1.default.createElement(Flex_1.Flex, { flexDirection: "row", alignItems: "center", className: "twa:flex-none" },
            react_1.default.createElement(SimpleButton_1.default, { "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_1.default.createElement(SimpleButton_1.default, { "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() }))) }));
};
exports.QuickSearchInput = QuickSearchInput;
