package ῲ.ؿ;

import androidx.lifecycle.Lifecycle;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Map;
import ῲ.ʬ.K.ῲ.C1499;
import ῲ.ʬ.K.ῲ.C1506;

/* renamed from: ῲ.ؿ.㿎  reason: contains not printable characters */
/* compiled from: LifecycleRegistry */
public class C1584 extends Lifecycle {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final WeakReference<AbstractC1574> f5749;

    /* renamed from: ඓ  reason: contains not printable characters */
    public boolean f5750 = false;

    /* renamed from: ῲ  reason: contains not printable characters */
    public Lifecycle.State f5751;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public ArrayList<Lifecycle.State> f5752 = new ArrayList<>();

    /* renamed from: K  reason: contains not printable characters */
    public C1506<AbstractC1582, C1585> f5753 = new C1506<>();

    /* renamed from: 㴹  reason: contains not printable characters */
    public boolean f5754 = false;

    /* renamed from: 㸾  reason: contains not printable characters */
    public int f5755 = 0;

    /* renamed from: ῲ.ؿ.㿎$K  reason: contains not printable characters */
    /* compiled from: LifecycleRegistry */
    public static class C1585 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public AbstractC1569 f5756;

        /* renamed from: K  reason: contains not printable characters */
        public Lifecycle.State f5757;

        public C1585(AbstractC1582 r1, Lifecycle.State state) {
            this.f5756 = C1581.m4137(r1);
            this.f5757 = state;
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m4147(AbstractC1574 r3, Lifecycle.Event event) {
            Lifecycle.State r0 = C1584.m4139(event);
            this.f5757 = C1584.m4140(this.f5757, r0);
            this.f5756.m4113(r3, event);
            this.f5757 = r0;
        }
    }

