/*
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 * as tslib_1 from "tslib";
import { Base, FormatException, Type, callStaticConstructors, toNullable, Number_$type, fromEnum, markType } from "igniteui-angular-core";
import { NotImplementedException } from "igniteui-angular-core";
import { Encoding } from "igniteui-angular-core";
import { Buffer } from "igniteui-angular-core";
import { BitConverter } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { EscherSysIndex_$type } from "./EscherSysIndex";
import { Windows1252Encoding } from "./Windows1252Encoding";
import { Windows936Encoding } from "./Windows936Encoding";
import { Windows932Encoding } from "./Windows932Encoding";
import { CultureInfo } from "igniteui-angular-core";
import { Localization } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ArgumentNullException } from "igniteui-angular-core";
import { MemoryStream } from "igniteui-angular-core";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { intDivide, truncate } from "igniteui-angular-core";
import { nullableEquals, nullableNotEquals } from "igniteui-angular-core";
import { intSToU, u32LS, u32BitwiseOr } from "igniteui-angular-core";
import { arrayShallowClone } from "igniteui-angular-core";
import { arrayCopy2 } from "igniteui-angular-core";
import { dateParseExact } from "igniteui-angular-core";
import { dateMinValue } from "igniteui-angular-core";
/**
 * @hidden
 */
