import { __extends } from "tslib";
import { EventEmitter, Output, Component, Input } from '@angular/core';
import { delegateCombine } from "igniteui-angular-core";
import { toPoint, ensureBool } from "igniteui-angular-core";
import { TypeRegistrar } from "igniteui-angular-core";
import { IgxStackedSeriesCreatedEventArgs } from './igx-stacked-series-created-event-args';
import { IgxCategorySeriesComponent } from "./igx-category-series-component";
import { ContentChildren } from '@angular/core';
import { NotifyCollectionChangedAction } from "igniteui-angular-core";
import { IgxStackedFragmentSeriesComponent } from './igx-stacked-fragment-series-component';
import { CollectionAdapter } from "igniteui-angular-core";
import { IgxStackedSeriesCollection } from './igx-stacked-series-collection';
import * as i0 from "@angular/core";
/**
 * Represents a base class for stacked series.
*/
var IgxStackedSeriesBaseComponent = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(IgxStackedSeriesBaseComponent, _super);
    function IgxStackedSeriesBaseComponent() {
        var _this = _super.call(this) || this;
        _this._seriesAdapter = null;
        /**
         * The series actually present in the chart. Do not directly modify this array.
         * This array's contents can be modified by causing Angular to reproject the child content.
         * Or adding and removing series from the manual series collection on the series property.
         */
        _this.actualSeries = [];
        _this._series = null;
        _this._seriesCreated = null;
        //=============================
        _this._seriesAdapter = new CollectionAdapter([], _this.i.series, _this.actualSeries, function (c) { return c.i; }, function (i) {
            i.owner = _this;
            //(<any>i)._provideRenderer(this._dataSource);
            //i.provideData(this._dataSource);
            //this._ensureDefaultTooltip(i);
            //this._ensureTooltipCreated(i);
        }, function (i) {
            //(<any>i)._provideRenderer(null);
            //i.provideData(null); 
        });
        return _this;
        //=============================
    }
    IgxStackedSeriesBaseComponent.prototype.createImplementation = function () {
        return null;
    };
    IgxStackedSeriesBaseComponent.prototype.ngOnInit = function () {
    };
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "i", {
        get: function () {
            return this._implementation;
        },
        enumerable: false,
        configurable: true
    });
    //=============================
    IgxStackedSeriesBaseComponent.prototype.ngAfterContentInit = function () {
        this._seriesAdapter.updateQuery(this.fragments);
    };
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "series", {
        /**
         * A collection or manually added series for the chart.
        */
        get: function () {
            var _this = this;
            if (this._series === null) {
                var coll = new IgxStackedSeriesCollection();
                var inner = coll._innerColl;
                inner.addListener(function (sender, e) {
                    switch (e.action) {
                        case NotifyCollectionChangedAction.Add:
                            _this._seriesAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0));
                            break;
                        case NotifyCollectionChangedAction.Remove:
                            _this._seriesAdapter.removeManualItemAt(e.oldStartingIndex);
                            break;
                        case NotifyCollectionChangedAction.Replace:
                            _this._seriesAdapter.removeManualItemAt(e.oldStartingIndex);
                            _this._seriesAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0));
                            break;
                        case NotifyCollectionChangedAction.Reset:
                            _this._seriesAdapter.clearManualItems();
                            break;
                    }
                });
                this._series = coll;
            }
            return this._series;
        },
        enumerable: false,
        configurable: true
    });
    //=============================
    IgxStackedSeriesBaseComponent._createFromInternal = function (internal) {
        if (!internal) {
            return null;
        }
        if (!internal.$type) {
            return null;
        }
        var name = internal.$type.name;
        var externalName = "Igx" + name + "Component";
        if (!TypeRegistrar.isRegistered(externalName)) {
            return null;
        }
        return TypeRegistrar.create(externalName);
    };
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "autoGenerateSeries", {
        /**
     * Gets or sets whether series should be automatically generated. Reqiures the use of GroupBy as the ItemsSource.
    */
        get: function () {
            return this.i.aa3;
        },
        set: function (v) {
            this.i.aa3 = ensureBool(v);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "reverseLegendOrder", {
        /**
         * Gets or sets whether the order of the fragment series should be reversed in the legend.
        */
        get: function () {
            return this.i.aa5;
        },
        set: function (v) {
            this.i.aa5 = ensureBool(v);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "isStacked", {
        /**
         * Checks if this series is a stacked series
        */
        get: function () {
            return this.i.isStacked;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "isPercentBased", {
        get: function () {
            return this.i.aa4;
        },
        enumerable: false,
        configurable: true
    });
    IgxStackedSeriesBaseComponent.prototype.findByName = function (name) {
        var baseResult = _super.prototype.findByName.call(this, name);
        if (baseResult) {
            return baseResult;
        }
        if (this.series != null && this.series.findByName && this.series.findByName(name)) {
            return this.series.findByName(name);
        }
        return null;
    };
    /**
 * Called to notify about changes to indexed-based properties, e.g. Brushes, Outlines, MarkerBrushes, MarkerOutlines and refresh series

*/
    IgxStackedSeriesBaseComponent.prototype.notifyIndexedPropertiesChanged = function () {
        this.i.qg();
    };
    /**
     * Simulates a pointer hover over the series surface.
    
    * @param point  * The pointer position relative to the series viewport over which to hover.
    */
    IgxStackedSeriesBaseComponent.prototype.simulateHover = function (point) {
        this.i.r6(toPoint(point));
    };
    /**
     * Scrolls the series to display the item for the specified data item.
     * The series is scrolled by the minimum amount required to place the specified data item within
     * the central 80% of the visible axis.
    
    * @param item  * The data item (item) to scroll to.
    */
    IgxStackedSeriesBaseComponent.prototype.scrollIntoView = function (item) {
        var iv = this.i.gd(item);
        return (iv);
    };
    IgxStackedSeriesBaseComponent.prototype.replayTransitionIn = function () {
        this.i.rv();
    };
    Object.defineProperty(IgxStackedSeriesBaseComponent.prototype, "seriesCreated", {
        /**
         * Event raised when a new fragment series is automatically generated.
        */
        get: function () {
            var _this = this;
            if (this._seriesCreated == null) {
                this._seriesCreated = new EventEmitter();
                this.i.seriesCreated = delegateCombine(this.i.seriesCreated, function (o, e) {
                    _this._runInZone(function () {
                        var outerArgs = new IgxStackedSeriesCreatedEventArgs();
                        outerArgs._provideImplementation(e);
                        if (_this.beforeSeriesCreated) {
                            _this.beforeSeriesCreated(_this, outerArgs);
                        }
                        _this._seriesCreated.emit({
                            sender: _this,
                            args: outerArgs
                        });
                    });
                });
            }
            return this._seriesCreated;
        },
        enumerable: false,
        configurable: true
    });
    IgxStackedSeriesBaseComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IgxStackedSeriesBaseComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    IgxStackedSeriesBaseComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.17", type: IgxStackedSeriesBaseComponent, selector: "ng-component", inputs: { autoGenerateSeries: "autoGenerateSeries", reverseLegendOrder: "reverseLegendOrder" }, outputs: { seriesCreated: "seriesCreated" }, queries: [{ propertyName: "fragments", predicate: IgxStackedFragmentSeriesComponent }], usesInheritance: true, ngImport: i0, template: "", isInline: true });
    return IgxStackedSeriesBaseComponent;
}(IgxCategorySeriesComponent));
export { IgxStackedSeriesBaseComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: IgxStackedSeriesBaseComponent, decorators: [{
            type: Component,
            args: [{
                    template: "",
                }]
        }], ctorParameters: function () { return []; }, propDecorators: { fragments: [{
                type: ContentChildren,
                args: [IgxStackedFragmentSeriesComponent]
            }], autoGenerateSeries: [{
                type: Input
            }], reverseLegendOrder: [{
                type: Input
            }], seriesCreated: [{
                type: Output
            }] } });
