package z5;

import A6.h;
import B6.k;
import B6.m;
import B6.q;
import E1.A;
import E1.C0103j;
import E1.H;
import E1.Q;
import G1.d;
import G1.e;
import P6.g;
import P6.n;
import W3.b;
import android.content.Context;
import android.os.Bundle;
import c7.InterfaceC0591B;
import c7.K;
import com.martsnew.tv.R;
import com.martsnew.tv.ui.main.TvMainFragment;
import d5.AbstractC0844a;
import h0.C1000H;
import h0.C1001a;
import h0.ComponentCallbacksC1023x;
import h0.M;
import h0.O;
import h0.P;
import h0.X;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

/* JADX INFO: renamed from: z5.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
@Q("fragment")
public final class C1795a extends e {

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final P f19372h;
    public final int i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final LinkedHashSet f19373j;

    public C1795a(Context context, P p3, int i) {
        super(context, p3, i);
        this.f19371g = context;
        this.f19372h = p3;
        this.i = i;
        this.f19373j = new LinkedHashSet();
    }

    /* JADX WARN: Removed duplicated region for block: B:71:0x0161  */
    @Override // G1.e, E1.S
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(List list, H h8) {
        boolean z8;
        boolean z9;
        boolean z10;
        C1795a c1795a = this;
        P p3 = c1795a.f19372h;
        if (p3.Q()) {
            return;
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0103j c0103j = (C0103j) it.next();
            List list2 = (List) ((K) ((InterfaceC0591B) c1795a.b().f2107e.f9369r)).e();
            boolean zIsEmpty = list2.isEmpty();
            if (h8 == null || zIsEmpty || !h8.f2026b || !c1795a.f19373j.remove(c0103j.f2091v)) {
                A a3 = c0103j.f2087r;
                g.c(a3, "null cannot be cast to non-null type androidx.navigation.fragment.FragmentNavigator.Destination");
                d dVar = (d) a3;
                String strL = dVar.f2920A;
                if (strL == null) {
                    throw new IllegalStateException("Fragment class was not set");
                }
                char cCharAt = strL.charAt(0);
                Context context = c1795a.f19371g;
                if (cCharAt == '.') {
                    strL = AbstractC0844a.l(context.getPackageName(), strL);
                }
                C1000H c1000hI = p3.I();
                context.getClassLoader();
                ComponentCallbacksC1023x componentCallbacksC1023xA = c1000hI.a(strL);
                g.d(componentCallbacksC1023xA, "instantiate(...)");
                componentCallbacksC1023xA.d0(c0103j.f2088s);
                C1001a c1001a = new C1001a(p3);
                int i = h8 != null ? h8.f2030f : -1;
                int i5 = h8 != null ? h8.f2031g : -1;
                int i8 = h8 != null ? h8.f2032h : -1;
                int i9 = h8 != null ? h8.i : -1;
                if (i != -1 || i5 != -1 || i8 != -1 || i9 != -1) {
                    if (i == -1) {
                        i = 0;
                    }
                    if (i5 == -1) {
                        i5 = 0;
                    }
                    if (i8 == -1) {
                        i8 = 0;
                    }
                    if (i9 == -1) {
                        i9 = 0;
                    }
                    c1001a.f13145b = i;
                    c1001a.f13146c = i5;
                    c1001a.f13147d = i8;
                    c1001a.f13148e = i9;
                }
                C2.a aVar = p3.f13069c;
                int size = aVar.t().size();
                int i10 = c1795a.i;
                if (size > 0) {
                    P6.d dVarA = n.a(TvMainFragment.class);
                    List listT = aVar.t();
                    g.d(listT, "getFragments(...)");
                    ArrayList arrayList = new ArrayList(m.a0(listT));
                    Iterator it2 = listT.iterator();
                    while (it2.hasNext()) {
                        arrayList.add(n.a(((ComponentCallbacksC1023x) it2.next()).getClass()));
                    }
                    if (!arrayList.contains(dVarA) || (h8 != null && h8.f2027c == R.id.nav_tv)) {
                        c1001a.j(i10, componentCallbacksC1023xA);
                    } else {
                        List listT2 = aVar.t();
                        g.d(listT2, "getFragments(...)");
                        ComponentCallbacksC1023x componentCallbacksC1023x = (ComponentCallbacksC1023x) k.n0(listT2);
                        P p4 = componentCallbacksC1023x.f13265K;
                        if (p4 != null && p4 != c1001a.f13160r) {
                            throw new IllegalStateException("Cannot hide Fragment attached to a different FragmentManager. Fragment " + componentCallbacksC1023x.toString() + " is already attached to a FragmentManager.");
                        }
                        c1001a.b(new X(4, componentCallbacksC1023x));
                        c1001a.h(i10, componentCallbacksC1023xA, null, 1);
                    }
                    c1001a.k(componentCallbacksC1023xA);
                    boolean z11 = h8 != null && !zIsEmpty && h8.f2025a && ((C0103j) k.n0(list2)).f2087r.f1985x == dVar.f1985x;
                    if (zIsEmpty) {
                        z8 = true;
                        z9 = true;
                    } else {
                        String str = c0103j.f2091v;
                        if (z11) {
                            z8 = true;
                            if (list2.size() > 1) {
                                z10 = false;
                                p3.x(new M(p3, str, -1), false);
                                c1001a.c(str);
                            } else {
                                z10 = false;
                            }
                            z9 = z10;
                        } else {
                            z8 = true;
                            c1001a.c(str);
                            z9 = true;
                        }
                    }
                    c1001a.f13158p = z8;
                    c1001a.f();
                    if (z9) {
                        b().e(c0103j);
                    }
                }
            } else {
                p3.x(new O(p3, c0103j.f2091v, 0), false);
                c1795a.b().e(c0103j);
            }
            c1795a = this;
        }
    }

    @Override // G1.e, E1.S
    public final void g(Bundle bundle) {
        ArrayList<String> stringArrayList = bundle.getStringArrayList("androidx-nav-fragment:navigator:savedIds");
        if (stringArrayList != null) {
            LinkedHashSet linkedHashSet = this.f19373j;
            linkedHashSet.clear();
            q.d0(stringArrayList, linkedHashSet);
        }
    }

    @Override // G1.e, E1.S
    public final Bundle h() {
        LinkedHashSet linkedHashSet = this.f19373j;
        if (linkedHashSet.isEmpty()) {
            return null;
        }
        return b.e(new h("androidx-nav-fragment:navigator:savedIds", new ArrayList(linkedHashSet)));
    }

    @Override // G1.e, E1.S
    public final void i(C0103j c0103j, boolean z8) {
        g.e(c0103j, "popUpTo");
        P p3 = this.f19372h;
        if (p3.Q()) {
            return;
        }
        if (z8) {
            List list = (List) ((K) ((InterfaceC0591B) b().f2107e.f9369r)).e();
            C0103j c0103j2 = (C0103j) k.h0(list);
            for (C0103j c0103j3 : k.s0(list.subList(list.indexOf(c0103j), list.size()))) {
                if (!g.a(c0103j3, c0103j2)) {
                    p3.x(new O(p3, c0103j3.f2091v, 1), false);
                    this.f19373j.add(c0103j3.f2091v);
                }
            }
        } else {
            p3.x(new M(p3, c0103j.f2091v, -1), false);
        }
        b().c(c0103j);
    }
}
