package com.google.zxing.qrcode.decoder;

import com.google.android.gms.dynamite.descriptors.com.google.android.gms.measurement.dynamite.ModuleDescriptor;
import fl.l;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

/* loaded from: classes3.dex */
abstract class d {

    /* renamed from: a, reason: collision with root package name */
    private static final char[] f15266a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:".toCharArray();

    /* loaded from: classes3.dex */
    static /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f15267a;

        static {
            int[] iArr = new int[h.values().length];
            f15267a = iArr;
            try {
                iArr[h.NUMERIC.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f15267a[h.ALPHANUMERIC.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f15267a[h.BYTE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f15267a[h.KANJI.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f15267a[h.TERMINATOR.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f15267a[h.FNC1_FIRST_POSITION.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f15267a[h.FNC1_SECOND_POSITION.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                f15267a[h.STRUCTURED_APPEND.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                f15267a[h.ECI.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                f15267a[h.HANZI.ordinal()] = 10;
            } catch (NoSuchFieldError unused10) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to find 'out' block for switch in B:8:0x003a. Please report as an issue. */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:25:0x00d8 A[LOOP:0: B:2:0x001e->B:25:0x00d8, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x00b7 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static fl.e a(byte[] bArr, j jVar, f fVar, Map map) {
        h hVar;
        int i10;
        fl.c cVar = new fl.c(bArr);
        StringBuilder sb2 = new StringBuilder(50);
        int i11 = 1;
        ArrayList arrayList = new ArrayList(1);
        int i12 = -1;
        int i13 = -1;
        boolean z10 = 0;
        fl.d dVar = null;
        while (true) {
            try {
                h forBits = cVar.a() < 4 ? h.TERMINATOR : h.forBits(cVar.d(4));
                int[] iArr = a.f15267a;
                int i14 = z10;
                switch (iArr[forBits.ordinal()]) {
                    case 5:
                        hVar = forBits;
                        i10 = i14;
                        if (hVar != h.TERMINATOR) {
                            return new fl.e(bArr, sb2.toString(), arrayList.isEmpty() ? null : arrayList, fVar == null ? null : fVar.toString(), i12, i13);
                        }
                        i11 = 1;
                        z10 = i10;
                    case 6:
                    case 7:
                        i14 = i11;
                        hVar = forBits;
                        i10 = i14;
                        if (hVar != h.TERMINATOR) {
                        }
                        break;
                    case 8:
                        if (cVar.a() < 16) {
                            throw yk.h.a();
                        }
                        int d10 = cVar.d(8);
                        i13 = cVar.d(8);
                        i12 = d10;
                        i14 = z10;
                        hVar = forBits;
                        i10 = i14;
                        if (hVar != h.TERMINATOR) {
                        }
                        break;
                    case 9:
                        dVar = fl.d.getCharacterSetECIByValue(g(cVar));
                        if (dVar == null) {
                            throw yk.h.a();
                        }
                        i14 = z10;
                        hVar = forBits;
                        i10 = i14;
                        if (hVar != h.TERMINATOR) {
                        }
                        break;
                    case 10:
                        int d11 = cVar.d(4);
                        int d12 = cVar.d(forBits.getCharacterCountBits(jVar));
                        i14 = z10;
                        if (d11 == i11) {
                            d(cVar, sb2, d12);
                            i14 = z10;
                        }
                        hVar = forBits;
                        i10 = i14;
                        if (hVar != h.TERMINATOR) {
                        }
                        break;
                    default:
                        int d13 = cVar.d(forBits.getCharacterCountBits(jVar));
                        int i15 = iArr[forBits.ordinal()];
                        if (i15 == i11) {
                            hVar = forBits;
                            f(cVar, sb2, d13);
                            i10 = z10;
                        } else if (i15 == 2) {
                            hVar = forBits;
                            b(cVar, sb2, d13, z10);
                            i10 = z10;
                        } else if (i15 == 3) {
                            hVar = forBits;
                            c(cVar, sb2, d13, dVar, arrayList, map);
                            i10 = z10;
                        } else {
                            if (i15 != 4) {
                                throw yk.h.a();
                            }
                            e(cVar, sb2, d13);
                            i14 = z10;
                            hVar = forBits;
                            i10 = i14;
                        }
                        if (hVar != h.TERMINATOR) {
                        }
                        break;
                }
            } catch (IllegalArgumentException unused) {
                throw yk.h.a();
            }
        }
    }

    private static void b(fl.c cVar, StringBuilder sb2, int i10, boolean z10) {
        while (i10 > 1) {
            if (cVar.a() < 11) {
                throw yk.h.a();
            }
            int d10 = cVar.d(11);
            sb2.append(h(d10 / 45));
            sb2.append(h(d10 % 45));
            i10 -= 2;
        }
        if (i10 == 1) {
            if (cVar.a() < 6) {
                throw yk.h.a();
            }
            sb2.append(h(cVar.d(6)));
        }
        if (z10) {
            for (int length = sb2.length(); length < sb2.length(); length++) {
                if (sb2.charAt(length) == '%') {
                    if (length < sb2.length() - 1) {
                        int i11 = length + 1;
                        if (sb2.charAt(i11) == '%') {
                            sb2.deleteCharAt(i11);
                        }
                    }
                    sb2.setCharAt(length, (char) 29);
                }
            }
        }
    }

    private static void c(fl.c cVar, StringBuilder sb2, int i10, fl.d dVar, Collection collection, Map map) {
        if ((i10 << 3) > cVar.a()) {
            throw yk.h.a();
        }
        byte[] bArr = new byte[i10];
        for (int i11 = 0; i11 < i10; i11++) {
            bArr[i11] = (byte) cVar.d(8);
        }
        try {
            sb2.append(new String(bArr, dVar == null ? l.a(bArr, map) : dVar.name()));
            collection.add(bArr);
        } catch (UnsupportedEncodingException unused) {
            throw yk.h.a();
        }
    }

    private static void d(fl.c cVar, StringBuilder sb2, int i10) {
        if (i10 * 13 > cVar.a()) {
            throw yk.h.a();
        }
        byte[] bArr = new byte[i10 * 2];
        int i11 = 0;
        while (i10 > 0) {
            int d10 = cVar.d(13);
            int i12 = (d10 % 96) | ((d10 / 96) << 8);
            int i13 = i12 + (i12 < 2560 ? 41377 : 42657);
            bArr[i11] = (byte) (i13 >> 8);
            bArr[i11 + 1] = (byte) i13;
            i11 += 2;
            i10--;
        }
        try {
            sb2.append(new String(bArr, "GB2312"));
        } catch (UnsupportedEncodingException unused) {
            throw yk.h.a();
        }
    }

    private static void e(fl.c cVar, StringBuilder sb2, int i10) {
        if (i10 * 13 > cVar.a()) {
            throw yk.h.a();
        }
        byte[] bArr = new byte[i10 * 2];
        int i11 = 0;
        while (i10 > 0) {
            int d10 = cVar.d(13);
            int i12 = (d10 % 192) | ((d10 / 192) << 8);
            int i13 = i12 + (i12 < 7936 ? 33088 : 49472);
            bArr[i11] = (byte) (i13 >> 8);
            bArr[i11 + 1] = (byte) i13;
            i11 += 2;
            i10--;
        }
        try {
            sb2.append(new String(bArr, "SJIS"));
        } catch (UnsupportedEncodingException unused) {
            throw yk.h.a();
        }
    }

    private static void f(fl.c cVar, StringBuilder sb2, int i10) {
        while (i10 >= 3) {
            if (cVar.a() < 10) {
                throw yk.h.a();
            }
            int d10 = cVar.d(10);
            if (d10 >= 1000) {
                throw yk.h.a();
            }
            sb2.append(h(d10 / 100));
            sb2.append(h((d10 / 10) % 10));
            sb2.append(h(d10 % 10));
            i10 -= 3;
        }
        if (i10 == 2) {
            if (cVar.a() < 7) {
                throw yk.h.a();
            }
            int d11 = cVar.d(7);
            if (d11 >= 100) {
                throw yk.h.a();
            }
            sb2.append(h(d11 / 10));
            sb2.append(h(d11 % 10));
            return;
        }
        if (i10 == 1) {
            if (cVar.a() < 4) {
                throw yk.h.a();
            }
            int d12 = cVar.d(4);
            if (d12 >= 10) {
                throw yk.h.a();
            }
            sb2.append(h(d12));
        }
    }

    private static int g(fl.c cVar) {
        int d10 = cVar.d(8);
        if ((d10 & 128) == 0) {
            return d10 & ModuleDescriptor.MODULE_VERSION;
        }
        if ((d10 & 192) == 128) {
            return cVar.d(8) | ((d10 & 63) << 8);
        }
        if ((d10 & 224) == 192) {
            return cVar.d(16) | ((d10 & 31) << 16);
        }
        throw yk.h.a();
    }

    private static char h(int i10) {
        char[] cArr = f15266a;
        if (i10 < cArr.length) {
            return cArr[i10];
        }
        throw yk.h.a();
    }
}
