package androidx.view;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.view.aa;
import androidx.view.bf;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import defpackage.bz8;
import defpackage.cr4;
import defpackage.ds;
import defpackage.e48;
import defpackage.e6a;
import defpackage.hz9;
import defpackage.m38;
import defpackage.n89;
import defpackage.og8;
import defpackage.oj9;
import defpackage.rc1;
import defpackage.sg8;
import defpackage.sh6;
import defpackage.vo7;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wy8;
import defpackage.xh6;
import defpackage.y41;
import defpackage.zy8;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0004\b\u0016\u0018\u00002\u00020\u0001:\u0003\u0002\u0003\u0004¨\u0006\u0005"}, d2 = {"Landroidx/navigation/ao;", "", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "b", "c", "navigation-common_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public class ao {
    public static final /* synthetic */ int l = 0;
    public final String a;
    public at b;
    public String c;
    public CharSequence d;
    public final ArrayList e;
    public final wy8 f;
    public final LinkedHashMap i;
    public int j;
    public String k;

    @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u001b\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0087\u0002\u0018\u00002\u00020\u0001B\u0013\u0012\n\u0010\u0003\u001a\u0006\u0012\u0002\b\u00030\u0002¢\u0006\u0004\b\u0004\u0010\u0005¨\u0006\u0006"}, d2 = {"Landroidx/navigation/ao$a;", "", "Lkotlin/reflect/KClass;", AppMeasurementSdk.ConditionalUserProperty.VALUE, "<init>", "(Lkotlin/reflect/KClass;)V", "navigation-common_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @oj9
    @e48
    @Retention(RetentionPolicy.CLASS)
    public @interface a {
    }

    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010%\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R$\u0010\u0005\u001a\u0012\u0012\u0004\u0012\u00020\u0003\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u00040\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0005\u0010\u0006¨\u0006\u0007"}, d2 = {"Landroidx/navigation/ao$b;", "", "", "", "Ljava/lang/Class;", "classes", "Ljava/util/Map;", "navigation-common_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class b {
        public static String a(Context context, int i) {
            String strValueOf;
            cr4.g(context, "context");
            if (i <= 16777215) {
                return String.valueOf(i);
            }
            try {
                strValueOf = context.getResources().getResourceName(i);
            } catch (Resources.NotFoundException unused) {
                strValueOf = String.valueOf(i);
            }
            cr4.f(strValueOf, "try {\n                co….toString()\n            }");
            return strValueOf;
        }

        public static og8 b(ao aoVar) {
            cr4.g(aoVar, "<this>");
            return sg8.j(ap.a, aoVar);
        }
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0010\u000f\n\u0000\b\u0007\u0018\u00002\b\u0012\u0004\u0012\u00020\u00000\u0001¨\u0006\u0002"}, d2 = {"Landroidx/navigation/ao$c;", "", "navigation-common_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @m38
    @vx8
    public static final class c implements Comparable<c> {
        public final ao a;
        public final Bundle b;
        public final boolean c;
        public final int d;
        public final boolean e;
        public final int f;

        public c(ao aoVar, Bundle bundle, boolean z, int i, boolean z2, int i2) {
            this.a = aoVar;
            this.b = bundle;
            this.c = z;
            this.d = i;
            this.e = z2;
            this.f = i2;
        }

        @Override // java.lang.Comparable
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public final int compareTo(c cVar) {
            cr4.g(cVar, "other");
            boolean z = cVar.e;
            boolean z2 = cVar.c;
            Bundle bundle = cVar.b;
            boolean z3 = this.c;
            if (z3 && !z2) {
                return 1;
            }
            if (!z3 && z2) {
                return -1;
            }
            int i = this.d - cVar.d;
            if (i > 0) {
                return 1;
            }
            if (i < 0) {
                return -1;
            }
            Bundle bundle2 = this.b;
            if (bundle2 != null && bundle == null) {
                return 1;
            }
            if (bundle2 == null && bundle != null) {
                return -1;
            }
            if (bundle2 != null) {
                int size = bundle2.size();
                cr4.d(bundle);
                int size2 = size - bundle.size();
                if (size2 > 0) {
                    return 1;
                }
                if (size2 < 0) {
                    return -1;
                }
            }
            boolean z4 = this.e;
            if (z4 && !z) {
                return 1;
            }
            if (z4 || !z) {
                return this.f - cVar.f;
            }
            return -1;
        }
    }

    static {
        new LinkedHashMap();
    }

    public ao(String str) {
        this.a = str;
        this.e = new ArrayList();
        this.f = new wy8();
        this.i = new LinkedHashMap();
    }

    public final void a(aa aaVar) {
        ArrayList arrayListA = xh6.a(this.i, new aq(aaVar));
        if (arrayListA.isEmpty()) {
            this.e.add(aaVar);
            return;
        }
        throw new IllegalArgumentException(("Deep link " + aaVar.a + " can't be used to open destination " + this + ".\nFollowing required arguments are missing: " + arrayListA).toString());
    }

    public final Bundle b(Bundle bundle) {
        LinkedHashMap linkedHashMap = this.i;
        if (bundle == null && (linkedHashMap == null || linkedHashMap.isEmpty())) {
            return null;
        }
        Bundle bundle2 = new Bundle();
        for (Map.Entry entry : linkedHashMap.entrySet()) {
            String str = (String) entry.getKey();
            e eVar = (e) entry.getValue();
            eVar.getClass();
            cr4.g(str, AppMeasurementSdk.ConditionalUserProperty.NAME);
            if (eVar.c) {
                eVar.a.e(bundle2, str, eVar.d);
            }
        }
        if (bundle != null) {
            bundle2.putAll(bundle);
            for (Map.Entry entry2 : linkedHashMap.entrySet()) {
                String str2 = (String) entry2.getKey();
                e eVar2 = (e) entry2.getValue();
                eVar2.getClass();
                ay ayVar = eVar2.a;
                cr4.g(str2, AppMeasurementSdk.ConditionalUserProperty.NAME);
                if (eVar2.b || !bundle2.containsKey(str2) || bundle2.get(str2) != null) {
                    try {
                        ayVar.a(bundle2, str2);
                    } catch (ClassCastException unused) {
                    }
                }
                StringBuilder sbS = vw2.s("Wrong argument type for '", str2, "' in argument bundle. ");
                sbS.append(ayVar.b());
                sbS.append(" expected.");
                throw new IllegalArgumentException(sbS.toString().toString());
            }
        }
        return bundle2;
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0022  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int[] c(ao aoVar) {
        ds dsVar = new ds();
        ao aoVar2 = this;
        while (true) {
            at atVar = aoVar2.b;
            if ((aoVar != null ? aoVar.b : null) != null) {
                at atVar2 = aoVar.b;
                cr4.d(atVar2);
                if (atVar2.h(aoVar2.j, true) != aoVar2) {
                    if (atVar == null || atVar.n != aoVar2.j) {
                        dsVar.addFirst(aoVar2);
                    }
                    if (cr4.b(atVar, aoVar) || atVar == null) {
                        break;
                    }
                    aoVar2 = atVar;
                } else {
                    dsVar.addFirst(aoVar2);
                    break;
                }
            }
        }
        List listBo = y41.bo(dsVar);
        ArrayList arrayList = new ArrayList(y41.p(listBo, 10));
        Iterator it = listBo.iterator();
        while (it.hasNext()) {
            arrayList.add(Integer.valueOf(((ao) it.next()).j));
        }
        return y41.bn(arrayList);
    }

    public final sh6 d(int i) {
        wy8 wy8Var = this.f;
        sh6 sh6Var = wy8Var.f() == 0 ? null : (sh6) wy8Var.c(i);
        if (sh6Var != null) {
            return sh6Var;
        }
        at atVar = this.b;
        if (atVar != null) {
            return atVar.d(i);
        }
        return null;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:15:0x0043  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0127  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x0136  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x0165  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0168  */
    /* JADX WARN: Removed duplicated region for block: B:92:0x01b9  */
    /* JADX WARN: Type inference failed for: r0v3, types: [androidx.navigation.aa, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v8, types: [j65, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r17v3, types: [java.lang.Throwable] */
    /* JADX WARN: Type inference failed for: r6v10 */
    /* JADX WARN: Type inference failed for: r6v11, types: [java.util.regex.Matcher] */
    /* JADX WARN: Type inference failed for: r6v18 */
    /* JADX WARN: Type inference failed for: r6v19, types: [java.util.regex.Matcher] */
    /* JADX WARN: Type inference failed for: r6v24 */
    /* JADX WARN: Type inference failed for: r6v25 */
    /* JADX WARN: Type inference failed for: r8v19 */
    /* JADX WARN: Type inference failed for: r8v7 */
    /* JADX WARN: Type inference failed for: r8v8, types: [java.util.regex.Matcher] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public c e(an anVar) {
        Bundle bundle;
        Bundle bundle2;
        int size;
        String str;
        int iA;
        String str2;
        ao aoVar = this;
        ArrayList<??> arrayList = aoVar.e;
        Bundle bundle3 = null;
        if (arrayList.isEmpty()) {
            return null;
        }
        c cVar = null;
        for (?? r0 : arrayList) {
            Uri uri = anVar.a;
            LinkedHashMap linkedHashMap = aoVar.i;
            if (uri != null) {
                r0.getClass();
                cr4.g(linkedHashMap, "arguments");
                Pattern pattern = (Pattern) r0.f.getValue();
                ?? Matcher = pattern != null ? pattern.matcher(uri.toString()) : bundle3;
                if (Matcher != 0 && Matcher.matches()) {
                    bundle2 = new Bundle();
                    if (r0.b(Matcher, bundle2, linkedHashMap) && (!((Boolean) r0.g.getValue()).booleanValue() || r0.c(uri, bundle2, linkedHashMap))) {
                        String fragment = uri.getFragment();
                        Pattern pattern2 = (Pattern) r0.m.getValue();
                        ?? Matcher2 = pattern2 != null ? pattern2.matcher(String.valueOf(fragment)) : bundle3;
                        if (Matcher2 != 0 && Matcher2.matches()) {
                            List list = (List) r0.k.getValue();
                            ArrayList arrayList2 = new ArrayList(y41.p(list, 10));
                            int i = 0;
                            for (Object obj : list) {
                                int i2 = i + 1;
                                if (i < 0) {
                                    ?? r17 = bundle3;
                                    y41.bm();
                                    throw r17;
                                }
                                String str3 = (String) obj;
                                String strDecode = Uri.decode(Matcher2.group(i2));
                                bundle = bundle3;
                                e eVar = (e) linkedHashMap.get(str3);
                                try {
                                    cr4.f(strDecode, AppMeasurementSdk.ConditionalUserProperty.VALUE);
                                    aa.d(bundle2, str3, strDecode, eVar);
                                    arrayList2.add(e6a.a);
                                    i = i2;
                                    bundle3 = bundle;
                                } catch (IllegalArgumentException unused) {
                                }
                            }
                            bundle = bundle3;
                            if (!xh6.a(linkedHashMap, new af(bundle2)).isEmpty()) {
                            }
                        } else {
                            bundle = bundle3;
                            if (!xh6.a(linkedHashMap, new af(bundle2)).isEmpty()) {
                            }
                        }
                    } else {
                        bundle2 = bundle3;
                        bundle = bundle2;
                    }
                }
                String str4 = r0.a;
                if (uri != null || str4 == null) {
                    size = 0;
                } else {
                    List<String> pathSegments = uri.getPathSegments();
                    List<String> pathSegments2 = Uri.parse(str4).getPathSegments();
                    cr4.f(pathSegments, "requestedPathSegments");
                    cr4.f(pathSegments2, "uriPathSegments");
                    size = y41.ag(pathSegments, pathSegments2).size();
                }
                String str5 = anVar.b;
                boolean z = str5 == null && str5.equals(r0.b);
                str = anVar.c;
                if (str != null || (str2 = r0.c) == null) {
                    iA = -1;
                } else {
                    Pattern pattern3 = (Pattern) r0.o.getValue();
                    cr4.d(pattern3);
                    if (pattern3.matcher(str).matches()) {
                        iA = new aa.c(str2).compareTo(new aa.c(str));
                    }
                }
                if (bundle2 != null) {
                    c cVar2 = new c(this, bundle2, r0.p, size, z, iA);
                    if (cVar == null || cVar2.compareTo(cVar) > 0) {
                        aoVar = this;
                        cVar = cVar2;
                    } else {
                        aoVar = this;
                    }
                } else {
                    if (z || iA > -1) {
                        cr4.g(linkedHashMap, "arguments");
                        Bundle bundle4 = new Bundle();
                        if (uri != null) {
                            Pattern pattern4 = (Pattern) r0.f.getValue();
                            ?? Matcher3 = pattern4 != null ? pattern4.matcher(uri.toString()) : bundle;
                            if (Matcher3 != 0 && Matcher3.matches()) {
                                r0.b(Matcher3, bundle4, linkedHashMap);
                                if (((Boolean) r0.g.getValue()).booleanValue()) {
                                    r0.c(uri, bundle4, linkedHashMap);
                                }
                            }
                        }
                        if (xh6.a(linkedHashMap, new ar(bundle4)).isEmpty()) {
                        }
                    }
                    aoVar = this;
                }
                bundle3 = bundle;
            } else {
                bundle = bundle3;
            }
            bundle2 = bundle;
            String str42 = r0.a;
            if (uri != null) {
                size = 0;
            }
            String str52 = anVar.b;
            if (str52 == null) {
            }
            str = anVar.c;
            if (str != null) {
                iA = -1;
            }
            if (bundle2 != null) {
            }
            bundle3 = bundle;
        }
        return cVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0065  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00a5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean equals(Object obj) {
        boolean z;
        LinkedHashMap linkedHashMap;
        boolean z2;
        if (this != obj) {
            if (obj != null && (obj instanceof ao)) {
                ao aoVar = (ao) obj;
                wy8 wy8Var = aoVar.f;
                LinkedHashMap linkedHashMap2 = aoVar.i;
                boolean zB = cr4.b(this.e, aoVar.e);
                wy8 wy8Var2 = this.f;
                if (wy8Var2.f() == wy8Var.f()) {
                    Iterator a2 = ((rc1) sg8.b(new zy8(wy8Var2))).getA();
                    while (a2.hasNext()) {
                        int iIntValue = ((Number) a2.next()).intValue();
                        if (!cr4.b(wy8Var2.c(iIntValue), wy8Var.c(iIntValue))) {
                        }
                    }
                    z = true;
                    linkedHashMap = this.i;
                    if (linkedHashMap.size() == linkedHashMap2.size()) {
                        for (Map.Entry entry : y41.m(linkedHashMap.entrySet()).a) {
                            if (!linkedHashMap2.containsKey(entry.getKey()) || !cr4.b(linkedHashMap2.get(entry.getKey()), entry.getValue())) {
                            }
                        }
                        z2 = true;
                        if (this.j == aoVar.j || !cr4.b(this.k, aoVar.k) || !zB || !z || !z2) {
                        }
                    }
                    z2 = false;
                    if (this.j == aoVar.j) {
                    }
                }
                z = false;
                linkedHashMap = this.i;
                if (linkedHashMap.size() == linkedHashMap2.size()) {
                }
                z2 = false;
                if (this.j == aoVar.j) {
                }
            }
            return false;
        }
        return true;
    }

    public void f(Context context, AttributeSet attributeSet) {
        Object next;
        TypedArray typedArrayObtainAttributes = context.getResources().obtainAttributes(attributeSet, vo7.b.e);
        cr4.f(typedArrayObtainAttributes, "context.resources.obtain…s, R.styleable.Navigator)");
        String string = typedArrayObtainAttributes.getString(2);
        if (string == null) {
            this.j = 0;
            this.c = null;
        } else {
            if (n89.ab(string)) {
                throw new IllegalArgumentException("Cannot have an empty route");
            }
            String strConcat = "android-app://androidx.navigation/".concat(string);
            this.j = strConcat.hashCode();
            this.c = null;
            aa.a aVar = new aa.a();
            aVar.a = strConcat;
            a(new aa(aVar.a, aVar.b, aVar.c));
        }
        ArrayList arrayList = this.e;
        Iterator it = arrayList.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            String str = ((aa) next).a;
            String str2 = this.k;
            if (cr4.b(str, str2 != null ? "android-app://androidx.navigation/".concat(str2) : "")) {
                break;
            }
        }
        hz9.a(arrayList);
        arrayList.remove(next);
        this.k = string;
        if (typedArrayObtainAttributes.hasValue(1)) {
            int resourceId = typedArrayObtainAttributes.getResourceId(1, 0);
            this.j = resourceId;
            this.c = null;
            this.c = b.a(context, resourceId);
        }
        this.d = typedArrayObtainAttributes.getText(0);
        typedArrayObtainAttributes.recycle();
    }

    public int hashCode() {
        Set<String> setKeySet;
        int i = this.j * 31;
        String str = this.k;
        int iHashCode = i + (str != null ? str.hashCode() : 0);
        for (aa aaVar : this.e) {
            int i2 = iHashCode * 31;
            String str2 = aaVar.a;
            int iHashCode2 = (i2 + (str2 != null ? str2.hashCode() : 0)) * 31;
            String str3 = aaVar.b;
            int iHashCode3 = (iHashCode2 + (str3 != null ? str3.hashCode() : 0)) * 31;
            String str4 = aaVar.c;
            iHashCode = iHashCode3 + (str4 != null ? str4.hashCode() : 0);
        }
        wy8 wy8Var = this.f;
        cr4.g(wy8Var, "<this>");
        bz8 bz8Var = new bz8(wy8Var);
        while (bz8Var.hasNext()) {
            sh6 sh6Var = (sh6) bz8Var.next();
            int i3 = ((iHashCode * 31) + sh6Var.a) * 31;
            aw awVar = sh6Var.b;
            iHashCode = i3 + (awVar != null ? awVar.hashCode() : 0);
            Bundle bundle = sh6Var.c;
            if (bundle != null && (setKeySet = bundle.keySet()) != null) {
                for (String str5 : setKeySet) {
                    int i4 = iHashCode * 31;
                    Bundle bundle2 = sh6Var.c;
                    cr4.d(bundle2);
                    Object obj = bundle2.get(str5);
                    iHashCode = i4 + (obj != null ? obj.hashCode() : 0);
                }
            }
        }
        LinkedHashMap linkedHashMap = this.i;
        for (String str6 : linkedHashMap.keySet()) {
            int iB = vw2.b(iHashCode * 31, 31, str6);
            Object obj2 = linkedHashMap.get(str6);
            iHashCode = iB + (obj2 != null ? obj2.hashCode() : 0);
        }
        return iHashCode;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append("(");
        String str = this.c;
        if (str == null) {
            sb.append("0x");
            sb.append(Integer.toHexString(this.j));
        } else {
            sb.append(str);
        }
        sb.append(")");
        String str2 = this.k;
        if (str2 != null && !n89.ab(str2)) {
            sb.append(" route=");
            sb.append(this.k);
        }
        if (this.d != null) {
            sb.append(" label=");
            sb.append(this.d);
        }
        String string = sb.toString();
        cr4.f(string, "sb.toString()");
        return string;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public ao(bc bcVar) {
        this(bf.a.a(bcVar.getClass()));
        cr4.g(bcVar, "navigator");
        LinkedHashMap linkedHashMap = bf.b;
    }
}