    public C1584(AbstractC1574 r2) {
        this.f5749 = new WeakReference<>(r2);
        this.f5751 = Lifecycle.State.INITIALIZED;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public final Lifecycle.State m4141(AbstractC1582 r4) {
        C1506<AbstractC1582, C1585> k = this.f5753;
        Lifecycle.State state = null;
        C1499.C1500<K, V> r42 = k.f5553.containsKey(r4) ? k.f5553.get(r4).f5545 : null;
        Lifecycle.State state2 = r42 != null ? ((C1585) r42.getValue()).f5757 : null;
        if (!this.f5752.isEmpty()) {
            ArrayList<Lifecycle.State> arrayList = this.f5752;
            state = arrayList.get(arrayList.size() - 1);
        }
        return m4140(m4140(this.f5751, state2), state);
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m4144(Lifecycle.Event event) {
        m4145(m4139(event));
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m4145(Lifecycle.State state) {
        if (this.f5751 != state) {
            this.f5751 = state;
            if (this.f5750 || this.f5755 != 0) {
                this.f5754 = true;
                return;
            }
            this.f5750 = true;
            m4142();
            this.f5750 = false;
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static Lifecycle.State m4139(Lifecycle.Event event) {
        int ordinal = event.ordinal();
        if (ordinal != 0) {
            if (ordinal != 1) {
                if (ordinal == 2) {
                    return Lifecycle.State.RESUMED;
                }
                if (ordinal != 3) {
                    if (ordinal != 4) {
                        if (ordinal == 5) {
                            return Lifecycle.State.DESTROYED;
                        }
                        throw new IllegalArgumentException("Unexpected event value " + event);
                    }
                }
            }
            return Lifecycle.State.STARTED;
        }
        return Lifecycle.State.CREATED;
    }

    @Override // androidx.lifecycle.Lifecycle
    /* renamed from: K  reason: contains not printable characters */
    public void m4146(AbstractC1582 r7) {
        AbstractC1574 r1;
        Lifecycle.State state = this.f5751;
        Lifecycle.State state2 = Lifecycle.State.DESTROYED;
        if (state != state2) {
            state2 = Lifecycle.State.INITIALIZED;
        }
        C1585 k = new C1585(r7, state2);
        if (this.f5753.m3843(r7, k) == null && (r1 = this.f5749.get()) != null) {
            boolean z = this.f5755 != 0 || this.f5750;
            Lifecycle.State r4 = m4141(r7);
            this.f5755++;
            while (k.f5757.compareTo((Enum) r4) < 0 && this.f5753.f5553.containsKey(r7)) {
                this.f5752.add(k.f5757);
                k.m4147(r1, m4138(k.f5757));
                m4143();
                r4 = m4141(r7);
            }
            if (!z) {
                m4142();
            }
            this.f5755--;
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public static Lifecycle.Event m4138(Lifecycle.State state) {
        int ordinal = state.ordinal();
        if (ordinal == 0 || ordinal == 1) {
            return Lifecycle.Event.ON_CREATE;
        }
        if (ordinal == 2) {
            return Lifecycle.Event.ON_START;
        }
        if (ordinal == 3) {
            return Lifecycle.Event.ON_RESUME;
        }
        if (ordinal != 4) {
            throw new IllegalArgumentException("Unexpected state value " + state);
        }
        throw new IllegalArgumentException();
    }

    /* JADX DEBUG: Multi-variable search result rejected for r4v4, resolved type: ῲ.ʬ.K.ῲ.K<ῲ.ؿ.㴹, ῲ.ؿ.㿎$K> */
    /* JADX DEBUG: Multi-variable search result rejected for r5v7, resolved type: ῲ.ʬ.K.ῲ.K<ῲ.ؿ.㴹, ῲ.ؿ.㿎$K> */
    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ῲ  reason: contains not printable characters */
    public final void m4142() {
        Lifecycle.Event event;
        Lifecycle.State state;
        AbstractC1574 r0 = this.f5749.get();
        if (r0 != null) {
            while (true) {
                C1506<AbstractC1582, C1585> k = this.f5753;
                if (!(k.f5541 == 0 || (k.f5542.getValue().f5757 == (state = this.f5753.f5540.getValue().f5757) && this.f5751 == state))) {
                    this.f5754 = false;
                    if (this.f5751.compareTo((Enum) this.f5753.f5542.getValue().f5757) < 0) {
                        C1506<AbstractC1582, C1585> k2 = this.f5753;
                        C1499.C1502 r2 = new C1499.C1502(k2.f5540, k2.f5542);
                        k2.f5543.put(r2, false);
                        while (r2.hasNext() && !this.f5754) {
                            Map.Entry entry = (Map.Entry) r2.next();
                            C1585 k3 = (C1585) entry.getValue();
                            while (k3.f5757.compareTo((Enum) this.f5751) > 0 && !this.f5754 && this.f5753.contains(entry.getKey())) {
                                Lifecycle.State state2 = k3.f5757;
                                int ordinal = state2.ordinal();
                                if (ordinal == 0) {
                                    throw new IllegalArgumentException();
                                } else if (ordinal != 1) {
                                    if (ordinal == 2) {
                                        event = Lifecycle.Event.ON_DESTROY;
                                    } else if (ordinal == 3) {
                                        event = Lifecycle.Event.ON_STOP;
                                    } else if (ordinal == 4) {
                                        event = Lifecycle.Event.ON_PAUSE;
                                    } else {
                                        throw new IllegalArgumentException("Unexpected state value " + state2);
                                    }
                                    this.f5752.add(m4139(event));
                                    k3.m4147(r0, event);
                                    m4143();
                                } else {
                                    throw new IllegalArgumentException();
                                }
                            }
                        }
                    }
                    C1499.C1500<K, V> r1 = this.f5753.f5540;
                    if (!this.f5754 && r1 != null && this.f5751.compareTo((Enum) r1.getValue().f5757) > 0) {
                        C1499<K, V>.C1505 r12 = this.f5753.m3832();
                        while (r12.hasNext() && !this.f5754) {
                            Map.Entry entry2 = (Map.Entry) r12.next();
                            C1585 k4 = (C1585) entry2.getValue();
                            while (k4.f5757.compareTo((Enum) this.f5751) < 0 && !this.f5754 && this.f5753.contains(entry2.getKey())) {
                                this.f5752.add(k4.f5757);
                                k4.m4147(r0, m4138(k4.f5757));
                                m4143();
                            }
                        }
                    }
                } else {
                    this.f5754 = false;
                    return;
                }
            }
        } else {
            throw new IllegalStateException("LifecycleOwner of this LifecycleRegistry is alreadygarbage collected. It is too late to change lifecycle state.");
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m4143() {
        ArrayList<Lifecycle.State> arrayList = this.f5752;
        arrayList.remove(arrayList.size() - 1);
    }

    /* renamed from: K  reason: contains not printable characters */
    public static Lifecycle.State m4140(Lifecycle.State state, Lifecycle.State state2) {
        return (state2 == null || state2.compareTo(state) >= 0) ? state : state2;
    }
}