var DocCoreUtils = /** @class */ (function (_super) {
    tslib_1.__extends(DocCoreUtils, _super);
    function DocCoreUtils() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    DocCoreUtils.staticInit = function () {
    };
    DocCoreUtils.a = function (a) {
        var b = a.length * 8;
        var c = (b % 512);
        var d = c < 448 ? 448 - c : 960 - c;
        var e = intDivide(d, 8);
        var f = new Array(a.length + e + 8);
        Buffer.c(a, 0, f, 0, a.length);
        f[a.length] = 128;
        Buffer.c(BitConverter.j(b), 0, f, a.length + e, 8);
        return f;
    };
    DocCoreUtils.n = function ($t, a) {
        return new FormatException(1, DocCoreUtils.aa("LE_FormatException_TypeError", $t.typeName, a));
    };
    DocCoreUtils.al = function (a, b, c, d, e, f) {
        c = toNullable(Color.$, null);
        d = toNullable(Number_$type, null);
        e = toNullable(EscherSysIndex_$type, null);
        f = toNullable(Number_$type, null);
        if (nullableEquals(a, null)) {
            return {
                p2: c,
                p3: d,
                p4: e,
                p5: f
            };
        }
        var g = 255;
        if (nullableNotEquals(b, null)) {
            var h = DocCoreUtils.v(b.value);
            g = truncate(DocCoreUtils.w(h * 255));
        }
        var i = a.value;
        var j = (i >>> 24);
        var k = j;
        switch (k) {
            case 1:
                f = toNullable(Number_$type, (i & 65535));
                break;
            case 8:
                d = toNullable(Number_$type, (i & 255));
                break;
            case 16:
                e = toNullable(EscherSysIndex_$type, (i & 16777215));
                break;
            default:
                var l = (i & 255);
                var m = ((i & 65280) >>> 8);
                var n = ((i & 16711680) >>> 16);
                c = toNullable(Color.$, Color.u(g, l, m, n));
                break;
        }
        return {
            p2: c,
            p3: d,
            p4: e,
            p5: f
        };
    };
    DocCoreUtils.v = function (a) {
        var b = (a >>> 16);
        var c = (a & 65535);
        return b + (c / 65536);
    };
    DocCoreUtils.am = function (a, b, c, d, e, f) {
        e = toNullable(Number_$type, null);
        f = toNullable(Number_$type, null);
        if (a.hasValue) {
            e = toNullable(Number_$type, intSToU(((a.value.m << 16) | (a.value.n << 8) | a.value.o)));
            var g = a.value.l;
            if (g != 255) {
                var h = g / 255;
                f = toNullable(Number_$type, DocCoreUtils.ah(h));
            }
            return {
                p4: e,
                p5: f
            };
        }
        if (nullableNotEquals(b, null)) {
            var i = u32LS(8, 24);
            e = toNullable(Number_$type, u32BitwiseOr(i, b.value));
            return {
                p4: e,
                p5: f
            };
        }
        if (nullableNotEquals(c, null)) {
            var j = u32LS(16, 24);
            e = toNullable(Number_$type, u32BitwiseOr(j, c.value));
            return {
                p4: e,
                p5: f
            };
        }
        if (nullableNotEquals(d, null)) {
            var k = u32LS(1, 24);
            e = toNullable(Number_$type, u32BitwiseOr(k, d.value));
            return {
                p4: e,
                p5: f
            };
        }
        return {
            p4: e,
            p5: f
        };
    };
    DocCoreUtils.ah = function (a) {
        var b = DocCoreUtils.l(a);
        var c = truncate(b);
        b = Math.abs(a % 1) * 65536;
        var d = truncate(DocCoreUtils.j(b));
        return intSToU((c << 16)) + d;
    };
    DocCoreUtils.aj = function (a, b) {
        if (b === void 0) { b = null; }
        if (DocCoreUtils.f) {
            return;
        }
    };
    DocCoreUtils.ak = function (a) {
        if (DocCoreUtils.f) {
            return;
        }
    };
    DocCoreUtils.an = function ($t, a, b) {
        var e_1, _a;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                b(c);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
    };
    DocCoreUtils.i = function (a) {
        return (a * 20) / 12700;
    };
    DocCoreUtils.ae = function (a) {
        switch (a) {
            case 1200: return Encoding.unicode;
            case 1201: return Encoding.bigEndianUnicode;
            case 65001: return Encoding.uTF8;
            case 1252: return new Windows1252Encoding();
            case 936: return new Windows936Encoding();
            case 932: return new Windows932Encoding();
            default: return Encoding.uTF8;
        }
    };
    DocCoreUtils.q = function (a) {
        if (a == Encoding.unicode) {
            return 1200;
        }
        if (a == Encoding.bigEndianUnicode) {
            return 1201;
        }
        if (a == Encoding.uTF8) {
            return 65001;
        }
        return 0;
    };
    DocCoreUtils.x = function (a) {
        try {
            var b = a.webName;
            return b;
        }
        catch (c) {
            return DocCoreUtils.q(a).toString();
        }
    };
    DocCoreUtils.o = function (a) {
        return CultureInfo.currentCulture;
    };
    DocCoreUtils.r = function (a) {
        if ('0'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= '9'.charCodeAt(0)) {
            return a.charCodeAt(0) - '0'.charCodeAt(0);
        }
        if ('a'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= 'f'.charCodeAt(0)) {
            return (a.charCodeAt(0) - 'a'.charCodeAt(0)) + 10;
        }
        if ('A'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= 'F'.charCodeAt(0)) {
            return (a.charCodeAt(0) - 'A'.charCodeAt(0)) + 10;
        }
        return 0;
    };
    DocCoreUtils.z = function (a) {
        return Localization.getString("documentsCore", a);
    };
    DocCoreUtils.aa = function (a) {
        var b = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            b[_i - 1] = arguments[_i];
        }
        return Localization.getString.apply(Localization, tslib_1.__spread(["documentsCore", a], b));
    };
    DocCoreUtils.d = function (a) {
        return ('0'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= '9'.charCodeAt(0)) || ('a'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= 'f'.charCodeAt(0)) || ('A'.charCodeAt(0) <= a.charCodeAt(0) && a.charCodeAt(0) <= 'F'.charCodeAt(0));
    };
    DocCoreUtils.e = function (a) {
        return a == null;
    };
    DocCoreUtils.ao = function (a, b, c) {
        if (b === void 0) { b = 40; }
        if (c === void 0) { c = "Global"; }
    };
    DocCoreUtils.w = function (a) {
        return DocCoreUtils.k(a, 0);
    };
    DocCoreUtils.j = function (a) {
        return DocCoreUtils.k(a, 0);
    };
    DocCoreUtils.k = function (a, b) {
        if (b < 0 || b > 15) {
            var c = Math.pow(10, b);
            var d = Math.sign(a);
            return DocCoreUtils.l(a * c + 0.5 * d) / c;
        }
        if (Math.abs(a) < 1E+16) {
            var e = DocCoreUtils.b[b];
            a *= e;
            var f = a % 1;
            a = DocCoreUtils.l(a);
            if (Math.abs(f) >= 0.5) {
                a += Math.sign(f);
            }
            a /= e;
        }
        return a;
    };
    DocCoreUtils.ai = function (a, b) {
        return u32BitwiseOr((a >>> (32 - b)), (u32LS(a, b)));
    };
    DocCoreUtils.s = function (a, b) {
        return a + b - 1 - ((a - 1) % b);
    };
    DocCoreUtils.ar = function ($t, a, b) {
        var c = a.toArray();
        DocCoreUtils.ap($t, c, null, b);
        a.clear();
        a.o(c);
    };
    DocCoreUtils.ap = function ($t, a, b, c) {
        DocCoreUtils.aq($t, a, b, c, 0, a.length - 1);
    };
    DocCoreUtils.aq = function ($t, a, b, c, d, e) {
        if (a == null) {
            throw new ArgumentNullException(0, "arr");
        }
        if (c == null) {
            throw new ArgumentNullException(0, "comparer");
        }
        if (null == b) {
            b = arrayShallowClone(a);
        }
        else {
            arrayCopy2(a, b, a.length);
        }
        DocCoreUtils.as($t, a, b, c, d, e);
    };
    DocCoreUtils.as = function ($t, a, b, c, d, e) {
        var f, g, h, i;
        var j = Type.getDefaultValue($t), k = Type.getDefaultValue($t);
        if (e - d < 6) {
            for (f = 1 + d; f <= e; f++) {
                j = a[f];
                for (g = f; g > d; g--) {
                    k = a[g - 1];
                    if (c.compare(j, k) < 0) {
                        a[g] = k;
                    }
                    else {
                        break;
                    }
                }
                if (f != g) {
                    a[g] = j;
                }
            }
            return;
        }
        i = intDivide((d + e), 2);
        DocCoreUtils.as($t, b, a, c, d, i);
        DocCoreUtils.as($t, b, a, c, 1 + i, e);
        for (f = d, g = 1 + i, h = d; h <= e; h++) {
            if (f <= i) {
                j = b[f];
            }
            if (g <= e) {
                k = b[g];
            }
            if (g > e || f <= i && c.compare(j, k) <= 0) {
                a[h] = j;
                f++;
            }
            else {
                a[h] = k;
                g++;
            }
        }
    };
    DocCoreUtils.c = function (a) {
        if (a.canSeek) {
            var b = new Array(a.length);
            a.read(b, 0, b.length);
            return b;
        }
        var c = new Array(16 * 1024);
        {
            var d = new MemoryStream(0);
            try {
                var e = void 0;
                while ((e = a.read(c, 0, c.length)) > 0) {
                    d.write(c, 0, e);
                }
                return d.toArray();
            }
            finally {
                if (d != null) {
                    d.dispose();
                }
            }
        }
    };
    DocCoreUtils.at = function ($t, a, b) {
        var c = a;
        a = b;
        b = c;
        return {
            p0: a,
            p1: b
        };
    };
    DocCoreUtils.l = function (a) {
        if (a < 0) {
            return Math.ceil(a);
        }
        return Math.floor(a);
    };
    DocCoreUtils.u = function (a, b, c) {
        c = null;
        return {
            ret: null,
            p2: c
        };
    };
    DocCoreUtils.g = function (a, b, c, d) {
        try {
            d = dateParseExact(a, b, c);
            return {
                ret: true,
                p3: d
            };
        }
        catch (e) {
            d = dateMinValue();
            return {
                ret: false,
                p3: d
            };
        }
    };
    DocCoreUtils.t = function (a) {
        return truncate(DocCoreUtils.j((a / 20) * 12700));
    };
    DocCoreUtils.au = function (a, b) {
        if (a == null) {
            throw new ArgumentNullException(0, b);
        }
    };
    DocCoreUtils.av = function ($t, a, b, c, d) {
        if (c <= a && a <= d) {
            return;
        }
        var e = DocCoreUtils.aa("LE_ArgumentOutOfRangeException_ValueError", $t.typeName, c, d);
        throw new ArgumentOutOfRangeException(2, b, e);
    };
    Object.defineProperty(DocCoreUtils, "p", {
        get: function () {
            throw new NotImplementedException(0);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(DocCoreUtils, "ad", {
        get: function () {
            return Encoding.defaultValue;
        },
        enumerable: true,
        configurable: true
    });
    DocCoreUtils.y = function (a) {
        return null;
    };
    DocCoreUtils.ab = function (a, b) {
        return a.getString1(b, 0, b.length);
    };
    DocCoreUtils.af = function (a, b) {
        return DocCoreUtils.ae(b);
    };
    DocCoreUtils.ac = function (a) {
        var b = new List$1(Number_$type, 0);
        while (true) {
            var c = a.readByte();
            var d = a.readByte();
            if (c == 0 && d == 0) {
                break;
            }
            b.add(c);
            b.add(d);
        }
        return Encoding.unicode.getString(b.toArray());
    };
    DocCoreUtils.aw = function (a, b) {
        a.h(Encoding.unicode.getBytes1(b));
        a.m(0);
        a.m(0);
    };
    DocCoreUtils.$t = markType(DocCoreUtils, 'DocCoreUtils');
    DocCoreUtils.b = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1E+15];
    DocCoreUtils.f = false;
    return DocCoreUtils;
}(Base));
export { DocCoreUtils };
(function (v) { callStaticConstructors(); })(true);
//# sourceMappingURL=DocCoreUtils.js.map