"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickSearchPopup = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_1 = require("react");
const react_redux_1 = require("react-redux");
const QuickSearchRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/QuickSearchRedux"));
const PopupPanel_1 = require("../Components/Popups/AdaptablePopup/PopupPanel");
const Panel_1 = tslib_1.__importDefault(require("../../components/Panel"));
const FormLayout_1 = tslib_1.__importStar(require("../../components/FormLayout"));
const StyleComponent_1 = require("../Components/StyleComponent");
const rebass_1 = require("rebass");
const CheckBox_1 = require("../../components/CheckBox");
const StringExtensions_1 = tslib_1.__importDefault(require("../../Utilities/Extensions/StringExtensions"));
const useQuickSearchDebounced_1 = require("./useQuickSearchDebounced");
const QuickSearchInput_1 = require("./QuickSearchInput");
const HelpBlock_1 = tslib_1.__importDefault(require("../../components/HelpBlock"));
const QuickSearchPopupComponent = (props) => {
    const [searchText, search] = (0, useQuickSearchDebounced_1.useQuickSearchDebounced)(props);
    const [state, setState] = (0, react_1.useState)({
        RunQueryAfterQuickSearch: props.api.optionsApi.getQuickSearchOptions().filterGridAfterQuickSearch,
        EditedStyle: props.QuickSearchStyle,
    });
    const onUpdateStyle = (style) => {
        setState({ ...state, EditedStyle: style });
        props.onSetMatchingCellStyle(style);
    };
    const onQuickSearchBehaviourChange = (checked) => {
        setState({ ...state, RunQueryAfterQuickSearch: checked });
        props.api.optionsApi.getAdaptableOptions().quickSearchOptions.filterGridAfterQuickSearch =
            checked;
    };
    return (React.createElement(PopupPanel_1.PopupPanel, { headerText: props.moduleInfo.FriendlyName, glyphicon: props.moduleInfo.Glyph, infoLink: props.moduleInfo.HelpPage, infoLinkDisabled: !props.api.internalApi.isDocumentationLinksDisplayed() },
        React.createElement(Panel_1.default, { header: props.moduleInfo.FriendlyName + ' Text', style: { height: 'auto' }, variant: "default", borderRadius: "none", marginTop: 3, marginLeft: 2, marginRight: 2 },
            React.createElement(FormLayout_1.default, null,
                React.createElement(QuickSearchInput_1.QuickSearchInput, null))),
        React.createElement(Panel_1.default, { header: props.api.internalApi.getCorrectEnglishVariant('Behaviour'), style: { height: 'auto' }, variant: "default", borderRadius: "none", marginTop: 3, marginLeft: 2, marginRight: 2 },
            ' ',
            React.createElement(rebass_1.Flex, { flexDirection: "column" },
                React.createElement(HelpBlock_1.default, { fontSize: 2, marginTop: 2, marginBottom: 2 }, "Filters the Grid to only show rows with matching cells; use with care as can cause performance issues"),
                ' ',
                React.createElement(FormLayout_1.default, { columns: [1, 2] },
                    React.createElement(FormLayout_1.FormRow, null,
                        React.createElement(CheckBox_1.CheckBox, { "data-name": "filter-quick-search-results", value: "existing", marginLeft: 1, marginRight: 3, checked: state.RunQueryAfterQuickSearch, disabled: StringExtensions_1.default.IsNotNullOrEmpty(searchText), onChange: onQuickSearchBehaviourChange }, "Filter using Quick Search Results"))))),
        React.createElement(StyleComponent_1.StyleComponent, { style: { height: '100%' }, headerText: 'Cell Matching Style', api: props.api, Style: props.QuickSearchStyle, UpdateStyle: onUpdateStyle })));
};
function mapStateToProps(state, ownProps) {
    return {
        QuickSearchText: state.QuickSearch.QuickSearchText,
        QuickSearchStyle: state.QuickSearch.CellMatchStyle ?? {},
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onRunQuickSearch: (quickSearchText) => dispatch(QuickSearchRedux.QuickSearchRun(quickSearchText)),
        onSetMatchingCellStyle: (style) => dispatch(QuickSearchRedux.QuickSearchSetCellMatchingStyle(style)),
    };
}
exports.QuickSearchPopup = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(QuickSearchPopupComponent);
