import * as React from 'react';
import { connect } from 'react-redux';
import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants';
import * as PopupRedux from '../../Redux/ActionsReducers/PopupRedux';
import * as TeamSharingRedux from '../../Redux/ActionsReducers/TeamSharingRedux';
import * as LayoutRedux from '../../Redux/ActionsReducers/LayoutRedux';
import { SummaryRowItem } from '../Components/ModuleSummary/SummaryRowItem';
import { ModuleProfile } from '../Components/ModuleProfile';
import { ButtonClear } from '../Components/Buttons/ButtonClear';
import { UIHelper } from '../UIHelper';
import { getColumnFiltersSelector } from '../../Redux/ActionsReducers/LayoutRedux';
export class FilterSummaryComponent extends React.Component {
    constructor(props) {
        super(props);
        this.state = 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, { moduleInfo: this.props.moduleInfo })));
        summaryItems.push(description);
        summaryItems.push(React.createElement(ButtonClear, { marginLeft: 1, onClick: () => this.props.onClearFilter(columnFilter), tooltip: "Clear Filter", disabled: columnFilter == null, accessLevel: this.props.accessLevel }));
        return React.createElement(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);
    }
}
function mapStateToProps(state) {
    return {
        ColumnFilters: 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)),
    };
}
export let FilterSummary = connect(mapStateToProps, mapDispatchToProps)(FilterSummaryComponent);
