import { Ring } from "./igr-ring";
import { IgrRingSeriesBase } from "./igr-ring-series-base";
import { RingSeries } from "./RingSeries";
import { IndexCollection } from "igniteui-react-charts/ES2015/igr-index-collection";
import { IndexCollection as IndexCollection_internal } from "igniteui-react-charts/ES2015/IndexCollection";
import { Number_$type } from "igniteui-react-core/ES2015/type";
import { SyncableObservableCollection$1 } from "igniteui-react-core/ES2015/SyncableObservableCollection$1";
/**
 * Represents one ring in IgxDoughnutChartComponent series.
*/
export class IgrRingSeries extends IgrRingSeriesBase {
    constructor(props) {
        super(props);
        this._explodedSlices = null;
        this._selectedSlices = null;
    }
    createImplementation() {
        return new RingSeries();
    }
    get i() {
        return this._implementation;
    }
    /**
     * Gets or sets the collection of exploded slice indices.
    */
    get explodedSlices() {
        if (this._explodedSlices === null) {
            let coll = new IndexCollection();
            let innerColl;
            if (this.ring.i.ringControl.arcs.count == 0) {
                innerColl = new IndexCollection_internal();
            }
            else {
                innerColl = this.ring.i.ringControl.arcs.item(0).explodedSlices;
            }
            this._explodedSlices = coll._fromInner(innerColl);
        }
        return this._explodedSlices;
    }
    set explodedSlices(v) {
        if (this._explodedSlices !== null) {
            this._explodedSlices._setSyncTarget(null);
            this._explodedSlices = null;
        }
        let coll = new IndexCollection();
        this._explodedSlices = coll._fromOuter(v);
        let syncColl = new SyncableObservableCollection$1(Number_$type);
        let innerColl;
        if (this.ring.i.ringControl.arcs.count == 0) {
            innerColl = new IndexCollection_internal();
        }
        else {
            innerColl = this.ring.i.ringControl.arcs.item(0).explodedSlices;
        }
        syncColl._inner = innerColl;
        syncColl.clear();
        this._explodedSlices._setSyncTarget(syncColl);
    }
    /**
     * Gets or sets the collection of selected slice indices.
    */
    get selectedSlices() {
        if (this._selectedSlices === null) {
            let coll = new IndexCollection();
            let innerColl;
            if (this.ring.i.ringControl.arcs.count == 0) {
                innerColl = new IndexCollection_internal();
            }
            else {
                innerColl = this.ring.i.ringControl.arcs.item(0).selectedSlices;
            }
            this._selectedSlices = coll._fromInner(innerColl);
        }
        return this._selectedSlices;
    }
    set selectedSlices(v) {
        if (this._selectedSlices !== null) {
            this._selectedSlices._setSyncTarget(null);
            this._selectedSlices = null;
        }
        let coll = new IndexCollection();
        this._selectedSlices = coll._fromOuter(v);
        let syncColl = new SyncableObservableCollection$1(Number_$type);
        let innerColl;
        if (this.ring.i.ringControl.arcs.count == 0) {
            innerColl = new IndexCollection_internal();
        }
        else {
            innerColl = this.ring.i.ringControl.arcs.item(0).selectedSlices;
        }
        syncColl._inner = innerColl;
        syncColl.clear();
        this._selectedSlices._setSyncTarget(syncColl);
    }
    sychronizeCollections() {
        if (this._explodedSlices) {
            let inner = this._explodedSlices._inner;
            if (inner && inner !== this.ring.i.ringControl.arcs.item(0).explodedSlices) {
                this._explodedSlices._inner = this.ring.i.ringControl.arcs.item(0).explodedSlices;
                for (var i = 0; i < inner.count; i++) {
                    this._explodedSlices.add(inner.item(i));
                }
            }
        }
        if (this._selectedSlices) {
            let inner = this._selectedSlices._inner;
            if (inner && inner !== this.ring.i.ringControl.arcs.item(0).selectedSlices) {
                this._selectedSlices._inner = this.ring.i.ringControl.arcs.item(0).selectedSlices;
                for (var i = 0; i < inner.count; i++) {
                    this._selectedSlices.add(inner.item(i));
                }
            }
        }
    }
    /**
 * Gets reference to the ring data.
*/
    get ring() {
        if (this.i.dr == null) {
            return null;
        }
        if (!this.i.dr.externalObject) {
            let e = new Ring();
            e._implementation = this.i.dr;
            this.i.dr.externalObject = e;
        }
        return this.i.dr.externalObject;
    }
    set ring(v) {
        v == null ? this.i.dr = null : this.i.dr = v.i;
    }
}
