"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlertScopeWizardSection = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const NewScopeComponent_1 = require("../../Components/NewScopeComponent");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const Flex_1 = require("../../../components/Flex");
const AlertScopeWizardSection = (props) => {
    const { data, api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    let disableDataTypes = true;
    let disableColumns = true;
    if (props.alertType === 'DataChange' || props.alertType == 'Validation') {
        disableDataTypes = false;
        disableColumns = false;
    }
    return (React.createElement(Flex_1.Flex, { flexDirection: "column", className: "twa:p-2 twa:h-full" },
        React.createElement(NewScopeComponent_1.NewScopeComponent, { disableColumns: disableColumns, disableDataTypes: disableDataTypes, descriptions: {
                rowScope: 'Changes in any Column in the row will trigger an Alert',
                columnScope: 'Changes in selected Columns will trigger an Alert',
                dataTypeScope: 'Changes in any Column which is of the selected Data Type(s) will trigger an Alert',
            }, scope: data.Scope, updateScope: (Scope) => {
                const newData = { ...data, Scope };
                if (newData.Rule.Predicates) {
                    // when scope is changed, reset the rule to predicate of any
                    // if it was set to a predicate before
                    newData.Rule = {
                        Predicates: [{ PredicateId: 'AnyChange' }],
                    };
                }
                if (newData.Rule.ObservableExpression !== undefined &&
                    !api.columnScopeApi.scopeIsAll(Scope)) {
                    // if it had observable expression and the scope is changed to partial
                    // we need to reset to not be an observable expression, as observable is not supported
                    // for partial scope
                    delete newData.Rule.ObservableExpression;
                    newData.Rule.BooleanExpression = '';
                }
                if (newData.Rule.AggregatedBooleanExpression !== undefined &&
                    !api.columnScopeApi.scopeIsAll(Scope)) {
                    // if it had aggregation expression and the scope is changed to partial
                    // we need to reset to not be an aggregation expression, as aggregation is not supported
                    // for partial scope
                    delete newData.Rule.AggregatedBooleanExpression;
                    newData.Rule.BooleanExpression = '';
                }
                props.onChange(newData);
            } })));
};
exports.AlertScopeWizardSection = AlertScopeWizardSection;
