package E1;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import d5.AbstractC0844a;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: renamed from: E1.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
@Q("activity")
public class C0097d extends S {

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Activity f2074d;

    public C0097d(Context context) {
        Object next;
        this.f2073c = context;
        Iterator it = W6.j.H(context, C0096c.f2064s).iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            } else {
                next = it.next();
                if (((Context) next) instanceof Activity) {
                    break;
                }
            }
        }
        this.f2074d = (Activity) next;
    }

    @Override // E1.S
    public final A a() {
        return new C0095b(this);
    }

    @Override // E1.S
    public final A c(A a3, Bundle bundle, H h8) {
        Intent intent;
        int intExtra;
        C0095b c0095b = (C0095b) a3;
        if (c0095b.f2062A == null) {
            throw new IllegalStateException(AbstractC0844a.n(new StringBuilder("Destination "), c0095b.f1985x, " does not have an Intent set.").toString());
        }
        Intent intent2 = new Intent(c0095b.f2062A);
        if (bundle != null) {
            intent2.putExtras(bundle);
            String str = c0095b.f2063B;
            if (str != null && str.length() != 0) {
                StringBuffer stringBuffer = new StringBuffer();
                Matcher matcher = Pattern.compile("\\{(.+?)\\}").matcher(str);
                while (matcher.find()) {
                    String strGroup = matcher.group(1);
                    if (!bundle.containsKey(strGroup)) {
                        throw new IllegalArgumentException("Could not find " + strGroup + " in " + bundle + " to fill data pattern " + str);
                    }
                    matcher.appendReplacement(stringBuffer, "");
                    stringBuffer.append(Uri.encode(String.valueOf(bundle.get(strGroup))));
                }
                matcher.appendTail(stringBuffer);
                intent2.setData(Uri.parse(stringBuffer.toString()));
            }
        }
        Activity activity = this.f2074d;
        if (activity == null) {
            intent2.addFlags(268435456);
        }
        if (h8 != null && h8.f2025a) {
            intent2.addFlags(536870912);
        }
        if (activity != null && (intent = activity.getIntent()) != null && (intExtra = intent.getIntExtra("android-support-navigation:ActivityNavigator:current", 0)) != 0) {
            intent2.putExtra("android-support-navigation:ActivityNavigator:source", intExtra);
        }
        intent2.putExtra("android-support-navigation:ActivityNavigator:current", c0095b.f1985x);
        Context context = this.f2073c;
        Resources resources = context.getResources();
        if (h8 != null) {
            int i = h8.f2032h;
            int i5 = h8.i;
            if ((i <= 0 || !P6.g.a(resources.getResourceTypeName(i), "animator")) && (i5 <= 0 || !P6.g.a(resources.getResourceTypeName(i5), "animator"))) {
                intent2.putExtra("android-support-navigation:ActivityNavigator:popEnterAnim", i);
                intent2.putExtra("android-support-navigation:ActivityNavigator:popExitAnim", i5);
            } else {
                Log.w("ActivityNavigator", "Activity destinations do not support Animator resource. Ignoring popEnter resource " + resources.getResourceName(i) + " and popExit resource " + resources.getResourceName(i5) + " when launching " + c0095b);
            }
        }
        context.startActivity(intent2);
        if (h8 == null || activity == null) {
            return null;
        }
        int i8 = h8.f2030f;
        int i9 = h8.f2031g;
        if ((i8 <= 0 || !P6.g.a(resources.getResourceTypeName(i8), "animator")) && (i9 <= 0 || !P6.g.a(resources.getResourceTypeName(i9), "animator"))) {
            if (i8 < 0 && i9 < 0) {
                return null;
            }
            if (i8 < 0) {
                i8 = 0;
            }
            activity.overridePendingTransition(i8, i9 >= 0 ? i9 : 0);
            return null;
        }
        Log.w("ActivityNavigator", "Activity destinations do not support Animator resource. Ignoring enter resource " + resources.getResourceName(i8) + " and exit resource " + resources.getResourceName(i9) + "when launching " + c0095b);
        return null;
    }

    @Override // E1.S
    public final boolean j() {
        Activity activity = this.f2074d;
        if (activity == null) {
            return false;
        }
        activity.finish();
        return true;
    }
}
