/*
 * Decompiled with CFR 0.152.
 */
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;

public final class gg
extends ep {
    private static final String E;
    private static final String F;
    private static final String G;
    private static final String H;
    private static final String I;
    public static final String c;
    public static final String e;
    public static final String d;
    public static final String f;
    public static final String g;
    public static final String h;
    private final int B;
    private final int C;
    private final ff j;
    private final gd m;
    private final lh n;
    private final w u;
    private final w v;
    private final w w;
    private static lh D;
    private hx l;
    private hc o;
    private ht[] A = null;
    private int J = 0;
    private mo i;
    private ft k;
    private long p;
    private int x;
    private int y;
    private Vector z = new Vector(0);
    public mo a;
    public int b;

    private int t() {
        return this.l.a();
    }

    private int u() {
        return ps.a(this.l, this.l.r());
    }

    public final void b() {
        this.k = null;
        this.l = null;
    }

    private int a(int n) {
        this.b = n;
        this.s();
        return n;
    }

    private void g(int n) {
        this.a(4);
        this.a.m(n);
        this.j.b(this.a);
    }

    public final void a(ht ht2) {
        this.k.a(ht2, 0, 0);
        this.n.a(ht2);
    }

    private jp a(String string, boolean bl2) {
        return dz.a(this.l, string, bl2, this.s.k);
    }

    private static String p() {
        return ed.a(h, ku.b());
    }

    private static void b(String string) {
        me.a((short)56, "ir", string);
    }

    private static void a(String string) {
        me.a((short)4, "sa", string);
    }

    private static void a(String string, String string2, String string3) {
        me.a((short)4, "o", me.a(new String[]{"a=" + string, "o=" + string2, "v=" + string3}));
    }

    public gg(eb eb2, ff ff2, lh lh2, gd gd2) {
        super(eb2, null);
        this.n = lh2;
        this.m = gd2;
        this.B = D.b("NextKey", 54);
        this.C = D.b("PrevKey", 52);
        this.j = ff2;
        this.u = jj.a(false);
        this.v = jj.a();
        this.w = jj.b(false);
        this.b = 1;
    }

    private void h(int n) {
        this.i = this.a;
        this.a = ((gc)this.i).g();
        this.a.p = this.i.p;
        this.a.q = this.i.q;
        this.a.r = n;
        this.a(3);
    }

    public final void a() {
        int n = this.a.x;
        if (n != -1) {
            this.x = this.b(n);
            this.o();
            this.g(n);
            return;
        }
        if (!(this.a instanceof by)) {
            this.a(1);
            return;
        }
        this.o();
        this.g(0);
    }

    public final void g_() {
        if (this.t) {
            int n = -1;
            if (this.l != null) {
                n = this.l.g(this.l.q());
            }
            this.s();
            if (n != -1) {
                this.l.l(this.l.h(n));
            }
        }
    }

    private void i(int n) {
        if (n != 0) {
            this.l.l(dz.a((fs)this.l, n));
            return;
        }
        this.l.s();
    }

    public final boolean a(boolean bl2) {
        if (this.b == 1 && this.o != null && Math.abs(System.currentTimeMillis() - this.p) > (long)10000) {
            this.p = System.currentTimeMillis();
            this.o.a(gg.p());
        }
        return this.a(this.k);
    }

    public final int a(nj nj2) {
        switch (this.k.b(nj2)) {
            case -3: {
                return this.a(pb.a(7));
            }
            default: {
                return 4;
            }
            case -2: 
        }
        return 3;
    }

    private static boolean a(int n, int n2) {
        return n > 480 || n2 > 666;
    }

    public final boolean m() {
        return this.b == 2 || this.b == 3;
    }

    public final boolean g() {
        return this.b == 0 || this.b == 3 || this.b == 4 || this.b == 5;
    }

    private int b(int n) {
        int n2 = this.a.r() ? 1 : 0;
        return n + n2;
    }

    public final cq d() {
        switch (this.b) {
            default: {
                return null;
            }
            case 1: 
            case 2: 
        }
        return jy.g;
    }

    public final cq e() {
        switch (this.b) {
            default: {
                if (!lh.t()) {
                    return jy.c;
                }
                return null;
            }
            case 2: 
        }
        return jy.d;
    }

    static {
        D = lh.k();
        c = lh.d(306);
        d = lh.d(35);
        String string = !lh.t() ? lh.d(537) : lh.d(549);
        e = string;
        string = !lh.t() ? lh.d(538) : lh.d(550);
        f = string;
        g = lh.d(560);
        h = lh.d(38);
        E = lh.d(479);
        F = lh.d(90);
        G = lh.d(328);
        H = lh.d(331);
        I = lh.d(391);
    }

    public final void l() {
        aa aa2 = D.f();
        if (!this.t && !this.j.h()) {
            aa2.b("PROTO_SAVED_DIRECTIONS_DB");
            return;
        }
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            this.a.b(new DataOutputStream(byteArrayOutputStream));
            aa2.b(byteArrayOutputStream.toByteArray(), "PROTO_SAVED_DIRECTIONS_DB");
            return;
        }
        catch (IOException iOException) {
            return;
        }
        catch (OutOfMemoryError outOfMemoryError) {
            me.b("UI-DL save", outOfMemoryError);
            return;
        }
    }

    public static mo a(fu fu2) {
        Object object = D.f();
        if (gu.g().t()) {
            object.a("SAVED_DIRECTIONS", null);
            object.b("SAVED_DIRECTIONS_DB");
        }
        if ((object = nz.a((aa)object, "PROTO_SAVED_DIRECTIONS_DB")) != null) {
            try {
                mo mo2 = mo.a((DataInput)object, fu2);
                if (mo2 instanceof by) {
                    mo2.w();
                }
                return mo2;
            }
            catch (IOException iOException) {
                me.a("UI-TDW", iOException);
            }
        }
        return null;
    }

    public final void a(mo mo2) {
        if (mo2.d) {
            this.m.d(null);
        }
        if (mo2.b == 6) {
            if (this.i != null) {
                mo2.a(this.i);
                mo2 = this.i;
            }
            if (mo2.r >= 0) {
                this.n.b(H);
            } else {
                this.n.b(G);
            }
        }
        this.i = null;
        this.a = mo2;
        if (mo2.J()) {
            ff.b("ha");
        }
        if (mo2.l != null) {
            gg.b("sa");
        }
        if (mo2.n != null) {
            gg.b("ea");
        }
        if (mo2.C.length > 0) {
            gg.a("a", "", "");
        }
        this.z = gu.d().b(mo2.C);
        this.x = this.b(0);
        this.y = 0;
    }

    private void v() {
        lk lk2;
        int n;
        lk[] lkArray = new lk[this.A.length];
        for (n = 0; n < lkArray.length; ++n) {
            lkArray[n] = this.A[n].a();
        }
        boolean bl2 = false;
        lk[] lkArray2 = this.a.D;
        Hashtable<Integer, Integer> hashtable = new Hashtable<Integer, Integer>();
        for (n = 0; n < lkArray2.length; ++n) {
            lk2 = lkArray2[n];
            hashtable.put(new Integer(lk2.d(1)), new Integer(lk2.d(2)));
        }
        for (n = 0; n < lkArray.length; ++n) {
            lk2 = lkArray[n];
            Integer n2 = new Integer(lk2.d(1));
            Integer n3 = new Integer(lk2.d(2));
            if (hashtable.containsKey(n2) && hashtable.get(n2).equals(n3)) continue;
            bl2 = true;
            gg.a("c", n2.toString(), n3.toString());
        }
        if (!bl2) {
            gg.a("nc", "", "");
        }
        this.a.D = lkArray;
        this.a.p();
    }

    /*
     * Unable to fully structure code
     */
    public final int a(pb var1_1) {
        block23: {
            this.n.b((String)null);
            var2_2 = ps.a(this.l, this.l.r());
            switch (this.b) {
                case 2: {
                    this.y = var2_2;
                    break;
                }
                case 1: {
                    this.x = var2_2;
                }
            }
            if (var1_1.c != 8) break block23;
            if (this.b != 2) {
                gg.a("b");
            } else {
                gg.a("nc", "", "");
            }
            switch (this.b) {
                case 2: {
                    var2_2 = 1;
                    break;
                }
                default: {
                    var2_2 = 1;
                    break;
                }
                case 1: {
                    var2_2 = 0;
                }
            }
            this.a(var2_2);
            if (this.b == 0) ** GOTO lbl47
        }
        if (var1_1.c == 6 && this.b == 2) {
            this.v();
            return 1;
        }
        var2_2 = var1_1.b;
        if ((var2_2 == this.B || var2_2 == this.C) && this.a.Q()) {
            var5_3 = var2_2 == this.B ? "l" : "e";
            gg.a(var5_3);
            var2_2 = var2_2 == this.B ? 1 : -1;
            this.h(var2_2);
            return 1;
        }
        if (this.l.a(var1_1) != -3) ** GOTO lbl-1000
        var3_4 = this.u();
        switch (this.b) {
            case 1: {
                var4_5 = this.a.w;
                var2_2 = this.a.r() != false ? 1 : 0;
                if (!this.a.r() || var3_4 != 0) ** GOTO lbl48
                gg.b("o");
                this.a(5);
lbl47:
                // 2 sources

                return 1;
lbl48:
                // 1 sources

                if (var3_4 - var2_2 < var4_5) break;
                if (var3_4 == var4_5 + var2_2 + 0) {
                    this.h(-1);
                    return 1;
                }
                if (var3_4 == var4_5 + var2_2 + 1) {
                    this.h(1);
                    return 1;
                }
                if (var3_4 == var4_5 + var2_2 + 2) {
                    gg.a("od", "", "");
                    this.a(2);
                }
            }
            default: lbl-1000:
            // 3 sources

            {
                return 3;
            }
        }
        gg.a(String.valueOf(var3_4 - var2_2));
        this.g(var3_4 - var2_2);
        return 1;
        {
            ** case 2:
        }
lbl66:
        // 1 sources

        ** while (this.u() != this.J)
lbl67:
        // 1 sources

        this.v();
        return 1;
    }

    /*
     * Unable to fully structure code
     */
    private void s() {
        if (!this.t) ** GOTO lbl-1000
        this.k = this.s.b(false, true);
        this.l = (hx)this.k.a();
        switch (this.b) {
            case 1: {
                dz.a(this.l, gg.d, -16777216, this.v);
                dz.a(this.l, ed.a(gg.E, bz.a(this.a.k)), -16777216, this.u, true);
                dz.a(this.l, ed.a(gg.F, bz.a(this.a.m)), -16777216, this.u, true);
                if (this.a.r()) {
                    this.a(gg.I, false);
                }
                this.o = dz.a(this.l, gg.p(), -7566196, this.u);
                this.p = System.currentTimeMillis();
                var2_1 = this.a.s;
                if (!ed.b(var2_1)) {
                    dz.a(this.l, var2_1, -65536, this.u);
                }
                if (this.a.b == 0) {
                    for (var6_3 = 0; var6_3 < this.a.w; ++var6_3) {
                        var7_13 = this.a.x;
                        var14_19 = new dr(false, 4);
                        this.a.m(var6_3);
                        var2_1 = this.a.O();
                        if (this.a.K().v()) {
                            var2_1 = ps.a('\ued3f') + " " + var2_1;
                        }
                        var15_20 = new hc(0, 0, this.t() - 12, this.w, var2_1);
                        var15_20.d = -14006936;
                        if (!ed.b(var15_20.b)) {
                            var14_19.d(var15_20);
                        }
                        var8_15 = new StringBuffer();
                        this.a.m(var6_3);
                        var20_22 = 0L;
                        var5_11 = 0;
                        var10_16 = this.a.L() - 1;
                        var3_7 = 0;
                        var1_5 = false;
                        var4_9 = 0;
                        do {
                            var2_1 = null;
                            var16_21 = 0L;
                            if (var3_7 < var10_16) {
                                var11_18 = this.a.k(var3_7);
                                if (var11_18.p() != 2) {
                                    if (!gg.a(var5_11, var4_9)) {
                                        var16_21 = var11_18.k();
                                        var2_1 = var11_18.l();
                                        ++var3_7;
                                    } else {
                                        var16_21 = var20_22;
                                    }
                                    var5_11 = 0;
                                    var4_9 = 0;
                                } else {
                                    if (var20_22 == 0L) {
                                        var20_22 = var11_18.k();
                                    }
                                    ++var3_7;
                                    var4_9 += var11_18.h();
                                    var5_11 += var11_18.j();
                                }
                            } else {
                                var16_21 = var20_22;
                                var4_9 = 0;
                                var5_11 = 0;
                            }
                            if (var16_21 == 0L) continue;
                            if (var1_5) {
                                var8_15.append(" ");
                                var8_15.append(ps.a('\ued17'));
                                var8_15.append(" ");
                            } else {
                                var1_5 = true;
                            }
                            var8_15.append(ps.a(this.s.j.a(var16_21)));
                            if (ed.b(var2_1)) continue;
                            var8_15.append(" ");
                            var8_15.append(var2_1);
                        } while (var3_7 < var10_16 || !var1_5 || gg.a(var5_11, var4_9));
                        var2_1 = var8_15.toString();
                        var22_23 = mg.a(this.u, var2_1, 1, 1);
                        new hc(0, 0, this.t() - 12, var22_23, var2_1).d = -13599807;
                        var14_19.d(new hc(0, 0, this.t() - 12, var22_23, var2_1));
                        dz.b(this.l, var14_19);
                        dz.b(this.l);
                        this.a.m(var7_13);
                    }
                }
                if (this.a.Q()) {
                    this.a(gg.e, false);
                    this.a(gg.f, false);
                }
                if (!this.z.isEmpty()) {
                    this.a(gg.c, false);
                }
                this.l.B();
                break;
            }
            case 2: {
                var3_8 = 0;
                var6_4 = false;
                dz.a(this.l, gg.c, -16777216, this.v);
                var12_24 = this.a.D;
                this.A = new ht[this.z.size()];
                for (var4_10 = 0; var4_10 < this.z.size(); ++var4_10) {
                    var9_25 = (lk)this.z.elementAt(var4_10);
                    var7_14 = var9_25.d(3);
                    var10_17 = var9_25.d(1);
                    var2_2 = var9_25.g(2);
                    var18_27 = var9_25.d(7);
                    for (var1_6 = 0; var1_6 < var12_24.length; ++var1_6) {
                        if (var12_24[var1_6].d(1) != var10_17) {
                            continue;
                        }
                        var5_12 = var12_24[var1_6].d(2);
                        ** GOTO lbl124
                    }
                    var5_12 = var18_27;
lbl124:
                    // 2 sources

                    if (var7_14 != 0) {
                        if (var7_14 != 1) continue;
                        dz.a(this.l, 4);
                        dz.a(this.l, var2_2, -16777216, this.w);
                        var13_26 = new bq(false);
                        this.A[var4_10] = ht.a(var10_17, var13_26);
                        var7_14 = var9_25.i(4);
                        var6_4 = true;
                        for (var1_6 = 0; var1_6 < var7_14; ++var1_6) {
                            ++var3_8;
                            dz.a(this.l, var9_25.e(4, var1_6).g(6), var13_26, this.u);
                        }
                        if (var5_12 >= var7_14 || var5_12 < 0) {
                            var5_12 = var18_27;
                        }
                        var13_26.a(var5_12).q_();
                        continue;
                    }
                    if (var6_4) {
                        dz.a(this.l, 4);
                    }
                    var19_28 = dz.c(this.l, var2_2);
                    var6_4 = false;
                    var1_6 = var5_12 != 0 ? 1 : 0;
                    ++var3_8;
                    var19_28.b((boolean)var1_6);
                    this.A[var4_10] = ht.a(var10_17, var19_28);
                }
                dz.a(this.l, 4);
                dz.a(this.l, gg.g);
                this.J = var3_8;
                this.l.B();
            }
        }
        switch (this.b) {
            case 2: {
                this.i(this.y);
            }
            default: lbl-1000:
            // 2 sources

            {
                return;
            }
            case 1: 
        }
        this.i(this.x);
    }
}

