"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CalculatedColumnSummary = exports.CalculatedColumnSummaryComponent = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_redux_1 = require("react-redux");
const Helper_1 = require("../../Utilities/Helpers/Helper");
const CalculatedColumnRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/CalculatedColumnRedux"));
const EditableConfigEntityState_1 = require("../Components/SharedProps/EditableConfigEntityState");
const UIHelper_1 = require("../UIHelper");
const ModuleDetail_1 = require("../Components/ModuleSummary/ModuleDetail");
const CalculatedColumnWizard_1 = require("./Wizard/CalculatedColumnWizard");
class CalculatedColumnSummaryComponent extends React.Component {
    constructor(props) {
        super(props);
        this.onFinishWizard = (calculatedColumn) => {
            this.props.onEdit(calculatedColumn);
            this.setState({
                editedAdaptableObject: null,
                wizardStartIndex: 0,
                wizardStatus: EditableConfigEntityState_1.WizardStatus.None,
            });
        };
        this.state = UIHelper_1.UIHelper.getEmptyConfigState();
    }
    render() {
        let detailRow;
        this.props.CalculatedColumns.map((item, index) => {
            if (item.ColumnId == this.props.summarisedColumn.columnId) {
                detailRow = (React.createElement(ModuleDetail_1.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_1.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_1.Helper.cloneObject(calculatedColumn),
            wizardStartIndex: 0,
            wizardStatus: EditableConfigEntityState_1.WizardStatus.Edit,
        });
    }
    onCloseWizard() {
        this.setState({
            editedAdaptableObject: null,
            wizardStartIndex: 0,
            wizardStatus: EditableConfigEntityState_1.WizardStatus.None,
        });
    }
}
exports.CalculatedColumnSummaryComponent = CalculatedColumnSummaryComponent;
function mapStateToProps(state) {
    return {
        CalculatedColumns: state.CalculatedColumn.CalculatedColumns,
    };
}
function mapDispatchToProps(dispatch) {
    return {
        onEdit: (calculatedColumn) => dispatch(CalculatedColumnRedux.CalculatedColumnEdit(calculatedColumn)),
    };
}
exports.CalculatedColumnSummary = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(CalculatedColumnSummaryComponent);
