package androidx.lifecycle;

import X.2GD;
import X.AnonymousClass0CB;
import X.AnonymousClass0CC;
import X.AnonymousClass0CD;
import X.AnonymousClass0CH;
import X.C02940Bg;
import X.C03060Bs;
import X.C03070Bt;
import X.C03110Bx;
import X.C03130Bz;
import X.C28391Bd;
import X.C28451Bj;
import X.M12;
import com.bytedance.covode.number.Covode;
import com.bytedance.provider.vm.ScopeViewModel;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Set;

public final class SharedViewModelProvider extends C03110Bx {
    public static final C02940Bg LIZ = new C02940Bg((byte) 0);
    public static final C03130Bz LIZLLL = new C03130Bz();
    public static final HashMap<String, Set<AnonymousClass0CD>> LJ = new HashMap<>();
    public C03130Bz LIZIZ;
    public HashMap<String, Set<AnonymousClass0CD>> LIZJ;

    public /* synthetic */ SharedViewModelProvider() {
        this(new C28391Bd());
    }

    static {
        Covode.recordClassIndex(1220);
    }

    public final <T extends C03070Bt> T LIZ(Class<T> cls) {
        M12.LIZ(cls);
        throw new IllegalAccessException("Unsupport get viewmodel without lifecycle, please use method get(Lifecycle,Class) or get(Lifecycle,String,Class) instead");
    }

    /* JADX WARNING: Illegal instructions before constructor call */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public SharedViewModelProvider(X.C03090Bv r2) {
        /*
            r1 = this;
            X.M12.LIZ(r2)
            X.0Bz r0 = LIZLLL
            r1.<init>((X.C03130Bz) r0, (X.C03090Bv) r2)
            r1.LIZIZ = r0
            java.util.HashMap<java.lang.String, java.util.Set<X.0CD>> r0 = LJ
            r1.LIZJ = r0
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.lifecycle.SharedViewModelProvider.<init>(X.0Bv):void");
    }

    public static final class ClearUselessViewModelObserver implements C28451Bj {
        public final AnonymousClass0CD LIZ;
        public final String LIZIZ;
        public final C03130Bz LIZJ;
        public final HashMap<String, Set<AnonymousClass0CD>> LIZLLL;

        static {
            Covode.recordClassIndex(1221);
        }

        public final void onStateChanged(AnonymousClass0CH r4, AnonymousClass0CB r5) {
            M12.LIZ(r4, r5);
            if (r5 == AnonymousClass0CB.ON_DESTROY) {
                Set<AnonymousClass0CD> set = this.LIZLLL.get(this.LIZIZ);
                if (set == null) {
                    set = new LinkedHashSet<>();
                }
                Set set2 = set;
                set2.remove(this.LIZ);
                if (set2.isEmpty()) {
                    C03130Bz.LIZ(this.LIZJ, this.LIZIZ, (C03070Bt) null);
                    this.LIZLLL.remove(this.LIZIZ);
                }
            }
        }

        public ClearUselessViewModelObserver(AnonymousClass0CD r1, String str, C03130Bz r3, HashMap<String, Set<AnonymousClass0CD>> hashMap) {
            M12.LIZ(r1, str, r3, hashMap);
            this.LIZ = r1;
            this.LIZIZ = str;
            this.LIZJ = r3;
            this.LIZLLL = hashMap;
        }
    }

    public final <T extends C03070Bt> T LIZ(AnonymousClass0CD r3, Class<T> cls) {
        M12.LIZ(r3, cls);
        String canonicalName = cls.getCanonicalName();
        if (canonicalName != null) {
            return LIZ(r3, "androidx.lifecycle.ViewModelProvider.DefaultKey:".concat(String.valueOf(canonicalName)), cls);
        }
        throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels");
    }

    public final <T extends C03070Bt> T LIZ(String str, Class<T> cls) {
        M12.LIZ(str, cls);
        throw new IllegalAccessException("Unsupport get viewmodel without lifecycle, please use method get(Lifecycle,Class) or get(Lifecycle,String,Class) instead");
    }

    public static C03070Bt LIZ(C03110Bx r2, String str, Class cls) {
        if (cls.equals(ScopeViewModel.class)) {
            return super.LIZ(str, cls);
        }
        C03070Bt LIZ2 = super.LIZ(str, cls);
        if (2GD.LIZ) {
            C03060Bs.LIZ(LIZ2, r2);
        }
        return LIZ2;
    }

    public final <T extends C03070Bt> T LIZ(AnonymousClass0CD r5, String str, Class<T> cls) {
        M12.LIZ(r5, str, cls);
        if (r5.LIZ() != AnonymousClass0CC.DESTROYED) {
            T LIZ2 = LIZ((C03110Bx) this, str, (Class) cls);
            Set<AnonymousClass0CD> set = this.LIZJ.get(str);
            if (set == null) {
                set = new LinkedHashSet<>();
            }
            Set set2 = set;
            this.LIZJ.put(str, set2);
            if (!set2.contains(r5)) {
                set2.add(r5);
                r5.LIZ(new ClearUselessViewModelObserver(r5, str, this.LIZIZ, this.LIZJ));
            }
            return LIZ2;
        }
        throw new IllegalStateException("Could not get viewmodel when lifecycle was destroyed");
    }
}
