/*
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 { __extends } from "tslib";
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
 */
var ST_Percentage = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ST_Percentage, _super);
    function ST_Percentage(a) {
        var _rest = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            _rest[_i - 1] = arguments[_i];
        }
        var _this = _super.call(this) || this;
        _this.k = 0;
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0: break;
            case 1:
                {
                    var c = _rest[0];
                    _this.k = c;
                }
                break;
        }
        return _this;
    }
    ST_Percentage.prototype.equals = function (a) {
        var 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());
    };
    ST_Percentage.prototype.getHashCode = function () {
        return (this.k);
    };
    ST_Percentage.prototype.toString = function () {
        return this.r(1);
    };
    ST_Percentage.prototype.r = function (a) {
        var 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;
        }
    };
    ST_Percentage.d = function (a, b) {
        var c = ST_Percentage.q(a, b);
        if (ST_Percentage.h(c, toNullable(ST_Percentage.$, null))) {
            return c.getValueOrDefault();
        }
        throw DocCoreUtils.n(ST_Percentage.$, a);
    };
    ST_Percentage.q = function (a, b) {
        if (stringIsNullOrEmpty(a)) {
            return toNullable(ST_Percentage.$, null);
        }
        var t1 = b;
        var _loop_1 = function () {
            switch (t1) {
                case 0:
                    {
                        if (a.charAt(a.length - 1) == '%') {
                            t1 = 1;
                            return "continue-L0";
                        }
                        var c_1;
                        if (((function () { var d = tryParseInt32_2(a, 7, CultureInfo.invariantCulture, c_1); c_1 = d.p3; return d.ret; })()) == false) {
                            return { value: toNullable(ST_Percentage.$, null) };
                        }
                        return { value: toNullable(ST_Percentage.$, new ST_Percentage(1, c_1 / 1000)) };
                    }
                case 1:
                    {
                        if (a.charAt(a.length - 1) != '%') {
                            t1 = 0;
                            return "continue-L0";
                        }
                        var d_1;
                        if (((function () { var e = tryParseNumber1(a.substr(0, a.length - 1), 167 | 64, CultureInfo.invariantCulture, d_1); d_1 = e.p3; return e.ret; })()) == false) {
                            return { value: toNullable(ST_Percentage.$, null) };
                        }
                        return { value: toNullable(ST_Percentage.$, ST_Percentage.b(d_1)) };
                    }
                default: return { value: toNullable(ST_Percentage.$, null) };
            }
            return "break";
        };
        L0: while (true) {
            var state_1 = _loop_1();
            if (typeof state_1 === "object")
                return state_1.value;
            if (state_1 === "break")
                break;
            switch (state_1) {
                case "continue-L0": continue L0;
            }
        }
    };
    ST_Percentage.n = function (a) {
        return a.k / 100;
    };
    ST_Percentage.a = function (a) {
        return new ST_Percentage(1, a * 100);
    };
    ST_Percentage.e = function (a, b) {
        return a.k == b.k;
    };
    ST_Percentage.f = function (a, b) {
        if (!a.hasValue) {
            return !b.hasValue;
        }
        else if (!b.hasValue) {
            return false;
        }
        return ST_Percentage.e(a.value, b.value);
    };
    ST_Percentage.g = function (a, b) {
        return !(ST_Percentage.e(a, b));
    };
    ST_Percentage.h = function (a, b) {
        if (!a.hasValue) {
            return b.hasValue;
        }
        else if (!b.hasValue) {
            return true;
        }
        return ST_Percentage.g(a.value, b.value);
    };
    ST_Percentage.b = function (a) {
        return new ST_Percentage(1, a);
    };
    ST_Percentage.p = function (a) {
        if (!a.hasValue) {
            return toNullable(ST_Percentage.$, null);
        }
        return toNullable(ST_Percentage.$, ST_Percentage.b(a.value));
    };
    ST_Percentage.l = function (a) {
        return a.k;
    };
    ST_Percentage.o = function (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');
    return ST_Percentage;
}(ValueType));
export { ST_Percentage };
