package androidx.lifecycle;

import android.os.Bundle;
import android.view.View;
import com.debridstream.tv.R;
import d2.C1867d;
import f2.C2032a;
import f2.C2034c;
import java.util.Arrays;
import n2.C2616g;
import n2.InterfaceC2615f;
import n2.InterfaceC2618i;
import y4.C3277e;

/* JADX INFO: loaded from: classes.dex */
public abstract class X {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final u4.c f12140a = new u4.c(24);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final u4.c f12141b = new u4.c(25);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final u4.c f12142c = new u4.c(26);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final C2034c f12143d = new C2034c();

    public static final void a(b0 b0Var, C2616g registry, r lifecycle) {
        kotlin.jvm.internal.o.h(registry, "registry");
        kotlin.jvm.internal.o.h(lifecycle, "lifecycle");
        V v3 = (V) b0Var.getCloseable("androidx.lifecycle.savedstate.vm.tag");
        if (v3 == null || v3.f12139c) {
            return;
        }
        v3.b(lifecycle, registry);
        k(lifecycle, registry);
    }

    public static final V b(C2616g registry, r lifecycle, String str, Bundle bundle) {
        U u6;
        kotlin.jvm.internal.o.h(registry, "registry");
        kotlin.jvm.internal.o.h(lifecycle, "lifecycle");
        Bundle bundleA = registry.a(str);
        if (bundleA != null) {
            bundle = bundleA;
        }
        if (bundle == null) {
            u6 = new U();
        } else {
            ClassLoader classLoader = U.class.getClassLoader();
            kotlin.jvm.internal.o.e(classLoader);
            bundle.setClassLoader(classLoader);
            C3277e c3277e = new C3277e(bundle.size());
            for (String str2 : bundle.keySet()) {
                kotlin.jvm.internal.o.e(str2);
                c3277e.put(str2, bundle.get(str2));
            }
            u6 = new U(c3277e.b());
        }
        V v3 = new V(str, u6);
        v3.b(lifecycle, registry);
        k(lifecycle, registry);
        return v3;
    }

