package androidx.fragment.app;

import F1.AbstractC0193w;
import android.animation.LayoutTransition;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.os.Build;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.widget.FrameLayout;
import com.debridstream.tv.R;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public final class P extends FrameLayout {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public View.OnApplyWindowInsetsListener f11536c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f11537d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public P(Context context, AttributeSet attrs, AbstractC1050g0 fm) {
        View view;
        super(context, attrs);
        kotlin.jvm.internal.o.h(context, "context");
        kotlin.jvm.internal.o.h(attrs, "attrs");
        kotlin.jvm.internal.o.h(fm, "fm");
        this.f11534a = new ArrayList();
        this.f11535b = new ArrayList();
        this.f11537d = true;
        String classAttribute = attrs.getClassAttribute();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attrs, W1.a.f8423b, 0, 0);
        classAttribute = classAttribute == null ? typedArrayObtainStyledAttributes.getString(0) : classAttribute;
        String string = typedArrayObtainStyledAttributes.getString(1);
        typedArrayObtainStyledAttributes.recycle();
        int id = getId();
        G gA = fm.A(id);
        if (classAttribute != null && gA == null) {
            if (id == -1) {
                throw new IllegalStateException(Z0.o.o("FragmentContainerView must have an android:id to add Fragment ", classAttribute, string != null ? " with tag ".concat(string) : ""));
            }
            Z zE = fm.E();
            context.getClassLoader();
            G gInstantiate = G.instantiate(zE.f11554a.f11623u.f11540b, classAttribute, null);
            kotlin.jvm.internal.o.g(gInstantiate, "fm.fragmentFactory.insta…ontext.classLoader, name)");
            gInstantiate.onInflate(context, attrs, (Bundle) null);
            C1037a c1037a = new C1037a(fm);
            c1037a.f11717o = true;
            gInstantiate.mContainer = this;
            c1037a.c(getId(), gInstantiate, string);
            if (c1037a.f11710g) {
                throw new IllegalStateException("This transaction is already being added to the back stack");
            }
            c1037a.f11555p.y(c1037a, true);
        }
        for (o0 o0Var : fm.f11606c.d()) {
            G g6 = o0Var.f11684c;
            if (g6.mContainerId == getId() && (view = g6.mView) != null && view.getParent() == null) {
                g6.mContainer = this;
                o0Var.b();
            }
        }
    }

    public final void a(View view) {
        if (this.f11535b.contains(view)) {
            this.f11534a.add(view);
        }
    }

    @Override // android.view.ViewGroup
    public final void addView(View child, int i6, ViewGroup.LayoutParams layoutParams) {
        kotlin.jvm.internal.o.h(child, "child");
        Object tag = child.getTag(R.id.fragment_container_view_tag);
        if ((tag instanceof G ? (G) tag : null) != null) {
            super.addView(child, i6, layoutParams);
            return;
        }
        throw new IllegalStateException(("Views added to a FragmentContainerView must be associated with a Fragment. View " + child + " is not associated with a Fragment.").toString());
    }

    @Override // android.view.ViewGroup, android.view.View
    public final WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        F1.m0 m0VarC;
        kotlin.jvm.internal.o.h(insets, "insets");
        F1.m0 m0VarC2 = F1.m0.c(null, insets);
        View.OnApplyWindowInsetsListener onApplyWindowInsetsListener = this.f11536c;
        if (onApplyWindowInsetsListener != null) {
            kotlin.jvm.internal.o.e(onApplyWindowInsetsListener);
            WindowInsets windowInsetsOnApplyWindowInsets = onApplyWindowInsetsListener.onApplyWindowInsets(this, insets);
            kotlin.jvm.internal.o.g(windowInsetsOnApplyWindowInsets, "onApplyWindowInsetsListe…lyWindowInsets(v, insets)");
            m0VarC = F1.m0.c(null, windowInsetsOnApplyWindowInsets);
        } else {
            Field field = F1.F.f1367a;
            WindowInsets windowInsetsB = m0VarC2.b();
            if (windowInsetsB != null) {
                WindowInsets windowInsetsB2 = AbstractC0193w.b(this, windowInsetsB);
                if (!windowInsetsB2.equals(windowInsetsB)) {
                    m0VarC2 = F1.m0.c(this, windowInsetsB2);
                }
            }
            m0VarC = m0VarC2;
        }
        if (!m0VarC.f1458a.o()) {
            int childCount = getChildCount();
            for (int i6 = 0; i6 < childCount; i6++) {
                View childAt = getChildAt(i6);
                Field field2 = F1.F.f1367a;
                int i7 = Build.VERSION.SDK_INT;
                WindowInsets windowInsetsB3 = m0VarC.b();
                if (windowInsetsB3 != null) {
                    WindowInsets windowInsetsA = i7 >= 30 ? F1.D.a(childAt, windowInsetsB3) : AbstractC0193w.a(childAt, windowInsetsB3);
                    if (!windowInsetsA.equals(windowInsetsB3)) {
                        F1.m0.c(childAt, windowInsetsA);
                    }
                }
            }
        }
        return insets;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        kotlin.jvm.internal.o.h(canvas, "canvas");
        if (this.f11537d) {
            Iterator it = this.f11534a.iterator();
            while (it.hasNext()) {
                super.drawChild(canvas, (View) it.next(), getDrawingTime());
            }
        }
        super.dispatchDraw(canvas);
    }

    @Override // android.view.ViewGroup
    public final boolean drawChild(Canvas canvas, View child, long j4) {
        kotlin.jvm.internal.o.h(canvas, "canvas");
        kotlin.jvm.internal.o.h(child, "child");
        if (this.f11537d) {
            ArrayList arrayList = this.f11534a;
            if (!arrayList.isEmpty() && arrayList.contains(child)) {
                return false;
            }
        }
        return super.drawChild(canvas, child, j4);
    }

    @Override // android.view.ViewGroup
    public final void endViewTransition(View view) {
        kotlin.jvm.internal.o.h(view, "view");
        this.f11535b.remove(view);
        if (this.f11534a.remove(view)) {
            this.f11537d = true;
        }
        super.endViewTransition(view);
    }

    public final <F extends G> F getFragment() {
        L l;
        G g6;
        AbstractC1050g0 supportFragmentManager;
        View view = this;
        while (true) {
            l = null;
            if (view == null) {
                g6 = null;
                break;
            }
            Object tag = view.getTag(R.id.fragment_container_view_tag);
            g6 = tag instanceof G ? (G) tag : null;
            if (g6 != null) {
                break;
            }
            Object parent = view.getParent();
            view = parent instanceof View ? (View) parent : null;
        }
        if (g6 == null) {
            Context context = getContext();
            while (true) {
                if (!(context instanceof ContextWrapper)) {
                    break;
                }
                if (context instanceof L) {
                    l = (L) context;
                    break;
                }
                context = ((ContextWrapper) context).getBaseContext();
            }
            if (l == null) {
                throw new IllegalStateException("View " + this + " is not within a subclass of FragmentActivity.");
            }
            supportFragmentManager = l.getSupportFragmentManager();
        } else {
            if (!g6.isAdded()) {
                throw new IllegalStateException("The Fragment " + g6 + " that owns View " + this + " has already been destroyed. Nested fragments should always use the child FragmentManager.");
            }
            supportFragmentManager = g6.getChildFragmentManager();
        }
        return (F) supportFragmentManager.A(getId());
    }

    @Override // android.view.View
    public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
        kotlin.jvm.internal.o.h(insets, "insets");
        return insets;
    }

    @Override // android.view.ViewGroup
    public final void removeAllViewsInLayout() {
        int childCount = getChildCount();
        while (true) {
            childCount--;
            if (-1 >= childCount) {
                super.removeAllViewsInLayout();
                return;
            } else {
                View view = getChildAt(childCount);
                kotlin.jvm.internal.o.g(view, "view");
                a(view);
            }
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewManager
    public final void removeView(View view) {
        kotlin.jvm.internal.o.h(view, "view");
        a(view);
        super.removeView(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViewAt(int i6) {
        View view = getChildAt(i6);
        kotlin.jvm.internal.o.g(view, "view");
        a(view);
        super.removeViewAt(i6);
    }

    @Override // android.view.ViewGroup
    public final void removeViewInLayout(View view) {
        kotlin.jvm.internal.o.h(view, "view");
        a(view);
        super.removeViewInLayout(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViews(int i6, int i7) {
        int i8 = i6 + i7;
        for (int i9 = i6; i9 < i8; i9++) {
            View view = getChildAt(i9);
            kotlin.jvm.internal.o.g(view, "view");
            a(view);
        }
        super.removeViews(i6, i7);
    }

    @Override // android.view.ViewGroup
    public final void removeViewsInLayout(int i6, int i7) {
        int i8 = i6 + i7;
        for (int i9 = i6; i9 < i8; i9++) {
            View view = getChildAt(i9);
            kotlin.jvm.internal.o.g(view, "view");
            a(view);
        }
        super.removeViewsInLayout(i6, i7);
    }

    public final void setDrawDisappearingViewsLast(boolean z6) {
        this.f11537d = z6;
    }

    @Override // android.view.ViewGroup
    public void setLayoutTransition(LayoutTransition layoutTransition) {
        throw new UnsupportedOperationException("FragmentContainerView does not support Layout Transitions or animateLayoutChanges=\"true\".");
    }

    @Override // android.view.View
    public void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener) {
        kotlin.jvm.internal.o.h(listener, "listener");
        this.f11536c = listener;
    }

    @Override // android.view.ViewGroup
    public final void startViewTransition(View view) {
        kotlin.jvm.internal.o.h(view, "view");
        if (view.getParent() == this) {
            this.f11535b.add(view);
        }
        super.startViewTransition(view);
    }
}
