package androidx.view;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.view.ao;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import defpackage.cr4;
import defpackage.ds;
import defpackage.li6;
import defpackage.vw2;
import defpackage.wj9;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\u0018\u00002\u00020\u0001:\u0002\u0002\u0003¨\u0006\u0004"}, d2 = {"Landroidx/navigation/ak;", "", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "b", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class ak {
    public final Context a;
    public final Intent b;
    public final at c;
    public final ArrayList d;

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\b\u0002\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Landroidx/navigation/ak$a;", "", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
        public final int a;
        public final Bundle b;

        public a(int i, Bundle bundle) {
            this.a = i;
            this.b = bundle;
        }
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0002\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Landroidx/navigation/ak$b;", "Landroidx/navigation/bf;", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class b extends bf {
        @Override // androidx.view.bf
        public final bc b(String str) {
            cr4.g(str, AppMeasurementSdk.ConditionalUserProperty.NAME);
            try {
                return super.b(str);
            } catch (IllegalStateException unused) {
                cr4.e(null, "null cannot be cast to non-null type T of androidx.navigation.NavDeepLinkBuilder.PermissiveNavigatorProvider.getNavigator");
                return null;
            }
        }
    }

    public ak(j jVar) {
        Intent launchIntentForPackage;
        cr4.g(jVar, "navController");
        Context context = jVar.a;
        this.a = context;
        if (context instanceof Activity) {
            launchIntentForPackage = new Intent(context, context.getClass());
        } else {
            launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
            if (launchIntentForPackage == null) {
                launchIntentForPackage = new Intent();
            }
        }
        launchIntentForPackage.addFlags(268468224);
        this.b = launchIntentForPackage;
        this.d = new ArrayList();
        this.c = jVar.h();
    }

    public final wj9 a() {
        at atVar = this.c;
        if (atVar == null) {
            throw new IllegalStateException("You must call setGraph() before constructing the deep link");
        }
        ArrayList arrayList = this.d;
        if (arrayList.isEmpty()) {
            throw new IllegalStateException("You must call setDestination() or addDestination() before constructing the deep link");
        }
        ArrayList arrayList2 = new ArrayList();
        ArrayList<? extends Parcelable> arrayList3 = new ArrayList<>();
        Iterator it = arrayList.iterator();
        ao aoVar = null;
        while (true) {
            boolean zHasNext = it.hasNext();
            Context context = this.a;
            int i = 0;
            if (!zHasNext) {
                int[] iArrBn = y41.bn(arrayList2);
                Intent intent = this.b;
                intent.putExtra("android-support-nav:controller:deepLinkIds", iArrBn);
                intent.putParcelableArrayListExtra("android-support-nav:controller:deepLinkArgs", arrayList3);
                wj9 wj9Var = new wj9(context);
                Intent intent2 = new Intent(intent);
                ComponentName component = intent2.getComponent();
                if (component == null) {
                    component = intent2.resolveActivity(wj9Var.b.getPackageManager());
                }
                if (component != null) {
                    wj9Var.a(component);
                }
                ArrayList arrayList4 = wj9Var.a;
                arrayList4.add(intent2);
                int size = arrayList4.size();
                while (i < size) {
                    Intent intent3 = (Intent) arrayList4.get(i);
                    if (intent3 != null) {
                        intent3.putExtra("android-support-nav:controller:deepLinkIntent", intent);
                    }
                    i++;
                }
                return wj9Var;
            }
            a aVar = (a) it.next();
            int i2 = aVar.a;
            Bundle bundle = aVar.b;
            ao aoVarB = b(i2);
            if (aoVarB == null) {
                int i3 = ao.l;
                throw new IllegalArgumentException("Navigation destination " + ao.b.a(context, i2) + " cannot be found in the navigation graph " + atVar);
            }
            int[] iArrC = aoVarB.c(aoVar);
            int length = iArrC.length;
            while (i < length) {
                arrayList2.add(Integer.valueOf(iArrC[i]));
                arrayList3.add(bundle);
                i++;
            }
            aoVar = aoVarB;
        }
    }

    public final ao b(int i) {
        ds dsVar = new ds();
        at atVar = this.c;
        cr4.d(atVar);
        dsVar.addLast(atVar);
        while (!dsVar.isEmpty()) {
            ao aoVar = (ao) dsVar.removeFirst();
            if (aoVar.j == i) {
                return aoVar;
            }
            if (aoVar instanceof at) {
                li6 li6Var = new li6((at) aoVar);
                while (li6Var.hasNext()) {
                    dsVar.addLast((ao) li6Var.next());
                }
            }
        }
        return null;
    }

    public final void c() {
        Iterator it = this.d.iterator();
        while (it.hasNext()) {
            int i = ((a) it.next()).a;
            if (b(i) == null) {
                int i2 = ao.l;
                StringBuilder sbS = vw2.s("Navigation destination ", ao.b.a(this.a, i), " cannot be found in the navigation graph ");
                sbS.append(this.c);
                throw new IllegalArgumentException(sbS.toString());
            }
        }
    }
}
