import * as React from 'react';
import { connect } from 'react-redux';
import { Helper } from '../../Utilities/Helpers/Helper';
import * as CalculatedColumnRedux from '../../Redux/ActionsReducers/CalculatedColumnRedux';
import { WizardStatus, } from '../Components/SharedProps/EditableConfigEntityState';
import { UIHelper } from '../UIHelper';
import { ModuleDetail } from '../Components/ModuleSummary/ModuleDetail';
import { CalculatedColumnWizard } from './Wizard/CalculatedColumnWizard';
export class CalculatedColumnSummaryComponent extends React.Component {
    constructor(props) {
        super(props);
        this.onFinishWizard = (calculatedColumn) => {
            this.props.onEdit(calculatedColumn);
            this.setState({
                editedAdaptableObject: null,
                wizardStartIndex: 0,
                wizardStatus: WizardStatus.None,
            });
        };
        this.state = UIHelper.getEmptyConfigState();
    }
    render() {
        let detailRow;
        this.props.CalculatedColumns.map((item, index) => {
            if (item.ColumnId == this.props.summarisedColumn.columnId) {
                detailRow = (React.createElement(ModuleDetail, { key: 'UF' + index, item1: this.props.moduleInfo.FriendlyName, item2: this.props.api.internalApi.getAdaptableQueryExpressionText(item.Query), configEnity: item, showShare: this.props.teamSharingActivated, moduleInfo: this.props.moduleInfo, onEdit: () => this.onEdit(item), onShare: (config) => this.props.onShare(item, config), onDelete: CalculatedColumnRedux.CalculatedColumnDelete(item), showBold: true, accessLevel: this.props.accessLevel }));
            }
        });
        return (React.createElement("div", null,
            detailRow,
            this.state.editedAdaptableObject && (React.createElement(CalculatedColumnWizard, { moduleInfo: this.props.moduleInfo, data: this.state.editedAdaptableObject, configEntities: this.props.CalculatedColumns, onCloseWizard: () => this.onCloseWizard(), onFinishWizard: this.onFinishWizard }))));
    }
    onEdit(calculatedColumn) {
        this.setState({
            editedAdaptableObject: Helper.cloneObject(calculatedColumn),
            wizardStartIndex: 0,
            wizardStatus: WizardStatus.Edit,
        });
    }
    onCloseWizard() {
        this.setState({
            editedAdaptableObject: null,
            wizardStartIndex: 0,
            wizardStatus: WizardStatus.None,
        });
    }
}
function mapStateToProps(state) {
    return {
        CalculatedColumns: state.CalculatedColumn.CalculatedColumns,
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onEdit: (calculatedColumn) => dispatch(CalculatedColumnRedux.CalculatedColumnEdit(calculatedColumn)),
    };
}
export let CalculatedColumnSummary = connect(mapStateToProps, mapDispatchToProps)(CalculatedColumnSummaryComponent);
