/*
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 { ValueType, toNullable, typeCast, Number_$type, markStruct } from "igniteui-angular-core";
import { DocCoreUtils } from "./DocCoreUtils";
import { CultureInfo } from "igniteui-angular-core";
import { truncate } from "igniteui-angular-core";
import { numberToString, tryParseInt32_2, tryParseNumber1 } from "igniteui-angular-core";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
 * @hidden
 */
export class ST_Percentage extends ValueType {
    constructor(a, ..._rest) {
        super();
        this.k = 0;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    let c = _rest[0];
                    this.k = c;
                }
                break;
        }
    }
    equals(a) {
        let b = toNullable(ST_Percentage.$, typeCast(ST_Percentage.$, a));
        if (ST_Percentage.h(b, toNullable(ST_Percentage.$, null))) {
            return false;
        }
        return ST_Percentage.e(this, b.getValueOrDefault());
    }
    getHashCode() {
        return (this.k);
    }
    toString() {
        return this.r(1);
    }
    r(a) {
        let t1 = a;
        L0: while (true) {
            switch (t1) {
                case 0: return truncate(DocCoreUtils.j(this.k * 1000)).toString();
                case 1: return numberToString(this.k, CultureInfo.invariantCulture) + "%";
                default:
                    t1 = 0;
                    continue L0;
            }
            break;
        }
    }
    static d(a, b) {
        let c = ST_Percentage.q(a, b);
        if (ST_Percentage.h(c, toNullable(ST_Percentage.$, null))) {
            return c.getValueOrDefault();
        }
        throw DocCoreUtils.n(ST_Percentage.$, a);
    }
    static q(a, b) {
        if (stringIsNullOrEmpty(a)) {
            return toNullable(ST_Percentage.$, null);
        }
        let t1 = b;
        L0: while (true) {
            switch (t1) {
                case 0:
                    {
                        if (a.charAt(a.length - 1) == '%') {
                            t1 = 1;
                            continue L0;
                        }
                        let c;
                        if (((() => { let d = tryParseInt32_2(a, 7, CultureInfo.invariantCulture, c); c = d.p3; return d.ret; })()) == false) {
                            return toNullable(ST_Percentage.$, null);
                        }
                        return toNullable(ST_Percentage.$, new ST_Percentage(1, c / 1000));
                    }
                case 1:
                    {
                        if (a.charAt(a.length - 1) != '%') {
                            t1 = 0;
                            continue L0;
                        }
                        let d;
                        if (((() => { let e = tryParseNumber1(a.substr(0, a.length - 1), 167 | 64, CultureInfo.invariantCulture, d); d = e.p3; return e.ret; })()) == false) {
                            return toNullable(ST_Percentage.$, null);
                        }
                        return toNullable(ST_Percentage.$, ST_Percentage.b(d));
                    }
                default: return toNullable(ST_Percentage.$, null);
            }
            break;
        }
    }
    static n(a) {
        return a.k / 100;
    }
    static a(a) {
        return new ST_Percentage(1, a * 100);
    }
    static e(a, b) {
        return a.k == b.k;
    }
    static f(a, b) {
        if (!a.hasValue) {
            return !b.hasValue;
        }
        else if (!b.hasValue) {
            return false;
        }
        return ST_Percentage.e(a.value, b.value);
    }
    static g(a, b) {
        return !(ST_Percentage.e(a, b));
    }
    static h(a, b) {
        if (!a.hasValue) {
            return b.hasValue;
        }
        else if (!b.hasValue) {
            return true;
        }
        return ST_Percentage.g(a.value, b.value);
    }
    static b(a) {
        return new ST_Percentage(1, a);
    }
    static p(a) {
        if (!a.hasValue) {
            return toNullable(ST_Percentage.$, null);
        }
        return toNullable(ST_Percentage.$, ST_Percentage.b(a.value));
    }
    static l(a) {
        return a.k;
    }
    static o(a) {
        if (!a.hasValue) {
            return toNullable(Number_$type, null);
        }
        return toNullable(Number_$type, ST_Percentage.l(a.value));
    }
}
ST_Percentage.$t = markStruct(ST_Percentage, 'ST_Percentage');
//# sourceMappingURL=ST_Percentage.js.map