/*
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 { Snapper } from "./Snapper";
import { markType } from "igniteui-react-core/ES2015/type";
import { truncate, log10 } from "igniteui-react-core/ES2015/number";
/**
 * @hidden
 */
export class LinearNumericSnapper extends Snapper {
    constructor(a, ..._rest) {
        super();
        this.g = 0;
        this.j = 0;
        this.i = 0;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0:
                {
                    let c = _rest[0];
                    let d = _rest[1];
                    let e = _rest[2];
                    let f = _rest[3];
                    if (f > 0) {
                        this.f = f;
                        this.b = true;
                    }
                    this.k(c, d, e, 10);
                }
                break;
            case 1:
                {
                    let c = _rest[0];
                    let d = _rest[1];
                    let e = _rest[2];
                    let f = _rest[3];
                    let g = _rest[4];
                    if (g > 0) {
                        this.f = g;
                        this.b = true;
                    }
                    this.k(c, d, e, f);
                }
                break;
        }
    }
    k(a, b, c, d) {
        this.g = NaN;
        this.j = 0;
        this.i = 0;
        let e = 0;
        if (c < 100) {
            e = 4;
        }
        else {
            e = Math.min(d, truncate((c / this.f)));
        }
        if (e > 0) {
            let f = this.h(a, b, e);
            if (this.b && f > e) {
                this.g = NaN;
                f = this.h(a, b, e - 1);
            }
            e = f;
            if (c / e > this.f * 10) {
                this.i = 10;
            }
            else {
                if (c / e > this.f * 5) {
                    this.i = 5;
                }
                else {
                    if (c / e > this.f * 2) {
                        this.i = 2;
                    }
                }
            }
            this.j = Math.max(-truncate(Math.floor(log10(this.g))), 0);
        }
    }
    h(a, b, c) {
        let d = Snapper.e(b - a, false);
        this.g = Snapper.e(d / (c - 1), true);
        let e = Math.floor(a / this.g) * this.g;
        let f = Math.ceil(b / this.g) * this.g;
        let g = truncate(Math.round((f - e) / this.g));
        return g;
    }
}
LinearNumericSnapper.$t = markType(LinearNumericSnapper, 'LinearNumericSnapper', Snapper.$);
