package h3;

import V2.AbstractC0696m3;
import V2.C0746z1;
import android.os.SystemClock;
import android.view.KeyEvent;
import androidx.compose.runtime.MutableIntState;
import androidx.compose.runtime.MutableLongState;
import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.State;
import com.debridstream.tv.HomeSection;
import com.debridstream.tv.data.home.HomeMetaItem;
import java.util.HashMap;
import java.util.List;
import w4.C3137A;
import x4.AbstractC3251q;
import x4.AbstractC3252r;

/* JADX INFO: loaded from: classes.dex */
public final class Y4 implements J4.c {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final /* synthetic */ MutableState f17634A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final /* synthetic */ MutableState f17635B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final /* synthetic */ MutableLongState f17636C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public final /* synthetic */ State f17637D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final /* synthetic */ V4.C f17638E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final /* synthetic */ D.H f17639F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final /* synthetic */ C2220x4 f17640G;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ List f17641a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ boolean f17642b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ boolean f17643c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ List f17644d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ MutableState f17645e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ MutableState f17646f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ MutableState f17647j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ HomeMetaItem f17648k;
    public final /* synthetic */ MutableIntState l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final /* synthetic */ State f17649m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final /* synthetic */ MutableIntState f17650n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final /* synthetic */ State f17651o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final /* synthetic */ State f17652p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ State f17653q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ MutableIntState f17654r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final /* synthetic */ State f17655s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final /* synthetic */ State f17656t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final /* synthetic */ State f17657u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final /* synthetic */ MutableState f17658v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ MutableIntState f17659w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final /* synthetic */ HashMap f17660x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final /* synthetic */ MutableState f17661y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final /* synthetic */ MutableState f17662z;

    public Y4(List list, boolean z6, boolean z7, List list2, MutableState mutableState, MutableState mutableState2, MutableState mutableState3, HomeMetaItem homeMetaItem, MutableIntState mutableIntState, State state, MutableIntState mutableIntState2, State state2, State state3, State state4, MutableIntState mutableIntState3, State state5, State state6, State state7, MutableState mutableState4, MutableIntState mutableIntState4, HashMap map, MutableState mutableState5, MutableState mutableState6, MutableState mutableState7, MutableState mutableState8, MutableLongState mutableLongState, State state8, V4.C c6, D.H h5, C2220x4 c2220x4) {
        this.f17641a = list;
        this.f17642b = z6;
        this.f17643c = z7;
        this.f17644d = list2;
        this.f17645e = mutableState;
        this.f17646f = mutableState2;
        this.f17647j = mutableState3;
        this.f17648k = homeMetaItem;
        this.l = mutableIntState;
        this.f17649m = state;
        this.f17650n = mutableIntState2;
        this.f17651o = state2;
        this.f17652p = state3;
        this.f17653q = state4;
        this.f17654r = mutableIntState3;
        this.f17655s = state5;
        this.f17656t = state6;
        this.f17657u = state7;
        this.f17658v = mutableState4;
        this.f17659w = mutableIntState4;
        this.f17660x = map;
        this.f17661y = mutableState5;
        this.f17662z = mutableState6;
        this.f17634A = mutableState7;
        this.f17635B = mutableState8;
        this.f17636C = mutableLongState;
        this.f17637D = state8;
        this.f17638E = c6;
        this.f17639F = h5;
        this.f17640G = c2220x4;
    }

    public static final int a(List list, HashMap map, State state, int i6) {
        Integer num;
        HomeSection homeSection = (HomeSection) AbstractC3251q.h0(i6, list);
        if (homeSection == null || (num = (Integer) map.get(homeSection.getId())) == null) {
            return 0;
        }
        int iIntValue = num.intValue();
        String id = homeSection.getId();
        List<HomeMetaItem> items = homeSection.getItems();
        float f6 = n5.f18281a;
        int size = n5.v(((Boolean) ((J4.c) state.getValue()).invoke(homeSection)).booleanValue() ? 19 : 30, items, id).size() - 1;
        if (size < 0) {
            size = 0;
        }
        return L4.a.v(iIntValue, 0, size);
    }

