/*
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 { CodePageEncoding } from "./CodePageEncoding";
import { Dictionary$2 } from "igniteui-angular-core";
import { String_$type, Array_$type, fromEnum, markType } from "igniteui-angular-core";
import { ArgumentNullException } from "igniteui-angular-core";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { StringBuilder } from "igniteui-angular-core";
import { nullableNotEquals, unwrapNullable } from "igniteui-angular-core";
import { stringToCharArray } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CodePageDoubleByte = /*@__PURE__*/ (() => {
    class CodePageDoubleByte extends CodePageEncoding {
        constructor(a, b) {
            super();
            this._ag = 0;
            this._ae = null;
            this._af = null;
            this._ag = a;
            this._ae = b;
            if (b == null) {
                return;
            }
            if (this._af != null) {
                return;
            }
            this._af = new Dictionary$2(String_$type, Array_$type, 0);
            for (let c of fromEnum(b.keys)) {
                let d = b.item(c);
                for (let e = 0; e < d.length; e++) {
                    let f = d[e];
                    if (nullableNotEquals(f, null) && !this._af.containsKey(f.value)) {
                        this._af.addItem(f.value, [c, e]);
                    }
                }
            }
        }
        get__codePage() {
            return this._ag;
        }
        get _codePage() {
            return this.get__codePage();
        }
        getChars(a, b, c, d, e) {
            if ((a == null) || (d == null)) {
                throw new ArgumentNullException(0, (a == null) ? "bytes are Null" : "chars are Null");
            }
            if ((b < 0) || (c < 0)) {
                throw new ArgumentOutOfRangeException(1, (b < 0) ? "byteIndex is out of Range" : "byteCount is out of Range");
            }
            if ((a.length - b) < c) {
                throw new ArgumentOutOfRangeException(1, "bytes");
            }
            if ((e < 0) || (e > d.length)) {
                throw new ArgumentOutOfRangeException(1, "charIndex");
            }
            if (a.length == 0) {
                return 0;
            }
            if (d.length == 0) {
                return 0;
            }
            let f = 0;
            let g = 0;
            let h = this.getString1(a, b, c);
            let i = stringToCharArray(h);
            for (let k = 0; k < i.length; k++) {
                let j = i[k];
                if (e <= j.charCodeAt(0)) {
                    if (g < d.length) {
                        d[g] = j;
                        g++;
                    }
                    f++;
                }
            }
            return f;
        }
        getMaxByteCount(a) {
            return a * 2;
        }
        getMaxCharCount(a) {
            return a;
        }
        getByteCount(a, b, c) {
            return c;
        }
        getBytes2(a, b, c, d, e) {
            let f = this._af;
            for (let g = b + c; b < g; b++) {
                let h;
                if (((() => { let i = f.tryGetValue(a[b], h); h = i.p1; return i.ret; })()) == false && ((() => { let i = f.tryGetValue('?', h); h = i.p1; return i.ret; })()) == false) {
                    continue;
                }
                if (h[0] == 0) {
                    d[e++] = h[1];
                }
                else {
                    d[e++] = h[0];
                    d[e++] = h[1];
                }
            }
            return c;
        }
        getCharCount1(a, b, c) {
            return c;
        }
        getString1(a, b, c) {
            let d = new StringBuilder(0);
            for (let e = b; e < b + c;) {
                if (this._ae.containsKey(a[e])) {
                    let f = this._ae.item(a[e]);
                    d.k(unwrapNullable(f[a[e + 1]]));
                    e += 2;
                }
                else {
                    let g = this._ae.item(0);
                    d.k(unwrapNullable(g[a[e]]));
                    e++;
                }
            }
            return d.toString();
        }
    }
    CodePageDoubleByte.$t = markType(CodePageDoubleByte, 'CodePageDoubleByte', CodePageEncoding.$);
    return CodePageDoubleByte;
})();