    public static final U c(C1867d c1867d) {
        U u6;
        InterfaceC2618i interfaceC2618i = (InterfaceC2618i) c1867d.a(f12140a);
        if (interfaceC2618i == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`");
        }
        j0 j0Var = (j0) c1867d.a(f12141b);
        if (j0Var == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_STORE_OWNER_KEY`");
        }
        Bundle bundle = (Bundle) c1867d.a(f12142c);
        String str = (String) c1867d.a(h0.f12174b);
        if (str == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_KEY`");
        }
        InterfaceC2615f interfaceC2615fB = interfaceC2618i.getSavedStateRegistry().b();
        Bundle bundle2 = null;
        Y y6 = interfaceC2615fB instanceof Y ? (Y) interfaceC2615fB : null;
        if (y6 == null) {
            throw new IllegalStateException("enableSavedStateHandles() wasn't called prior to createSavedStateHandle() call");
        }
        SavedStateHandlesVM savedStateHandlesVMG = g(j0Var);
        U u7 = savedStateHandlesVMG.getHandles().get(str);
        if (u7 != null) {
            return u7;
        }
        y6.b();
        Bundle bundle3 = y6.f12146c;
        if (bundle3 != null && bundle3.containsKey(str)) {
            Bundle bundle4 = bundle3.getBundle(str);
            if (bundle4 == null) {
                bundle4 = e4.C.m((w4.k[]) Arrays.copyOf(new w4.k[0], 0));
            }
            bundle3.remove(str);
            if (bundle3.isEmpty()) {
                y6.f12146c = null;
            }
            bundle2 = bundle4;
        }
        if (bundle2 != null) {
            bundle = bundle2;
        }
        if (bundle == null) {
            u6 = new U();
        } else {
            ClassLoader classLoader = U.class.getClassLoader();
            kotlin.jvm.internal.o.e(classLoader);
            bundle.setClassLoader(classLoader);
            C3277e c3277e = new C3277e(bundle.size());
            for (String str2 : bundle.keySet()) {
                kotlin.jvm.internal.o.e(str2);
                c3277e.put(str2, bundle.get(str2));
            }
            u6 = new U(c3277e.b());
        }
        savedStateHandlesVMG.getHandles().put(str, u6);
        return u6;
    }

    public static final void d(InterfaceC2618i interfaceC2618i) {
        EnumC1108q currentState = interfaceC2618i.getLifecycle().getCurrentState();
        if (currentState != EnumC1108q.f12181b && currentState != EnumC1108q.f12182c) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        if (interfaceC2618i.getSavedStateRegistry().b() == null) {
            Y y6 = new Y(interfaceC2618i.getSavedStateRegistry(), (j0) interfaceC2618i);
            interfaceC2618i.getSavedStateRegistry().c("androidx.lifecycle.internal.SavedStateHandlesProvider", y6);
            interfaceC2618i.getLifecycle().addObserver(new C1097f(y6, 1));
        }
    }

    public static final InterfaceC1113w e(View view) {
        kotlin.jvm.internal.o.h(view, "<this>");
        while (view != null) {
            Object tag = view.getTag(R.id.view_tree_lifecycle_owner);
            InterfaceC1113w interfaceC1113w = tag instanceof InterfaceC1113w ? (InterfaceC1113w) tag : null;
            if (interfaceC1113w != null) {
                return interfaceC1113w;
            }
            Object objK = L4.a.K(view);
            view = objK instanceof View ? (View) objK : null;
        }
        return null;
    }

    public static final j0 f(View view) {
        kotlin.jvm.internal.o.h(view, "<this>");
        while (view != null) {
            Object tag = view.getTag(R.id.view_tree_view_model_store_owner);
            j0 j0Var = tag instanceof j0 ? (j0) tag : null;
            if (j0Var != null) {
                return j0Var;
            }
            Object objK = L4.a.K(view);
            view = objK instanceof View ? (View) objK : null;
        }
        return null;
    }

    public static final SavedStateHandlesVM g(j0 j0Var) {
        h0 h0VarC = u4.c.c(j0Var, new W(), 4);
        return (SavedStateHandlesVM) ((C0.J) h0VarC.f12175a).g(kotlin.jvm.internal.D.a(SavedStateHandlesVM.class), "androidx.lifecycle.internal.SavedStateHandlesVM");
    }

    public static final C2032a h(b0 b0Var) {
        C2032a c2032a;
        kotlin.jvm.internal.o.h(b0Var, "<this>");
        synchronized (f12143d) {
            c2032a = (C2032a) b0Var.getCloseable("androidx.lifecycle.viewmodel.internal.ViewModelCoroutineScope.JOB_KEY");
            if (c2032a == null) {
                A4.j jVar = A4.k.f106a;
                try {
                    c5.e eVar = V4.N.f8259a;
                    jVar = a5.m.f10845a.f8429e;
                } catch (IllegalStateException | w4.j unused) {
                }
                C2032a c2032a2 = new C2032a(jVar.plus(V4.E.d()));
                b0Var.addCloseable("androidx.lifecycle.viewmodel.internal.ViewModelCoroutineScope.JOB_KEY", c2032a2);
                c2032a = c2032a2;
            }
        }
        return c2032a;
    }

    public static final void i(View view, InterfaceC1113w interfaceC1113w) {
        kotlin.jvm.internal.o.h(view, "<this>");
        view.setTag(R.id.view_tree_lifecycle_owner, interfaceC1113w);
    }

    public static final void j(View view, j0 j0Var) {
        kotlin.jvm.internal.o.h(view, "<this>");
        view.setTag(R.id.view_tree_view_model_store_owner, j0Var);
    }

    public static void k(r rVar, C2616g c2616g) {
        EnumC1108q currentState = rVar.getCurrentState();
        if (currentState == EnumC1108q.f12181b || currentState.compareTo(EnumC1108q.f12183d) >= 0) {
            c2616g.d();
        } else {
            rVar.addObserver(new C1099h(rVar, c2616g));
        }
    }
}
