/*
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, Date_$type, markType, TypeRegistrar } from "./type";
import { List$1 } from "./List$1";
import { NotImplementedException } from "./NotImplementedException";
import { FastItemColumn } from "./FastItemColumn";
import { dateMinValue } from "./date";
export class FastItemDateTimeColumn extends Base {
    constructor(a, b, c, d) {
        super();
        this.k = null;
        this.c = false;
        this.a = null;
        this._propertyName = null;
        this.e = false;
        this.d = false;
        this.i = new Date();
        this.h = new Date();
        this.g = null;
        this.k = 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 (!this.e && this.g != null) {
            for (let a of fromEnum(this.g)) {
                if (a < this.i) {
                    this.i = a;
                }
            }
            if (this.g.count > 0) {
                this.e = true;
            }
        }
        return this.i;
    }
    set minimum(a) {
        this.i = a;
    }
    get maximum() {
        if (!this.d && this.g != null) {
            for (let a of fromEnum(this.g)) {
                if (a > this.h) {
                    this.h = a;
                }
            }
            if (this.g.count > 0) {
                this.d = true;
            }
        }
        return this.h;
    }
    set maximum(a) {
        this.h = a;
    }
    item(a, b) {
        if (arguments.length === 2) {
            return b;
        }
        else {
            return this.g._inner[a];
        }
    }
    getEnumerator() {
        return this.g.getEnumerator();
    }
    getEnumeratorObject() {
        return this.g.getEnumerator();
    }
    contains(a) {
        return this.g.contains(a);
    }
    copyTo(a, b) {
        this.g.copyTo(a, b);
    }
    get count() {
        return this.g.count;
    }
    get isReadOnly() {
        return true;
    }
    indexOf(a) {
        return this.g.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.g = null;
        this.e = false;
        this.d = false;
        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;
        let g = 0;
        let h = this.k;
        let propertyName_ = this._propertyName;
        let sourceItem_ = null;
        if (this.k != null || this.c) {
            for (let i_ = a; i_ < a + b; ++i_) {
                sourceItem_ = source_[i_];
                item_ = (source_[i_][propertyName_]);
                if (this.c) {
                    if ((typeof (item_) == 'function')) {
                        item_ = item_.apply(sourceItem_);
                    }
                }
                if (h != null) {
                    item_ = h(item_);
                }
                f = item_ == null ? (new Date()) : item_;
                if (!this.e) {
                    d = f;
                    this.e = true;
                }
                else if (f < d) {
                    d = f;
                }
                if (!this.d) {
                    e = f;
                    this.d = true;
                }
                else if (f > e) {
                    e = f;
                }
                c[g] = f;
                g++;
            }
        }
        else {
            for (let i_ = a; i_ < a + b; ++i_) {
                item_ = (source_[i_][propertyName_]);
                f = item_ == null ? (new Date()) : item_;
                if (!this.e) {
                    d = f;
                    this.e = true;
                }
                else if (f < d) {
                    d = f;
                }
                if (!this.d) {
                    e = f;
                    this.d = true;
                }
                else if (f > e) {
                    e = f;
                }
                c[g] = f;
                g++;
            }
        }
        this.minimum = d;
        this.maximum = e;
        if (this.g == null) {
            this.g = new List$1(Date_$type, 1, c);
        }
        else {
            this.g.t(a, c);
        }
        return true;
    }
    removeRange(a, b) {
        for (let c = a; c < a + b; ++c) {
            if (+(this.item(c)) == +(this.minimum)) {
                this.e = false;
            }
            if (+(this.item(c)) == +(this.maximum)) {
                this.d = false;
            }
        }
        this.g.v(a, b);
        return true;
    }
    n(a, b) {
        if (+a != +(dateMinValue())) {
            if (+b != +(dateMinValue())) {
                this.minimum = b < this.minimum ? b : this.minimum;
                this.maximum = b > this.maximum ? b : this.maximum;
            }
            return;
        }
        this.minimum = b < this.minimum ? b : this.minimum;
        this.maximum = b > this.maximum ? b : this.maximum;
    }
    replaceRange(a, b) {
        let c = false;
        for (let d = 0; d < b; ++d) {
            let e = this.g._inner[a + d];
            let f = this.j(this.b.item(a + d));
            if (+e != +f) {
                this.g._inner[a + d] = f;
                c = true;
                this.n(e, f);
            }
        }
        return c;
    }
    j(a) {
        if (a == null) {
            return dateMinValue();
        }
        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.k != null) {
            a = this.k(a);
        }
        if (a == null) {
            return dateMinValue();
        }
        return a;
    }
    get mayContainUnknowns() {
        return true;
    }
    f() {
        return FastItemColumn.e(this.g, (a, b) => {
            let c = a;
            let d = b;
            if (c < d) {
                return -1;
            }
            if (c > d) {
                return 1;
            }
            return 0;
        });
    }
    asArray() {
        return this.g.asArray();
    }
    getItem(a) {
        return this.item(a);
    }
    static m() {
        TypeRegistrar.register("FastItemDateTimeColumn", FastItemDateTimeColumn.$);
    }
}
FastItemDateTimeColumn.$t = markType(FastItemDateTimeColumn, 'FastItemDateTimeColumn', Base.$, [IFastItemColumnInternal_$type, IFastItemColumn$1_$type.specialize(Date_$type)]);
//# sourceMappingURL=FastItemDateTimeColumn.js.map