package androidx.fragment.app;

import android.animation.LayoutTransition;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
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.riyaz.zvytour.R;
import f0.AbstractC0589a;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import p0.AbstractC0928a;
import r4.AbstractC0983h;

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FragmentContainerView(Context context, AttributeSet attributeSet) {
        String str;
        super(context, attributeSet, 0);
        AbstractC0983h.e("context", context);
        this.f4176k = new ArrayList();
        this.f4177l = new ArrayList();
        this.f4179n = true;
        if (attributeSet != null) {
            String classAttribute = attributeSet.getClassAttribute();
            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0589a.f6337b, 0, 0);
            if (classAttribute == null) {
                classAttribute = typedArrayObtainStyledAttributes.getString(0);
                str = "android:name";
            } else {
                str = "class";
            }
            typedArrayObtainStyledAttributes.recycle();
            if (classAttribute == null || isInEditMode()) {
                return;
            }
            throw new UnsupportedOperationException("FragmentContainerView must be within a FragmentActivity to use " + str + "=\"" + classAttribute + '\"');
        }
    }

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

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

    @Override // android.view.ViewGroup, android.view.View
    public final WindowInsets dispatchApplyWindowInsets(WindowInsets windowInsets) {
        P.s0 s0VarD;
        AbstractC0983h.e("insets", windowInsets);
        P.s0 s0VarD2 = P.s0.d(null, windowInsets);
        View.OnApplyWindowInsetsListener onApplyWindowInsetsListener = this.f4178m;
        if (onApplyWindowInsetsListener != null) {
            WindowInsets windowInsetsOnApplyWindowInsets = onApplyWindowInsetsListener.onApplyWindowInsets(this, windowInsets);
            AbstractC0983h.d("onApplyWindowInsetsListe…lyWindowInsets(v, insets)", windowInsetsOnApplyWindowInsets);
            s0VarD = P.s0.d(null, windowInsetsOnApplyWindowInsets);
        } else {
            Field field = P.Q.f2392a;
            WindowInsets windowInsetsC = s0VarD2.c();
            if (windowInsetsC != null) {
                WindowInsets windowInsetsB = P.G.b(this, windowInsetsC);
                if (!windowInsetsB.equals(windowInsetsC)) {
                    s0VarD2 = P.s0.d(this, windowInsetsB);
                }
            }
            s0VarD = s0VarD2;
        }
        if (!s0VarD.f2486a.m()) {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                P.Q.a(getChildAt(i), s0VarD);
            }
        }
        return windowInsets;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        AbstractC0983h.e("canvas", canvas);
        if (this.f4179n) {
            Iterator it = this.f4176k.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 view, long j5) {
        AbstractC0983h.e("canvas", canvas);
        AbstractC0983h.e("child", view);
        if (this.f4179n) {
            ArrayList arrayList = this.f4176k;
            if (!arrayList.isEmpty() && arrayList.contains(view)) {
                return false;
            }
        }
        return super.drawChild(canvas, view, j5);
    }

    @Override // android.view.ViewGroup
    public final void endViewTransition(View view) {
        AbstractC0983h.e("view", view);
        this.f4177l.remove(view);
        if (this.f4176k.remove(view)) {
            this.f4179n = true;
        }
        super.endViewTransition(view);
    }

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

    @Override // android.view.View
    public final WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
        AbstractC0983h.e("insets", windowInsets);
        return windowInsets;
    }

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

    @Override // android.view.ViewGroup, android.view.ViewManager
    public final void removeView(View view) {
        AbstractC0983h.e("view", view);
        a(view);
        super.removeView(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViewAt(int i) {
        View childAt = getChildAt(i);
        AbstractC0983h.d("view", childAt);
        a(childAt);
        super.removeViewAt(i);
    }

    @Override // android.view.ViewGroup
    public final void removeViewInLayout(View view) {
        AbstractC0983h.e("view", view);
        a(view);
        super.removeViewInLayout(view);
    }

    @Override // android.view.ViewGroup
    public final void removeViews(int i, int i5) {
        int i6 = i + i5;
        for (int i7 = i; i7 < i6; i7++) {
            View childAt = getChildAt(i7);
            AbstractC0983h.d("view", childAt);
            a(childAt);
        }
        super.removeViews(i, i5);
    }

    @Override // android.view.ViewGroup
    public final void removeViewsInLayout(int i, int i5) {
        int i6 = i + i5;
        for (int i7 = i; i7 < i6; i7++) {
            View childAt = getChildAt(i7);
            AbstractC0983h.d("view", childAt);
            a(childAt);
        }
        super.removeViewsInLayout(i, i5);
    }

    public final void setDrawDisappearingViewsLast(boolean z5) {
        this.f4179n = z5;
    }

    @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 onApplyWindowInsetsListener) {
        AbstractC0983h.e("listener", onApplyWindowInsetsListener);
        this.f4178m = onApplyWindowInsetsListener;
    }

    @Override // android.view.ViewGroup
    public final void startViewTransition(View view) {
        AbstractC0983h.e("view", view);
        if (view.getParent() == this) {
            this.f4177l.add(view);
        }
        super.startViewTransition(view);
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FragmentContainerView(Context context, AttributeSet attributeSet, h0 h0Var) {
        View view;
        super(context, attributeSet);
        AbstractC0983h.e("context", context);
        AbstractC0983h.e("attrs", attributeSet);
        AbstractC0983h.e("fm", h0Var);
        this.f4176k = new ArrayList();
        this.f4177l = new ArrayList();
        this.f4179n = true;
        String classAttribute = attributeSet.getClassAttribute();
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0589a.f6337b, 0, 0);
        classAttribute = classAttribute == null ? typedArrayObtainStyledAttributes.getString(0) : classAttribute;
        String string = typedArrayObtainStyledAttributes.getString(1);
        typedArrayObtainStyledAttributes.recycle();
        int id = getId();
        I iB = h0Var.B(id);
        if (classAttribute != null && iB == null) {
            if (id == -1) {
                throw new IllegalStateException(AbstractC0928a.l("FragmentContainerView must have an android:id to add Fragment ", classAttribute, string != null ? " with tag ".concat(string) : ""));
            }
            C0263a0 c0263a0G = h0Var.G();
            context.getClassLoader();
            I iInstantiate = I.instantiate(c0263a0G.f4224a.f4293v.f4196l, classAttribute, null);
            AbstractC0983h.d("fm.fragmentFactory.insta…ontext.classLoader, name)", iInstantiate);
            iInstantiate.mFragmentId = id;
            iInstantiate.mContainerId = id;
            iInstantiate.mTag = string;
            iInstantiate.mFragmentManager = h0Var;
            iInstantiate.mHost = h0Var.f4293v;
            iInstantiate.onInflate(context, attributeSet, (Bundle) null);
            C0262a c0262a = new C0262a(h0Var);
            c0262a.f4221o = true;
            iInstantiate.mContainer = this;
            c0262a.e(getId(), iInstantiate, string, 1);
            if (!c0262a.f4214g) {
                h0 h0Var2 = c0262a.p;
                if (h0Var2.f4293v != null && !h0Var2.I) {
                    h0Var2.y(true);
                    c0262a.a(h0Var2.K, h0Var2.f4271L);
                    h0Var2.f4276b = true;
                    try {
                        h0Var2.T(h0Var2.K, h0Var2.f4271L);
                        h0Var2.d();
                        h0Var2.d0();
                        boolean z5 = h0Var2.J;
                        q0 q0Var = h0Var2.f4277c;
                        if (z5) {
                            h0Var2.J = false;
                            for (p0 p0Var : q0Var.d()) {
                                I i = p0Var.f4351c;
                                if (i.mDeferStart) {
                                    if (h0Var2.f4276b) {
                                        h0Var2.J = true;
                                    } else {
                                        i.mDeferStart = false;
                                        p0Var.k();
                                    }
                                }
                            }
                        }
                        q0Var.f4360b.values().removeAll(Collections.singleton(null));
                    } catch (Throwable th) {
                        h0Var2.d();
                        throw th;
                    }
                }
            } else {
                throw new IllegalStateException("This transaction is already being added to the back stack");
            }
        }
        for (p0 p0Var2 : h0Var.f4277c.d()) {
            I i5 = p0Var2.f4351c;
            if (i5.mContainerId == getId() && (view = i5.mView) != null && view.getParent() == null) {
                i5.mContainer = this;
                p0Var2.b();
            }
        }
    }
}