    public static final void b(MutableLongState mutableLongState, int i6, J4.a aVar) {
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        float f6 = n5.f18281a;
        long longValue = jElapsedRealtime - mutableLongState.getLongValue();
        if (0 > longValue || longValue > i6) {
            mutableLongState.setLongValue(jElapsedRealtime);
            aVar.invoke();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00d2  */
    @Override // J4.c
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invoke(Object obj) {
        final MutableIntState mutableIntState;
        boolean z6;
        boolean z7;
        HomeMetaItem homeMetaItem;
        HomeMetaItem homeMetaItem2;
        KeyEvent event = ((A0.c) obj).f76a;
        kotlin.jvm.internal.o.h(event, "event");
        MutableState mutableState = this.f17645e;
        if (((HomeMetaItem) mutableState.getValue()) != null) {
            return Boolean.FALSE;
        }
        boolean z8 = event.getKeyCode() == 23 || event.getKeyCode() == 66 || event.getKeyCode() == 160;
        MutableIntState mutableIntState2 = this.f17654r;
        final List listV = this.f17644d;
        final List list = this.f17641a;
        final MutableIntState mutableIntState3 = this.l;
        final MutableIntState mutableIntState4 = this.f17650n;
        MutableState mutableState2 = this.f17646f;
        MutableState mutableState3 = this.f17647j;
        if (z8 && A0.d.c(event) == 1) {
            if (((Boolean) mutableState2.getValue()).booleanValue()) {
                mutableState2.setValue(Boolean.FALSE);
                return Boolean.TRUE;
            }
            if (((Boolean) mutableState3.getValue()).booleanValue()) {
                mutableState3.setValue(Boolean.FALSE);
                return Boolean.TRUE;
            }
            if (event.isCanceled()) {
                return Boolean.FALSE;
            }
            float f6 = n5.f18281a;
            if (mutableIntState3.getIntValue() == -2) {
                State state = this.f17649m;
                if (((List) state.getValue()).isEmpty()) {
                    int intValue = mutableIntState3.getIntValue();
                    State state2 = this.f17652p;
                    if (intValue == -1) {
                        HomeMetaItem homeMetaItem3 = this.f17648k;
                        if (homeMetaItem3 != null) {
                            ((J4.c) state2.getValue()).invoke(homeMetaItem3);
                        }
                    } else {
                        HomeSection homeSection = (HomeSection) AbstractC3251q.h0(mutableIntState3.getIntValue(), list);
                        if (homeSection != null) {
                            int i6 = ((Boolean) ((J4.c) this.f17653q.getValue()).invoke(homeSection)).booleanValue() ? 19 : 30;
                            if (listV.isEmpty()) {
                                listV = n5.v(i6, homeSection.getItems(), homeSection.getId());
                            }
                            InterfaceC2214w4 interfaceC2214w4 = (InterfaceC2214w4) AbstractC3251q.h0(mutableIntState2.getIntValue(), listV);
                            if (interfaceC2214w4 != null) {
                                boolean z9 = interfaceC2214w4 instanceof C2208v4;
                                if (z9) {
                                    J4.e eVar = (J4.e) this.f17655s.getValue();
                                    EnumC2203v enumC2203v = (EnumC2203v) this.f17656t.getValue();
                                    if (eVar != null && enumC2203v != null && homeSection.getItems().size() > i6) {
                                        eVar.invoke(enumC2203v, homeSection);
                                    }
                                } else {
                                    if (interfaceC2214w4 instanceof C2202u4) {
                                        homeMetaItem2 = ((C2202u4) interfaceC2214w4).f18592a;
                                    } else if (interfaceC2214w4 instanceof C2196t4) {
                                        homeMetaItem2 = ((C2196t4) interfaceC2214w4).f18557a;
                                    } else {
                                        if (!z9) {
                                            throw new E3.v();
                                        }
                                        homeMetaItem2 = null;
                                    }
                                    if (homeMetaItem2 != null) {
                                        if (kotlin.jvm.internal.o.c(homeSection.getId(), n5.f18314t)) {
                                            ((J4.c) this.f17657u.getValue()).invoke(homeMetaItem2);
                                        } else {
                                            ((J4.c) state2.getValue()).invoke(homeMetaItem2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } else {
                    int iV = L4.a.v(mutableIntState4.getIntValue(), 0, AbstractC3252r.A((List) state.getValue()));
                    C0746z1 c0746z1 = (C0746z1) ((List) state.getValue()).get(iV);
                    AbstractC0696m3.e0 = Integer.valueOf(iV >= 0 ? iV : 0);
                    ((J4.e) this.f17651o.getValue()).invoke(c0746z1.f8209a, c0746z1.f8210b);
                }
            }
            return Boolean.TRUE;
        }
        if (A0.d.c(event) != 2) {
            return Boolean.FALSE;
        }
        if (list.isEmpty() && !this.f17642b && !this.f17643c) {
            return Boolean.FALSE;
        }
        int keyCode = event.getKeyCode();
        if (keyCode == 66 || keyCode == 160) {
            mutableIntState = mutableIntState2;
        } else {
            MutableLongState mutableLongState = this.f17636C;
            mutableIntState = mutableIntState2;
            final MutableState mutableState4 = this.f17662z;
            switch (keyCode) {
                case 19:
                    b(mutableLongState, 200, new J3(this.f17643c, mutableIntState3, this.f17637D, this.f17661y, mutableState4, mutableIntState, this.f17634A, this.f17635B, this.f17658v, list, this.f17660x, this.f17649m, mutableIntState4, this.f17659w, this.f17653q));
                    z7 = true;
                    return Boolean.valueOf(z7);
                case 20:
                    b(mutableLongState, 200, new T4(list, mutableIntState3, this.f17658v, this.f17649m, mutableIntState4, this.f17659w, mutableIntState, this.f17660x, this.f17653q, this.f17661y, mutableState4, this.f17634A, this.f17635B));
                    z7 = true;
                    return Boolean.valueOf(z7);
                case 21:
                    b(mutableLongState, mutableIntState3.getIntValue() == -2 ? 80 : 200, new T4(list, this.f17638E, listV, mutableIntState3, this.f17649m, mutableState4, mutableIntState4, this.f17653q, this.f17635B, this.f17634A, this.f17659w, mutableIntState, this.f17640G));
                    z7 = true;
                    return Boolean.valueOf(z7);
                case 22:
                    int i7 = mutableIntState3.getIntValue() == -2 ? 80 : 200;
                    final MutableState mutableState5 = this.f17634A;
                    final V4.C c6 = this.f17638E;
                    final State state3 = this.f17649m;
                    final MutableState mutableState6 = this.f17661y;
                    final D.H h5 = this.f17639F;
                    final State state4 = this.f17653q;
                    final MutableState mutableState7 = this.f17635B;
                    final MutableIntState mutableIntState5 = this.f17659w;
                    final C2220x4 c2220x4 = this.f17640G;
                    b(mutableLongState, i7, new J4.a() { // from class: h3.U4
                        /* JADX WARN: Multi-variable type inference failed */
                        @Override // J4.a
                        public final Object invoke() {
                            float f7 = n5.f18281a;
                            MutableIntState mutableIntState6 = mutableIntState3;
                            int intValue2 = mutableIntState6.getIntValue();
                            V4.C c7 = c6;
                            if (intValue2 == -2) {
                                int size = ((List) state3.getValue()).size();
                                if (size > 0) {
                                    MutableState mutableState8 = mutableState4;
                                    if (!((Boolean) mutableState8.getValue()).booleanValue()) {
                                        int i8 = size - 1;
                                        MutableIntState mutableIntState7 = mutableIntState4;
                                        if (mutableIntState7.getIntValue() >= i8) {
                                            mutableIntState7.setIntValue(0);
                                            MutableState mutableState9 = mutableState6;
                                            n5.r(mutableState9, mutableState8);
                                            mutableState8.setValue(Boolean.TRUE);
                                            mutableState9.setValue(V4.E.y(c7, null, null, new V4(h5, size, mutableState8, mutableState9, null), 3));
                                        } else {
                                            mutableIntState7.setIntValue(mutableIntState7.getIntValue() + 1);
                                        }
                                    }
                                }
                            } else {
                                HomeSection homeSection2 = (HomeSection) AbstractC3251q.h0(mutableIntState6.getIntValue(), list);
                                if (homeSection2 != null) {
                                    int i9 = ((Boolean) ((J4.c) state4.getValue()).invoke(homeSection2)).booleanValue() ? 19 : 30;
                                    List listV2 = listV;
                                    if (listV2.isEmpty()) {
                                        listV2 = n5.v(i9, homeSection2.getItems(), homeSection2.getId());
                                    }
                                    if (!listV2.isEmpty()) {
                                        MutableState mutableState10 = mutableState7;
                                        if (!((Boolean) mutableState10.getValue()).booleanValue()) {
                                            MutableState mutableState11 = mutableState5;
                                            n5.s(mutableState11, mutableState10);
                                            int i10 = homeSection2.getItems().size() > i9 ? i9 : -1;
                                            MutableIntState mutableIntState8 = mutableIntState;
                                            MutableIntState mutableIntState9 = mutableIntState5;
                                            if (i10 < 0 || mutableIntState8.getIntValue() != i10) {
                                                mutableIntState9.setIntValue(mutableIntState8.getIntValue());
                                                mutableIntState8.setIntValue(mutableIntState8.getIntValue() >= AbstractC3252r.A(listV2) ? AbstractC3252r.A(listV2) : mutableIntState8.getIntValue() + 1);
                                            } else {
                                                int i11 = homeSection2.getItems().size() > i9 ? i9 + 1 : -1;
                                                mutableIntState9.setIntValue(mutableIntState8.getIntValue());
                                                mutableState10.setValue(Boolean.TRUE);
                                                mutableIntState8.setIntValue(0);
                                                mutableState11.setValue(V4.E.y(c7, null, null, new W4(c2220x4, homeSection2.getId(), i11, mutableState10, mutableState11, null), 3));
                                            }
                                        }
                                    }
                                }
                            }
                            return C3137A.f25453a;
                        }
                    });
                    z7 = true;
                    return Boolean.valueOf(z7);
                case 23:
                    break;
                default:
                    z7 = false;
                    return Boolean.valueOf(z7);
            }
        }
        if (event.getKeyCode() != 23 && event.getKeyCode() != 66 && event.getKeyCode() != 160) {
            return Boolean.FALSE;
        }
        int repeatCount = event.getRepeatCount();
        if (repeatCount != 0) {
            if (repeatCount == 1) {
                if (mutableIntState3.getIntValue() == -1) {
                    Boolean bool = Boolean.TRUE;
                    mutableState3.setValue(bool);
                    return bool;
                }
                HomeSection homeSection2 = (HomeSection) AbstractC3251q.h0(mutableIntState3.getIntValue(), list);
                if (homeSection2 == null) {
                    return Boolean.TRUE;
                }
                if (kotlin.jvm.internal.o.c(homeSection2.getId(), n5.f18314t)) {
                    InterfaceC2214w4 interfaceC2214w42 = (InterfaceC2214w4) AbstractC3251q.h0(mutableIntState.getIntValue(), listV);
                    if (interfaceC2214w42 == null) {
                        return Boolean.TRUE;
                    }
                    boolean z10 = interfaceC2214w42 instanceof C2208v4;
                    if (!z10) {
                        if (interfaceC2214w42 instanceof C2202u4) {
                            homeMetaItem = ((C2202u4) interfaceC2214w42).f18592a;
                        } else if (interfaceC2214w42 instanceof C2196t4) {
                            homeMetaItem = ((C2196t4) interfaceC2214w42).f18557a;
                        } else {
                            if (!z10) {
                                throw new E3.v();
                            }
                            homeMetaItem = null;
                        }
                        if (homeMetaItem != null && homeMetaItem.getTmdbId() > 0) {
                            mutableState.setValue(homeMetaItem);
                            n5.o(mutableState2, true);
                            return Boolean.TRUE;
                        }
                    }
                }
                z6 = true;
                mutableState3.setValue(Boolean.TRUE);
            }
            z7 = true;
            return Boolean.valueOf(z7);
        }
        z6 = true;
        mutableState3.setValue(Boolean.FALSE);
        z7 = z6;
        return Boolean.valueOf(z7);
    }
}
