/*
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 { IFastItemColumnInternal_$type } from "./IFastItemColumnInternal";
import { IFastItemColumn$1_$type } from "./IFastItemColumn$1";
import { Base, fromEnum, Number_$type, typeGetValue, markType } from "./type";
import { List$1 } from "./List$1";
import { NotImplementedException } from "./NotImplementedException";
import { isNaN_ } from "./number";
export class FastItemColumn extends Base {
    constructor(a, b, c, d) {
        super();
        this.j = null;
        this.c = false;
        this.a = null;
        this._propertyName = null;
        this.h = 0;
        this.g = 0;
        this.f = null;
        this.k = 0;
        this.j = c;
        this.c = d;
        this.propertyName = b;
        this.b = a;
    }
    get b() {
        return this.a;
    }
    set b(a) {
        this.a = a;
        this.reset();
    }
    get propertyName() {
        return this._propertyName;
    }
    set propertyName(a) {
        this._propertyName = a;
    }
    get minimum() {
        if (isNaN_(this.h) && this.f != null) {
            this.h = Number.POSITIVE_INFINITY;
            for (let a of fromEnum(this.f)) {
                if (!isNaN_(a)) {
                    this.h = Math.min(this.h, a);
                }
            }
        }
        return this.h;
    }
    set minimum(a) {
        this.h = a;
    }
    get maximum() {
        if (isNaN_(this.g) && this.f != null) {
            this.g = Number.NEGATIVE_INFINITY;
            for (let a of fromEnum(this.f)) {
                if (!isNaN_(a)) {
                    this.g = Math.max(this.g, a);
                }
            }
        }
        return this.g;
    }
    set maximum(a) {
        this.g = a;
    }
    item(a, b) {
        if (arguments.length === 2) {
            this.f._inner[a] = b;
            return b;
        }
        else {
            return this.f._inner[a];
        }
    }
    getEnumerator() {
        return this.f.getEnumerator();
    }
    getEnumeratorObject() {
        return this.f.getEnumerator();
    }
    contains(a) {
        return this.f.contains(a);
    }
    copyTo(a, b) {
        this.f.copyTo(a, b);
    }
    get count() {
        return this.f.count;
    }
    get isReadOnly() {
        return true;
    }
    indexOf(a) {
        return this.f.indexOf(a);
    }
    add(a) {
        throw new NotImplementedException(0);
    }
    clear() {
        throw new NotImplementedException(0);
    }
    remove(a) {
        throw new NotImplementedException(0);
    }
    insert(a, b) {
        throw new NotImplementedException(0);
    }
    removeAt(a) {
        throw new NotImplementedException(0);
    }
    reset() {
        this.f = null;
        this.minimum = NaN;
        this.maximum = NaN;
        this.k = 0;
        return this.b != null ? this.insertRange(0, this.b.count) : true;
    }
    insertRange(a, b) {
        let c = new Array(b);
        let source_ = this.a.asArray();
        let item_;
        let d = this.minimum;
        let e = this.maximum;
        let f = isNaN_(this.minimum);
        let g = isNaN_(this.maximum);
        let h = 0;
        let i;
        let j = this.j;
        let sourceItem_ = null;
        let propertyName_ = this._propertyName;
        if (this.j != null || this.c) {
            for (let i_ = a; i_ < a + b; ++i_) {
                sourceItem_ = source_[i_];
                if (sourceItem_ == null) {
                    item_ = NaN;
                }
                else {
                    item_ = (sourceItem_[propertyName_]);
                }
                if (this.c) {
                    if ((typeof (item_) == 'function')) {
                        item_ = item_.apply(sourceItem_);
                    }
                }
                if (j != null) {
                    item_ = j(item_);
                }
                i = item_ == null ? NaN : item_;
                let k = (i != i);
                if (k) {
                    this.k++;
                }
                if (f || i < d) {
                    d = i;
                    f = k;
                }
                if (g || i > e) {
                    e = i;
                    g = k;
                }
                c[h] = i;
                h++;
            }
        }
        else {
            for (let i_ = a; i_ < a + b; ++i_) {
                sourceItem_ = source_[i_];
                if (sourceItem_ == null) {
                    item_ = NaN;
                }
                else {
                    item_ = (sourceItem_[propertyName_]);
                }
                i = item_ == null ? NaN : item_;
                let l = (i != i);
                if (l) {
                    this.k++;
                }
                if (f || i < d) {
                    d = i;
                    f = l;
                }
                if (g || i > e) {
                    e = i;
                    g = l;
                }
                c[h] = i;
                h++;
            }
        }
        this.minimum = d;
        this.maximum = e;
        if (this.f == null) {
            this.f = new List$1(Number_$type, 1, c);
        }
        else {
            this.f.t(a, c);
        }
        return true;
    }
    removeRange(a, b) {
        for (let c = a; c < a + b && !isNaN_(this.minimum) && !isNaN_(this.maximum); ++c) {
            if (this.item(c) == this.minimum) {
                this.minimum = NaN;
            }
            if (this.item(c) == this.maximum) {
                this.maximum = NaN;
            }
            if (isNaN_(this.item(c))) {
                this.k--;
            }
        }
        this.f.v(a, b);
        return true;
    }
    p(a, b) {
        if (isNaN_(a)) {
            if (!isNaN_(b)) {
                if (!isNaN_(this.minimum)) {
                    this.minimum = Math.min(b, this.minimum);
                }
                if (!isNaN_(this.maximum)) {
                    this.maximum = Math.max(b, this.maximum);
                }
            }
            return;
        }
        if (isNaN_(b)) {
            this.minimum = !isNaN_(this.minimum) && a == this.minimum ? NaN : this.minimum;
            this.maximum = !isNaN_(this.maximum) && a == this.maximum ? NaN : this.maximum;
            return;
        }
        if (!isNaN_(this.minimum)) {
            if (a == this.minimum && b > this.minimum) {
                this.minimum = NaN;
            }
            else {
                this.minimum = Math.min(b, this.minimum);
            }
        }
        if (!isNaN_(this.maximum)) {
            if (a == this.maximum && b < this.maximum) {
                this.maximum = NaN;
            }
            else {
                this.maximum = Math.max(b, this.maximum);
            }
        }
    }
    replaceRange(a, b) {
        let c = false;
        for (let d = 0; d < b; ++d) {
            let e = this.f._inner[a + d];
            let f = this.i(this.b.item(a + d));
            if (isNaN_(e)) {
                this.k--;
            }
            if (isNaN_(f)) {
                this.k++;
            }
            if (e != f) {
                this.f._inner[a + d] = f;
                c = true;
                this.p(e, f);
            }
        }
        return c;
    }
    i(a) {
        if (a == null) {
            return NaN;
        }
        let sourceItem_ = a;
        let from_ = a;
        let propertyName_ = this._propertyName;
        a = from_[propertyName_];
        if (this.c) {
            from_ = a;
            if ((typeof (from_) == 'function')) {
                a = from_.apply(sourceItem_);
            }
        }
        if (this.j != null) {
            a = this.j(a);
        }
        if (a == null) {
            return NaN;
        }
        return a;
    }
    get mayContainUnknowns() {
        return this.k > 0;
    }
    static n(a, b) {
        FastItemColumn.o(a, 0, a.count - 1, b);
    }
    static o(a, b, c, d) {
        if (b < c) {
            let e = FastItemColumn.l(a, b, c, d);
            FastItemColumn.o(a, b, e - 1, d);
            FastItemColumn.o(a, e + 1, c, d);
        }
    }
    static l(a, b, c, d) {
        let e = a.item(c);
        let f = b;
        for (let g = b; g < c; g++) {
            if (d(a.item(g), e) <= 0) {
                let h = a.item(f);
                a.item(f, a.item(g));
                a.item(g, h);
                f++;
            }
        }
        let i = a.item(f);
        a.item(f, a.item(c));
        a.item(c, i);
        return f;
    }
    static e(a, b) {
        let c = new List$1(Number_$type, 2, a.count);
        for (let d = 0; d < a.count; d++) {
            c.add(d);
        }
        if (a.count < 22) {
            FastItemColumn.n(c, (e, f) => {
                let g = a.item(typeGetValue(e));
                let h = a.item(typeGetValue(f));
                return b(g, h);
            });
        }
        else {
            c.aa((e, f) => {
                let g = a.item(e);
                let h = a.item(f);
                return b(g, h);
            });
        }
        return c;
    }
    d() {
        return FastItemColumn.e(this.f, (a, b) => {
            let c = a;
            let d = b;
            if (c < d) {
                return -1;
            }
            if (c > d) {
                return 1;
            }
            return 0;
        });
    }
    asArray() {
        return this.f.asArray();
    }
    getItem(a) {
        return this.item(a);
    }
}
FastItemColumn.$t = markType(FastItemColumn, 'FastItemColumn', Base.$, [IFastItemColumnInternal_$type, IFastItemColumn$1_$type.specialize(Number_$type)]);
//# sourceMappingURL=FastItemColumn.js.map