"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterSummary = exports.FilterSummaryComponent = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
const PopupRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/PopupRedux"));
const TeamSharingRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/TeamSharingRedux"));
const LayoutRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/LayoutRedux"));
const SummaryRowItem_1 = require("../Components/ModuleSummary/SummaryRowItem");
const ModuleProfile_1 = require("../Components/ModuleProfile");
const ButtonClear_1 = require("../Components/Buttons/ButtonClear");
const UIHelper_1 = require("../UIHelper");
const LayoutRedux_1 = require("../../Redux/ActionsReducers/LayoutRedux");
class FilterSummaryComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = UIHelper_1.UIHelper.getEmptyConfigState();
    }
    render() {
        let columnFilter = this.props.ColumnFilters.find((c) => c.ColumnId == this.props.summarisedColumn.columnId);
        let description = this.getDescription(columnFilter);
        let summaryItems = [];
        summaryItems.push(React.createElement("b", null, React.createElement(ModuleProfile_1.ModuleProfile, { moduleInfo: this.props.moduleInfo })));
        summaryItems.push(description);
        summaryItems.push(React.createElement(ButtonClear_1.ButtonClear, { marginLeft: 1, onClick: () => this.props.onClearFilter(columnFilter), tooltip: "Clear Filter", disabled: columnFilter == null, accessLevel: this.props.accessLevel }));
        return React.createElement(SummaryRowItem_1.SummaryRowItem, { SummaryItems: summaryItems });
    }
    getDescription(columnFilter) {
        if (this.props.summarisedColumn && !this.props.summarisedColumn.filterable) {
            return 'Column is not filterable';
        }
        if (columnFilter == null) {
            return 'No Column Filter Active';
        }
        return this.props.api.filterApi.columnFilterApi.columnFilterToString(columnFilter);
    }
}
exports.FilterSummaryComponent = FilterSummaryComponent;
function mapStateToProps(state) {
    return {
        ColumnFilters: (0, LayoutRedux_1.getColumnFiltersSelector)(state),
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onClearFilter: (columnFilter) => dispatch(LayoutRedux.LayoutColumnFilterClear(columnFilter.ColumnId)),
        onClearPopupParams: () => dispatch(PopupRedux.PopupClearParam()),
        onShare: (entity, config) => dispatch(TeamSharingRedux.TeamSharingShare(entity, ModuleConstants.ColumnFilterModuleId, config)),
    };
}
exports.FilterSummary = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(FilterSummaryComponent);
