import { EventEmitter } from '@angular/core';
import { delegateCombine } from "igniteui-angular-core";
import { DataSourceSummaryOperand_$type } from "igniteui-angular-core";
import { IgxProvideCalculatorEventArgs } from "igniteui-angular-core";
import { ChartSummaryDescription as ChartSummaryDescription_internal } from "./ChartSummaryDescription";
import { ensureEnum } from "igniteui-angular-core";
/**
 * Represents a summary that is applied to a datasource. Changes to this object are not observed or expected after it is initially assigned to a collection.
*/
export class IgxChartSummaryDescription {
    constructor() {
        this._provideCalculator = null;
        this._zoneRunner = null;
        this._implementation = this.createImplementation();
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    }
    createImplementation() {
        return new ChartSummaryDescription_internal(0);
    }
    /**
     * @hidden
     */
    get i() {
        return this._implementation;
    }
    onImplementationCreated() {
    }
    _provideImplementation(i) {
        this._implementation = i;
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    }
    get field() {
        return this.i.p;
    }
    set field(v) {
        this.i.p = v;
    }
    get operand() {
        return this.i.c;
    }
    set operand(v) {
        this.i.c = ensureEnum(DataSourceSummaryOperand_$type, v);
    }
    /**
     * Gets or sets an alias for the summary. Currently only used in aggregated data situations.
    */
    get alias() {
        return this.i.n;
    }
    set alias(v) {
        this.i.n = v;
    }
    /**
     * Gets or sets the name to use when displaying the calculator name.
    */
    get calculatorDisplayName() {
        return this.i.o;
    }
    set calculatorDisplayName(v) {
        this.i.o = v;
    }
    findByName(name) {
        if (this.findEphemera) {
            if (name && name.indexOf("@@e:") == 0) {
                return this.findEphemera(name);
            }
        }
        return null;
    }
    equals(other) {
        let iv = this.i.equals(other);
        return (iv);
    }
    /**
     * Called when the summary calculator is required.
    */
    get provideCalculator() {
        if (this._provideCalculator == null) {
            this._provideCalculator = new EventEmitter();
            this.i.provideCalculator = delegateCombine(this.i.provideCalculator, (o, e) => {
                this._runInZone(() => {
                    let outerArgs = new IgxProvideCalculatorEventArgs();
                    outerArgs._provideImplementation(e);
                    if (this.beforeProvideCalculator) {
                        this.beforeProvideCalculator(this, outerArgs);
                    }
                    this._provideCalculator.emit({
                        sender: this,
                        args: outerArgs
                    });
                });
            });
        }
        return this._provideCalculator;
    }
    _runInZone(act) {
        if (this._zoneRunner != null) {
            this._zoneRunner(act);
        }
        else {
            act();
        }
    }
}
