package E1;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.util.Xml;
import java.io.IOException;
import java.io.Serializable;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public final class G {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final ThreadLocal f2022c = new ThreadLocal();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f2023a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final T f2024b;

    public G(Context context, T t6) {
        P6.g.e(t6, "navigatorProvider");
        this.f2023a = context;
        this.f2024b = t6;
    }

    /* JADX WARN: Removed duplicated region for block: B:186:0x0346  */
    /* JADX WARN: Removed duplicated region for block: B:195:0x037b  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x00ac  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static C0102i c(TypedArray typedArray, Resources resources, int i) throws XmlPullParserException {
        boolean z8;
        J j8;
        P p3;
        P o8;
        Class cls;
        boolean z9;
        P p4;
        Object objC;
        P o9;
        P pC;
        Object objValueOf;
        int i5;
        boolean z10 = typedArray.getBoolean(3, false);
        ThreadLocal threadLocal = f2022c;
        TypedValue typedValue = (TypedValue) threadLocal.get();
        if (typedValue == null) {
            typedValue = new TypedValue();
            threadLocal.set(typedValue);
        }
        String string = typedArray.getString(2);
        J j9 = P.f2044c;
        J j10 = P.f2049h;
        J j11 = P.f2052l;
        J j12 = P.f2050j;
        J j13 = P.f2047f;
        J j14 = P.f2045d;
        J j15 = P.f2046e;
        J j16 = P.f2051k;
        J j17 = P.i;
        J j18 = P.f2048g;
        J j19 = P.f2043b;
        if (string != null) {
            j8 = j14;
            String resourcePackageName = resources.getResourcePackageName(i);
            if ("integer".equals(string)) {
                z8 = z10;
                p3 = j15;
                o8 = j19;
            } else {
                z8 = z10;
                if ("integer[]".equals(string)) {
                    p3 = j15;
                    o8 = j8;
                } else if ("long".equals(string)) {
                    o8 = j15;
                    p3 = o8;
                } else if ("long[]".equals(string)) {
                    p3 = j15;
                    o8 = j13;
                } else if ("boolean".equals(string)) {
                    p3 = j15;
                    o8 = j17;
                } else if ("boolean[]".equals(string)) {
                    p3 = j15;
                    o8 = j12;
                } else if (!"string".equals(string)) {
                    if ("string[]".equals(string)) {
                        p3 = j15;
                        o8 = j11;
                    } else {
                        if ("float".equals(string)) {
                            o8 = j18;
                        } else if ("float[]".equals(string)) {
                            p3 = j15;
                            o8 = j10;
                        } else if ("reference".equals(string)) {
                            o8 = j9;
                        } else if (string.length() == 0) {
                            p3 = j15;
                            o8 = j16;
                        } else {
                            try {
                                p3 = j15;
                                String strConcat = (!X6.n.M(string, ".", false) || resourcePackageName == null) ? string : resourcePackageName.concat(string);
                                if (X6.n.H(string, "[]", false)) {
                                    strConcat = strConcat.substring(0, strConcat.length() - 2);
                                    P6.g.d(strConcat, "this as java.lang.String…ing(startIndex, endIndex)");
                                    Class<?> cls2 = Class.forName(strConcat);
                                    if (!Parcelable.class.isAssignableFrom(cls2)) {
                                        if (Serializable.class.isAssignableFrom(cls2)) {
                                            o8 = new N(cls2);
                                        }
                                        throw new IllegalArgumentException(strConcat + " is not Serializable or Parcelable.");
                                    }
                                    o8 = new L(cls2);
                                } else {
                                    Class<?> cls3 = Class.forName(strConcat);
                                    if (Parcelable.class.isAssignableFrom(cls3)) {
                                        o8 = new M(cls3);
                                    } else {
                                        if (!Enum.class.isAssignableFrom(cls3)) {
                                            if (Serializable.class.isAssignableFrom(cls3)) {
                                                o8 = new O(cls3);
                                            }
                                            throw new IllegalArgumentException(strConcat + " is not Serializable or Parcelable.");
                                        }
                                        o8 = new K(cls3);
                                    }
                                }
                            } catch (ClassNotFoundException e8) {
                                throw new RuntimeException(e8);
                            }
                        }
                        p3 = j15;
                    }
                }
            }
        } else {
            z8 = z10;
            j8 = j14;
            p3 = j15;
            o8 = null;
        }
        if (typedArray.getValue(1, typedValue)) {
            cls = Serializable.class;
            if (o8 == j9) {
                int i8 = typedValue.resourceId;
                if (i8 != 0) {
                    i5 = i8;
                } else {
                    if (typedValue.type != 16 || typedValue.data != 0) {
                        throw new XmlPullParserException("unsupported value '" + ((Object) typedValue.string) + "' for " + o8.b() + ". Must be a reference to a resource.");
                    }
                    i5 = 0;
                }
                objC = Integer.valueOf(i5);
            } else {
                int i9 = typedValue.resourceId;
                if (i9 == 0) {
                    if (o8 == j16) {
                        z9 = true;
                        objC = typedArray.getString(1);
                    } else {
                        z9 = true;
                        int i10 = typedValue.type;
                        if (i10 != 3) {
                            if (i10 == 4) {
                                pC = U2.a.c(typedValue, o8, j18, string, "float");
                                objValueOf = Float.valueOf(typedValue.getFloat());
                            } else if (i10 == 5) {
                                pC = U2.a.c(typedValue, o8, j19, string, "dimension");
                                objValueOf = Integer.valueOf((int) typedValue.getDimension(resources.getDisplayMetrics()));
                            } else if (i10 == 18) {
                                pC = U2.a.c(typedValue, o8, j17, string, "boolean");
                                objValueOf = Boolean.valueOf(typedValue.data != 0);
                            } else {
                                if (i10 < 16 || i10 > 31) {
                                    throw new XmlPullParserException("unsupported argument type " + typedValue.type);
                                }
                                if (o8 == j18) {
                                    pC = U2.a.c(typedValue, o8, j18, string, "float");
                                    objValueOf = Float.valueOf(typedValue.data);
                                } else {
                                    pC = U2.a.c(typedValue, o8, j19, string, "integer");
                                    objValueOf = Integer.valueOf(typedValue.data);
                                }
                            }
                            o8 = pC;
                            objC = objValueOf;
                        } else {
                            String string2 = typedValue.string.toString();
                            if (o8 == null) {
                                P6.g.e(string2, "value");
                                try {
                                    j19.c(string2);
                                    o8 = j19;
                                    p4 = p3;
                                } catch (IllegalArgumentException unused) {
                                    p4 = p3;
                                    try {
                                        try {
                                            try {
                                                p4.c(string2);
                                                o8 = p4;
                                            } catch (IllegalArgumentException unused2) {
                                                o8 = j16;
                                            }
                                        } catch (IllegalArgumentException unused3) {
                                            j17.c(string2);
                                            o8 = j17;
                                        }
                                    } catch (IllegalArgumentException unused4) {
                                        j18.c(string2);
                                        o8 = j18;
                                    }
                                }
                                objC = o8.c(string2);
                            } else {
                                p4 = p3;
                                objC = o8.c(string2);
                            }
                        }
                    }
                    p4 = p3;
                } else {
                    if (o8 != null) {
                        throw new XmlPullParserException("unsupported value '" + ((Object) typedValue.string) + "' for " + o8.b() + ". You must use a \"reference\" type to reference other resources.");
                    }
                    objC = Integer.valueOf(i9);
                    o8 = j9;
                }
            }
            p4 = p3;
            z9 = true;
        } else {
            cls = Serializable.class;
            z9 = true;
            p4 = p3;
            objC = null;
        }
        if (objC == null) {
            objC = null;
            z9 = false;
        }
        P p8 = o8 != null ? o8 : null;
        if (p8 != null) {
            o9 = p8;
        } else if (objC instanceof Integer) {
            o9 = j19;
        } else if (objC instanceof int[]) {
            o9 = j8;
        } else if (objC instanceof Long) {
            o9 = p4;
        } else if (objC instanceof long[]) {
            o9 = j13;
        } else if (objC instanceof Float) {
            o9 = j18;
        } else if (objC instanceof float[]) {
            o9 = j10;
        } else if (objC instanceof Boolean) {
            o9 = j17;
        } else if (objC instanceof boolean[]) {
            o9 = j12;
        } else if ((objC instanceof String) || objC == null) {
            o9 = j16;
        } else if ((objC instanceof Object[]) && (((Object[]) objC) instanceof String[])) {
            o9 = j11;
        } else if (objC.getClass().isArray()) {
            Class<?> componentType = objC.getClass().getComponentType();
            P6.g.b(componentType);
            if (Parcelable.class.isAssignableFrom(componentType)) {
                Class<?> componentType2 = objC.getClass().getComponentType();
                if (componentType2 == null) {
                    throw new NullPointerException("null cannot be cast to non-null type java.lang.Class<android.os.Parcelable>");
                }
                o9 = new L(componentType2);
            } else if (objC.getClass().isArray()) {
                Class<?> componentType3 = objC.getClass().getComponentType();
                P6.g.b(componentType3);
                if (cls.isAssignableFrom(componentType3)) {
                    Class<?> componentType4 = objC.getClass().getComponentType();
                    if (componentType4 == null) {
                        throw new NullPointerException("null cannot be cast to non-null type java.lang.Class<java.io.Serializable>");
                    }
                    o9 = new N(componentType4);
                } else if (objC instanceof Parcelable) {
                    o9 = new M(objC.getClass());
                } else if (objC instanceof Enum) {
                    o9 = new K(objC.getClass());
                } else {
                    if (!(objC instanceof Serializable)) {
                        throw new IllegalArgumentException("Object of type " + objC.getClass().getName() + " is not supported for navigation arguments.");
                    }
                    o9 = new O(objC.getClass());
                }
            }
        }
        return new C0102i(o9, z8, objC, z9);
    }

    /* JADX WARN: Code restructure failed: missing block: B:50:0x0100, code lost:
    
        throw new org.xmlpull.v1.XmlPullParserException("Every <deepLink> must include at least one of app:uri, app:action, or app:mimeType");
     */
    /* JADX WARN: Code restructure failed: missing block: B:98:0x0245, code lost:
    
        return r4;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final A a(Resources resources, XmlResourceParser xmlResourceParser, AttributeSet attributeSet, int i) throws XmlPullParserException, IOException {
        int depth;
        String strK;
        String strK2;
        Context context;
        int i5;
        TypedArray typedArray;
        int i8 = i;
        String name = xmlResourceParser.getName();
        P6.g.d(name, "parser.name");
        A a3 = this.f2024b.b(name).a();
        Context context2 = this.f2023a;
        a3.g(context2, attributeSet);
        int i9 = 1;
        int depth2 = xmlResourceParser.getDepth() + 1;
        while (true) {
            int next = xmlResourceParser.next();
            if (next == i9 || ((depth = xmlResourceParser.getDepth()) < depth2 && next == 3)) {
                break;
            }
            if (next == 2 && depth <= depth2) {
                String name2 = xmlResourceParser.getName();
                boolean zEquals = "argument".equals(name2);
                int[] iArr = F1.a.f2433b;
                if (zEquals) {
                    TypedArray typedArrayObtainAttributes = resources.obtainAttributes(attributeSet, iArr);
                    P6.g.d(typedArrayObtainAttributes, "res.obtainAttributes(att… R.styleable.NavArgument)");
                    String string = typedArrayObtainAttributes.getString(0);
                    if (string == null) {
                        throw new XmlPullParserException("Arguments must have a name");
                    }
                    a3.f1984w.put(string, c(typedArrayObtainAttributes, resources, i8));
                    typedArrayObtainAttributes.recycle();
                } else if ("deepLink".equals(name2)) {
                    TypedArray typedArrayObtainAttributes2 = resources.obtainAttributes(attributeSet, F1.a.f2434c);
                    P6.g.d(typedArrayObtainAttributes2, "res.obtainAttributes(att… R.styleable.NavDeepLink)");
                    String string2 = typedArrayObtainAttributes2.getString(3);
                    String string3 = typedArrayObtainAttributes2.getString(i9);
                    String string4 = typedArrayObtainAttributes2.getString(2);
                    if ((string2 == null || string2.length() == 0) && ((string3 == null || string3.length() == 0) && (string4 == null || string4.length() == 0))) {
                        break;
                    }
                    String strK3 = null;
                    if (string2 != null) {
                        String packageName = context2.getPackageName();
                        P6.g.d(packageName, "context.packageName");
                        strK = X6.n.K(string2, "${applicationId}", packageName);
                    } else {
                        strK = null;
                    }
                    if (string3 == null || string3.length() == 0) {
                        strK2 = null;
                    } else {
                        String packageName2 = context2.getPackageName();
                        P6.g.d(packageName2, "context.packageName");
                        strK2 = X6.n.K(string3, "${applicationId}", packageName2);
                        if (strK2.length() <= 0) {
                            throw new IllegalArgumentException("The NavDeepLink cannot have an empty action.");
                        }
                    }
                    if (string4 != null) {
                        String packageName3 = context2.getPackageName();
                        P6.g.d(packageName3, "context.packageName");
                        strK3 = X6.n.K(string4, "${applicationId}", packageName3);
                    }
                    a3.a(new y(strK, strK2, strK3));
                    typedArrayObtainAttributes2.recycle();
                } else {
                    if ("action".equals(name2)) {
                        TypedArray typedArrayObtainStyledAttributes = context2.obtainStyledAttributes(attributeSet, F1.a.f2432a, 0, 0);
                        int resourceId = typedArrayObtainStyledAttributes.getResourceId(0, 0);
                        int i10 = i9;
                        C0099f c0099f = new C0099f(typedArrayObtainStyledAttributes.getResourceId(i9, 0));
                        c0099f.f2076b = new H(typedArrayObtainStyledAttributes.getBoolean(4, false), typedArrayObtainStyledAttributes.getBoolean(10, false), typedArrayObtainStyledAttributes.getResourceId(7, -1), typedArrayObtainStyledAttributes.getBoolean(8, false), typedArrayObtainStyledAttributes.getBoolean(9, false), typedArrayObtainStyledAttributes.getResourceId(2, -1), typedArrayObtainStyledAttributes.getResourceId(3, -1), typedArrayObtainStyledAttributes.getResourceId(5, -1), typedArrayObtainStyledAttributes.getResourceId(6, -1));
                        Bundle bundle = new Bundle();
                        int depth3 = xmlResourceParser.getDepth() + 1;
                        context = context2;
                        while (true) {
                            int next2 = xmlResourceParser.next();
                            i5 = depth2;
                            if (next2 == i10) {
                                typedArray = typedArrayObtainStyledAttributes;
                                break;
                            }
                            int depth4 = xmlResourceParser.getDepth();
                            typedArray = typedArrayObtainStyledAttributes;
                            if (depth4 < depth3 && next2 == 3) {
                                break;
                            }
                            if (next2 == 2 && depth4 <= depth3) {
                                if ("argument".equals(xmlResourceParser.getName())) {
                                    TypedArray typedArrayObtainAttributes3 = resources.obtainAttributes(attributeSet, iArr);
                                    P6.g.d(typedArrayObtainAttributes3, "res.obtainAttributes(att… R.styleable.NavArgument)");
                                    String string5 = typedArrayObtainAttributes3.getString(0);
                                    if (string5 == null) {
                                        throw new XmlPullParserException("Arguments must have a name");
                                    }
                                    C0102i c0102iC = c(typedArrayObtainAttributes3, resources, i8);
                                    boolean z8 = c0102iC.f2082c;
                                    if (z8 && z8) {
                                        c0102iC.f2080a.d(bundle, string5, c0102iC.f2083d);
                                    }
                                    typedArrayObtainAttributes3.recycle();
                                }
                                i8 = i;
                            }
                            depth2 = i5;
                            typedArrayObtainStyledAttributes = typedArray;
                            i10 = 1;
                        }
                        if (!bundle.isEmpty()) {
                            c0099f.f2077c = bundle;
                        }
                        if (a3 instanceof C0095b) {
                            throw new UnsupportedOperationException("Cannot add action " + resourceId + " to " + a3 + " as it does not support actions, indicating that it is a terminal destination in your navigation graph and will never trigger actions.");
                        }
                        if (resourceId == 0) {
                            throw new IllegalArgumentException("Cannot have an action with actionId 0");
                        }
                        a3.f1983v.i(resourceId, c0099f);
                        typedArray.recycle();
                    } else {
                        context = context2;
                        i5 = depth2;
                        if ("include".equals(name2) && (a3 instanceof D)) {
                            TypedArray typedArrayObtainAttributes4 = resources.obtainAttributes(attributeSet, U.f2060c);
                            P6.g.d(typedArrayObtainAttributes4, "res.obtainAttributes(att…n.R.styleable.NavInclude)");
                            ((D) a3).h(b(typedArrayObtainAttributes4.getResourceId(0, 0)));
                            typedArrayObtainAttributes4.recycle();
                        } else if (a3 instanceof D) {
                            ((D) a3).h(a(resources, xmlResourceParser, attributeSet, i));
                        }
                    }
                    i8 = i;
                    context2 = context;
                    depth2 = i5;
                    i9 = 1;
                }
            }
        }
    }

    public final D b(int i) {
        int next;
        Resources resources = this.f2023a.getResources();
        XmlResourceParser xml = resources.getXml(i);
        P6.g.d(xml, "res.getXml(graphResId)");
        AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
        do {
            try {
                try {
                    next = xml.next();
                    if (next == 2) {
                        break;
                    }
                } catch (Exception e8) {
                    throw new RuntimeException("Exception inflating " + resources.getResourceName(i) + " line " + xml.getLineNumber(), e8);
                }
            } finally {
                xml.close();
            }
        } while (next != 1);
        if (next != 2) {
            throw new XmlPullParserException("No start tag found");
        }
        String name = xml.getName();
        P6.g.d(attributeSetAsAttributeSet, "attrs");
        A a3 = a(resources, xml, attributeSetAsAttributeSet, i);
        if (a3 instanceof D) {
            return (D) a3;
        }
        throw new IllegalArgumentException(("Root element <" + name + "> did not inflate into a NavGraph").toString());
    }
}
