"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 AdaptableFormControlTextClear_1 = require("../Components/Forms/AdaptableFormControlTextClear");
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 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.onSetStyle(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(AdaptableFormControlTextClear_1.AdaptableFormControlTextClear, { "data-name": "quick-search-text", type: "text", marginLeft: 2, marginRight: 5, padding: 20, style: { height: '100%' }, placeholder: props.api.optionsApi.getQuickSearchOptions().quickSearchPlaceholder, value: searchText, OnTextChange: search }))),
        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(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%' }, api: props.api, Style: props.QuickSearchStyle, UpdateStyle: onUpdateStyle })));
};
function mapStateToProps(state, ownProps) {
    return {
        QuickSearchText: state.QuickSearch.QuickSearchText,
        QuickSearchStyle: state.QuickSearch.Style,
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onRunQuickSearch: (quickSearchText) => dispatch(QuickSearchRedux.QuickSearchRun(quickSearchText)),
        onSetStyle: (style) => dispatch(QuickSearchRedux.QuickSearchSetStyle(style)),
    };
}
exports.QuickSearchPopup = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(QuickSearchPopupComponent);
