"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterViewPanelControl = void 0;
const tslib_1 = require("tslib");
const InternalRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/InternalRedux"));
const React = tslib_1.__importStar(require("react"));
const ActiveFiltersPanel_1 = require("./ActiveFiltersPanel");
const ArrayExtensions_1 = require("../../Utilities/Extensions/ArrayExtensions");
const AdaptablePopover_1 = require("../AdaptablePopover");
const ButtonClear_1 = require("../Components/Buttons/ButtonClear");
const CheckBox_1 = require("../../components/CheckBox");
const react_redux_1 = require("react-redux");
const LayoutRedux_1 = require("../../Redux/ActionsReducers/LayoutRedux");
const SimpleButton_1 = tslib_1.__importDefault(require("../../components/SimpleButton"));
const join_1 = tslib_1.__importDefault(require("../../components/utils/join"));
const Flex_1 = require("../../components/Flex");
class FilterViewPanelComponent extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        const elementType = this.props.viewType === 'Toolbar' ? 'DashboardToolbar' : 'ToolPanel';
        const isAtLeastOneFilterActive = this.props.api.filterApi.columnFilterApi.getActiveColumnFilters().length > 0;
        const isAtLeastOneFilter = this.props.api.filterApi.columnFilterApi.getColumnFilters().length > 0;
        const handleSuspendUnsuspendAll = () => {
            if (isAtLeastOneFilterActive) {
                this.props.api.filterApi.columnFilterApi.suspendAllColumnFilters();
            }
            else {
                this.props.api.filterApi.columnFilterApi.unSuspendAllColumnFilters();
            }
        };
        return (React.createElement(Flex_1.Flex, { flexDirection: "row", className: `ab-${elementType}__Filter__wrap`, flexWrap: this.props.viewType === 'ToolPanel' ? 'wrap' : 'nowrap' },
            React.createElement(Flex_1.Flex, null,
                ArrayExtensions_1.ArrayExtensions.IsNotNullOrEmpty(this.props.ColumnFilters) && (React.createElement(AdaptablePopover_1.AdaptablePopover, { popupPadding: 0, className: `ab-${elementType}__Filter__info`, headerText: "", bodyText: [React.createElement(ActiveFiltersPanel_1.ActiveFiltersPanel, null)], useButton: true, showEvent: 'focus', hideEvent: "blur", popoverMinWidth: 400 })),
                React.createElement(ButtonClear_1.ButtonClear, { "aria-label": 'Clear Filters', className: `ab-${elementType}__Filter__clear twa:mx-1 twa:mb-0`, onClick: () => this.onClearFilters(), tooltip: "Clear Filters", disabled: this.props.ColumnFilters.length == 0, showText: this.props.viewType === 'ToolPanel' }, this.props.viewType === 'ToolPanel' && 'Clear'),
                React.createElement(SimpleButton_1.default, { "aria-label": isAtLeastOneFilterActive ? 'Suspend All Filters' : 'Resume All Filters', className: (0, join_1.default)(`ab-${elementType}__Filter__suspend-button`, isAtLeastOneFilterActive && `ab-${elementType}__Filter__suspend-all`, !isAtLeastOneFilterActive && `ab-${elementType}__Filter__un-suspend-all`), disabled: !isAtLeastOneFilter, onClick: handleSuspendUnsuspendAll, tone: isAtLeastOneFilterActive ? 'neutral' : 'success', variant: "text", icon: isAtLeastOneFilterActive ? 'pause' : 'play', accessLevel: this.props.accessLevel })),
            React.createElement(Flex_1.Flex, { alignItems: "center" }, this.props.api.filterApi.columnFilterApi.isQuickFilterAvailable() && (React.createElement(CheckBox_1.CheckBox, { "data-name": "quick-filter-toggle", className: `ab-${elementType}__Filter__active-check twa:my-0 twa:text-2 twa:p-1`, disabled: this.props.accessLevel === 'ReadOnly' ||
                    this.props.api.layoutApi.isCurrentLayoutPivot(), checked: this.props.IsQuickFilterVisible, onChange: (checked) => {
                    checked ? this.props.onShowQuickFilterBar() : this.props.onHideQuickFilterBar();
                } }, "Filter Bar")))));
    }
    onClearFilters() {
        this.props.api.filterApi.columnFilterApi.clearColumnFilters();
    }
}
function mapStateToProps(state) {
    return {
        ColumnFilters: (0, LayoutRedux_1.getColumnFiltersSelector)(state),
        IsQuickFilterVisible: state.Internal.IsQuickFilterVisible,
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onHideQuickFilterBar: () => dispatch(InternalRedux.QuickFilterBarHide()),
        onShowQuickFilterBar: () => dispatch(InternalRedux.QuickFilterBarShow()),
    };
}
exports.FilterViewPanelControl = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(FilterViewPanelComponent);
