/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { IDataSource_$type } from "./IDataSource";
import { IDataSourceDataProviderUpdateNotifier_$type } from "./IDataSourceDataProviderUpdateNotifier";
import { SortDescriptionCollection } from "./SortDescriptionCollection";
import { FilterExpressionCollection } from "./FilterExpressionCollection";
import { PropertyChangedEventArgs, Base, runOn, delegateRemove, delegateCombine, markType } from "./type";
import { DataSourceSchemaChangedEventArgs } from "./DataSourceSchemaChangedEventArgs";
export class BaseDataSource extends Base {
    constructor() {
        super();
        this.aa = false;
        this.ah = null;
        this.m = null;
        this.o = null;
        this.n = null;
        this.e = null;
        this.f = null;
        this.k = null;
        this.ad = 0;
        this.ae = 0;
        this.af = 0;
        this.l = null;
        this.propertyChanged = null;
        this.h = null;
        this.j = null;
        this.schemaChanged = null;
        this.s = false;
        this.r = false;
        this.b = null;
        this.a = null;
        this.c = null;
        this.t = false;
        this.u = false;
        this.p = false;
        this.w = true;
        this.v = false;
        this.x = true;
        this.q = false;
        this.d = null;
        this.h = new DefaultDataSourceDataProviderUpdateNotifier(this);
        this.o = new SortDescriptionCollection();
        this.n = new SortDescriptionCollection();
        this.o.m(runOn(this, this.bt));
        this.n.m(runOn(this, this.a3));
        this.e = new FilterExpressionCollection();
        this.e.l(runOn(this, this.a1));
    }
    bt(a, b) {
        this.bp(b);
    }
    a3(a, b) {
        this.bg(b);
    }
    a1(a, b) {
        this.bf(b);
    }
    bp(a) {
        this.queueAutoRefresh();
    }
    bg(a) {
        if (this.isGroupingSupported) {
            if (this.groupDescriptions != null && this.groupDescriptions.j.count > 0) {
                this.aa = true;
            }
            else {
                this.aa = false;
            }
            this.queueAutoRefresh();
        }
    }
    bf(a) {
        this.queueAutoRefresh();
    }
    isPlaceholderItem(a) {
        return false;
    }
    get actualSchema() {
        return this.k;
    }
    set actualSchema(a) {
        let b = this.k;
        this.k = a;
        if (b != this.k) {
            this.bj("ActualSchema", b, this.k);
        }
    }
    get actualCount() {
        return this.ad;
    }
    set actualCount(a) {
        let b = this.ad;
        this.ad = a;
        if (b != this.ad) {
            this.bj("ActualCount", b, this.ad);
        }
    }
    get firstVisibleIndexRequested() {
        return this.ae;
    }
    set firstVisibleIndexRequested(a) {
        let b = this.ae;
        this.ae = a;
        if (b != this.ae) {
            this.bj("FirstVisibleIndexRequested", b, this.ae);
        }
    }
    get lastVisibleIndexRequested() {
        return this.af;
    }
    set lastVisibleIndexRequested(a) {
        let b = this.af;
        this.af = a;
        if (b != this.af) {
            this.bj("LastVisibleIndexRequested", b, this.af);
        }
    }
    get updateNotifier() {
        return this.l;
    }
    set updateNotifier(a) {
        let b = this.l;
        this.l = a;
        if (b != this.l) {
            this.bj("UpdateNotifier", b, this.l);
        }
    }
    getItemAtIndex(a) {
        return null;
    }
    getItemProperty(a, b) {
        if (this.g != null) {
            let item_ = a;
            if ((item_ != null && item_.$$isSpecialRow !== undefined)) {
                return this.ai(a, b);
            }
            return this.g.getItemValue(a, b);
        }
        return null;
    }
    ai(a, b) {
        if (a.a == 3) {
            return this.getItemProperty(a.f, b);
        }
        return a.e(b);
    }
    getItemPropertyAtIndex(a, b) {
        return null;
    }
    get_z() {
        return false;
    }
    get z() {
        return this.get_z();
    }
    bj(a, b, c) {
        if (this.propertyChanged != null) {
            this.propertyChanged(this, new PropertyChangedEventArgs(a));
        }
        this.bq(a, b, c);
    }
    bq(a, b, c) {
        switch (a) {
            case "PrimaryKey":
                this.actualPrimaryKey = this.primaryKey;
                break;
            case "ActualPrimaryKey":
                this.a7(b, c);
                break;
            case "ExecutionContext":
                if (this.g != null) {
                    this.g.executionContext = this.executionContext;
                }
                this.queueAutoRefresh();
                break;
            case "LastVisibleIndexRequested":
            case "FirstVisibleIndexRequested":
                this.bm();
                break;
            case "ActualDataProvider":
                this.a6(b, c);
                break;
            case "DeferAutoRefresh":
                if (this.g != null) {
                    this.g.deferAutoRefresh = this.deferAutoRefresh;
                }
                if (!c) {
                    this.queueAutoRefresh();
                }
                break;
            case "PropertiesRequested":
                if (this.g != null) {
                    this.g.propertiesRequested = this.propertiesRequested;
                }
                break;
            case "ShouldEmitSectionFooters":
            case "ShouldEmitSectionHeaders":
            case "ShouldEmitShiftedRows":
                this.queueAutoRefresh();
                break;
        }
    }
    a7(a, b) {
        this.a8(a, b);
    }
    a8(a, b) {
    }
    get_isVirtual() {
        return false;
    }
    get isVirtual() {
        return this.get_isVirtual();
    }
    get i() {
        return this.h;
    }
    a6(a, b) {
        let c = a;
        let d = b;
        if (c != null) {
            c.updateNotifier = null;
        }
        if (d != null) {
            d.updateNotifier = this.h;
        }
        if (c != null) {
            c.schemaChanged = delegateRemove(c.schemaChanged, runOn(this, this.ay));
        }
        if (d != null) {
            d.schemaChanged = delegateCombine(d.schemaChanged, runOn(this, this.ay));
            d.executionContext = this.executionContext;
            this.notifyUsingSourceIndexes = this.g.notifyUsingSourceIndexes;
        }
        else {
            this.notifyUsingSourceIndexes = false;
        }
        if (c != null) {
            this.sortDescriptions.e = null;
            this.groupDescriptions.e = null;
            this.filterExpressions.b = null;
        }
        if (d != null) {
            this.sortDescriptions.e = d.sortDescriptions;
            this.groupDescriptions.e = d.groupDescriptions;
            this.filterExpressions.b = d.filterExpressions;
            if (this.propertiesRequested != null) {
                d.propertiesRequested = this.propertiesRequested;
            }
        }
        this.queueAutoRefresh();
    }
    bm() {
    }
    get executionContext() {
        return this.j;
    }
    set executionContext(a) {
        let b = this.j;
        this.j = a;
        if (this.j != b) {
            this.bj("ExecutionContext", b, this.j);
        }
    }
    y() {
        if (this.j != null && this.g != null) {
            return true;
        }
        return false;
    }
    get ab() {
        return this.s;
    }
    get_isSortingSupported() {
        return false;
    }
    get isSortingSupported() {
        return this.get_isSortingSupported();
    }
    get_isFilteringSupported() {
        return false;
    }
    get isFilteringSupported() {
        return this.get_isFilteringSupported();
    }
    get sortDescriptions() {
        return this.o;
    }
    get groupDescriptions() {
        return this.n;
    }
    get filterExpressions() {
        return this.e;
    }
    get deferAutoRefresh() {
        return this.r;
    }
    set deferAutoRefresh(a) {
        let b = this.r;
        this.r = a;
        if (this.r != b) {
            this.bj("DeferAutoRefresh", b, this.r);
        }
    }
    get primaryKey() {
        return this.b;
    }
    set primaryKey(a) {
        let b = this.b;
        this.b = a;
        if (this.b != b) {
            this.bj("PrimaryKey", b, this.b);
        }
    }
    get actualPrimaryKey() {
        return this.a;
    }
    set actualPrimaryKey(a) {
        let b = this.a;
        this.a = a;
        if (this.a != b) {
            this.bj("ActualPrimaryKey", b, this.a);
        }
    }
    get propertiesRequested() {
        return this.c;
    }
    set propertiesRequested(a) {
        let b = this.c;
        this.c = a;
        if (this.c != b) {
            this.bj("PropertiesRequested", b, this.c);
        }
    }
    get notifyUsingSourceIndexes() {
        return this.t;
    }
    set notifyUsingSourceIndexes(a) {
        let b = this.t;
        this.t = a;
        if (this.t != b) {
            this.bj("NotifyUsingSourceIndexes", b, this.t);
        }
    }
    get_isItemIndexLookupSupported() {
        return false;
    }
    get isItemIndexLookupSupported() {
        return this.get_isItemIndexLookupSupported();
    }
    get_isKeyIndexLookupSupported() {
        return false;
    }
    get isKeyIndexLookupSupported() {
        return this.get_isKeyIndexLookupSupported();
    }
    a4() {
    }
    ag(a) {
        return a;
    }
    ay(a, b) {
        let c = this.executionContext;
        c.execute(() => {
            this.u = true;
            this.q = true;
            this.queueAutoRefresh();
            if (this.deferAutoRefresh) {
                this.actualSchema = b.schema;
                this.actualCount = this.ag(b.count);
                this.a5();
            }
        });
    }
    a5() {
        if (this.schemaChanged != null) {
            this.schemaChanged(this, new DataSourceSchemaChangedEventArgs(this.actualSchema, this.actualCount));
        }
    }
    bn(a, b, c) {
        this.bo(a, b, c);
    }
    bc(a, b, c) {
        if (this.updateNotifier != null) {
            this.updateNotifier.notifySetItem(a, b, c);
        }
    }
    bo(a, b, c) {
        if (this.g != null) {
            this.actualCount = this.ag(this.g.actualCount);
        }
        this.bc(a, b, c);
    }
    bd() {
        this.be();
    }
    a9() {
        if (this.updateNotifier != null) {
            this.updateNotifier.notifyClearItems();
        }
    }
    be() {
        if (this.g != null) {
            this.actualCount = this.ag(this.g.actualCount);
        }
        this.a9();
    }
    bh(a, b) {
        this.bi(a, b);
    }
    ba(a, b) {
        if (this.updateNotifier != null) {
            this.updateNotifier.notifyInsertItem(a, b);
        }
    }
    bi(a, b) {
        if (this.g != null) {
            this.actualCount = this.ag(this.g.actualCount);
        }
        this.ba(a, b);
    }
    bk(a, b) {
        this.bl(a, b);
    }
    bb(a, b) {
        if (this.updateNotifier != null) {
            this.updateNotifier.notifyRemoveItem(a, b);
        }
    }
    bl(a, b) {
        if (this.g != null) {
            this.actualCount = this.ag(this.g.actualCount);
        }
        this.bb(a, b);
    }
    notifySetItem(a, b, c) {
        if (this.g != null) {
            this.g.notifySetItem(a, b, c);
        }
    }
    notifyClearItems() {
        if (this.g != null) {
            this.g.notifyClearItems();
        }
    }
    notifyInsertItem(a, b) {
        if (this.g != null) {
            this.g.notifyInsertItem(a, b);
        }
        ;
    }
    notifyRemoveItem(a, b) {
        if (this.g != null) {
            this.g.notifyRemoveItem(a, b);
        }
        ;
    }
    queueAutoRefresh() {
        if (this.deferAutoRefresh) {
            return;
        }
        if (this.g != null) {
            this.g.queueAutoRefresh();
        }
        if (this.p) {
            return;
        }
        if (this.executionContext != null) {
            this.p = true;
            this.executionContext.enqueueAction(runOn(this, this.az));
        }
    }
    az() {
        if (this.deferAutoRefresh) {
            this.p = false;
            return;
        }
        if (this.g != null) {
            this.g.flushAutoRefresh();
        }
        if (!this.p) {
            return;
        }
        this.p = false;
        this.br();
    }
    br() {
        if (this.g != null) {
            this.actualSchema = this.g.actualSchema;
            this.actualCount = this.ag(this.g.actualCount);
        }
        if (this.actualSchema != null && this.primaryKey == null) {
            this.actualPrimaryKey = this.actualSchema.primaryKey;
        }
        this.bs();
        if (this.u) {
            this.u = false;
            this.a5();
        }
    }
    bs() {
    }
    flushAutoRefresh() {
        this.az();
    }
    refresh() {
        if (this.g != null) {
            this.g.refresh();
        }
        this.br();
    }
    indexOfItem(a) {
        return -1;
    }
    indexOfKey(a) {
        return -1;
    }
    a2(a, b) {
        let c = this.actualPrimaryKey;
        if (c == null || c.length < 1 || this.g == null) {
            return;
        }
        for (let d = 0; d < c.length; d++) {
            b[d] = this.g.getItemValue(a, c[d]);
        }
    }
    getRowType(a) {
        return 0;
    }
    getMainValuePath(a) {
        return "SectionInformation";
    }
    getStickyRows() {
        return null;
    }
    isRowSpanning(a) {
        return a == 1 || a == 2;
    }
    getStickyRowPriority(a) {
        return -1;
    }
    isExclusivelySticky(a) {
        return false;
    }
    pinRow(a) {
    }
    unpinRow(a) {
    }
    clearPinnedRows() {
    }
    isRowPinned(a) {
        return false;
    }
    get_isGroupingSupported() {
        return false;
    }
    get isGroupingSupported() {
        return this.get_isGroupingSupported();
    }
    get shouldEmitSectionHeaders() {
        return this.w;
    }
    set shouldEmitSectionHeaders(a) {
        let b = this.w;
        this.w = a;
        if (this.w != b) {
            this.bj("ShouldEmitSectionHeaders", b, this.w);
        }
    }
    get shouldEmitSectionFooters() {
        return this.v;
    }
    set shouldEmitSectionFooters(a) {
        let b = this.v;
        this.v = a;
        if (this.v != b) {
            this.bj("ShouldEmitSectionFooters", b, this.v);
        }
    }
    get shouldEmitShiftedRows() {
        return this.x;
    }
    set shouldEmitShiftedRows(a) {
        let b = this.x;
        this.x = a;
        if (this.x != b) {
            this.bj("ShouldEmitShiftedRows", b, this.x);
        }
    }
    a0(a) {
        if (this.q && this.actualCount > 0) {
            this.d = new Array(a.propertyNames.length);
            this.q = false;
        }
    }
    resolveSchemaPropertyType(a) {
        return this.g.resolveSchemaPropertyType(a);
    }
}
BaseDataSource.$t = markType(BaseDataSource, 'BaseDataSource', Base.$, [IDataSource_$type]);
export class DefaultDataSourceDataProviderUpdateNotifier extends Base {
    constructor(a) {
        super();
        this.a = null;
        this.a = a;
    }
    notifySetItem(a, b, c) {
        this.a.bn(a, b, c);
    }
    notifyClearItems() {
        this.a.bd();
    }
    notifyInsertItem(a, b) {
        this.a.bh(a, b);
    }
    notifyRemoveItem(a, b) {
        this.a.bk(a, b);
    }
}
DefaultDataSourceDataProviderUpdateNotifier.$t = markType(DefaultDataSourceDataProviderUpdateNotifier, 'DefaultDataSourceDataProviderUpdateNotifier', Base.$, [IDataSourceDataProviderUpdateNotifier_$type]);
//# sourceMappingURL=BaseDataSource_combined.js.map