package com.bytedance.ext_power_list;

import X.2Pr;
import X.4h3;
import X.4r1;
import X.C0436Cwu;
import X.C0746D8s;
import X.C0782DAc;
import X.C1493Dab;
import X.C1663DdL;
import X.C1666DdO;
import X.C1683Ddf;
import X.C1695Ddr;
import X.C1699Ddv;
import X.C1702Ddy;
import X.C1703Ddz;
import X.C1704De0;
import X.C1705De1;
import X.C1706De2;
import X.C1707De3;
import X.C1711De7;
import X.C1712De8;
import X.C1713De9;
import X.C1714DeA;
import X.C1715DeB;
import X.C1716DeC;
import X.C1717DeD;
import X.C1718DeE;
import X.C1719DeF;
import X.C1720DeG;
import X.C1721DeH;
import X.C1722DeI;
import X.C1723DeJ;
import X.C1724DeK;
import X.C1726DeM;
import X.C1727DeN;
import X.C1728DeO;
import X.C1729DeP;
import X.C1730DeQ;
import X.C1732DeS;
import X.C1740Dea;
import X.C1743Ded;
import X.C1744Dee;
import X.C1745Def;
import X.DAU;
import X.DBT;
import X.DWM;
import X.Lea;
import X.Lel;
import X.Ls2;
import X.LsC;
import X.LsD;
import X.LsE;
import X.M12;
import com.bytedance.assem.arch.viewModel.AssemViewModel;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public abstract class AssemSingleListViewModel<ITEM, S extends C1493Dab<S, ITEM>, Cursor> extends AssemViewModel<S> {
    public C0436Cwu<? extends Cursor, ? extends Cursor> lastPageResult = new C0436Cwu<>(null, null);

    static {
        Covode.recordClassIndex(25810);
    }

    public abstract void newState(DWM<ITEM> dwm);

    public Object whenLoadLatest(Cursor cursor, 4r1<? super C1683Ddf<ITEM>> r3) {
        return C1683Ddf.LIZ.LIZ(Lel.INSTANCE);
    }

    public abstract Object whenLoadMore(Cursor cursor, 4r1<? super C1683Ddf<ITEM>> r2);

    public abstract Object whenRefresh(4r1<? super C1683Ddf<ITEM>> r1);

    public void listClear() {
        withState(new C1730DeQ(this));
    }

    public List<ITEM> listGetAll() {
        return getState().getListItemState();
    }

    public void manualListRefresh() {
        withState(new C1713De9(this));
    }

    public void listAddAll(Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1714DeA(this, collection));
    }

    public void listAddItem(ITEM item) {
        withState(new C1726DeM(this, item));
    }

    public void listRemoveItem(ITEM item) {
        withState(new C1727DeN(this, item));
    }

    public void listRemoveItemAt(int i) {
        withState(new C1732DeS(this, i));
    }

    public void listSetItem(ITEM item) {
        withState(new C1724DeK(this, item));
    }

    public void listSetItems(Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1716DeC(this, collection));
    }

    public ITEM listGetAt(int i) {
        List listItemState = getState().getListItemState();
        if (listItemState == null) {
            return null;
        }
        return listItemState.get(i);
    }

    public int listIndexOf(ITEM item) {
        List listItemState = getState().getListItemState();
        if (listItemState == null) {
            return -1;
        }
        return listItemState.indexOf(item);
    }

    public void manualListLoadLatest(Cursor cursor) {
        if (cursor != null || (cursor = this.lastPageResult.getFirst()) != null) {
            withState(new C1712De8(this, cursor));
        }
    }

    public void manualListLoadMore(Cursor cursor) {
        if (cursor != null || (cursor = this.lastPageResult.getSecond()) != null) {
            withState(new C1711De7(this, cursor));
        }
    }

    public void listAddAllAt(int i, Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1715DeB(this, i, collection));
    }

    public void listAddItemAt(int i, ITEM item) {
        withState(new C1728DeO(this, i, item));
    }

    public void listSetItemAt(int i, ITEM item) {
        withState(new C1729DeP(this, i, item));
    }

    public final void refreshInner(Ls2<Boolean> ls2, LsC<? super C1683Ddf<ITEM>, 2Pr> lsC) {
        Ls2<Boolean> ls22 = ls2;
        M12.LIZ(ls22);
        loadPage(C1663DdL.Refresh, ls22, lsC, new C1702Ddy(this, (4r1<? super C1702Ddy>) null), new C1721DeH(this), new C1705De1(this), C1718DeE.LIZ);
    }

    public final void modifyListState(S s, LsC<? super List<ITEM>, 2Pr> lsC) {
        List LJII;
        List listItemState = s.getListItemState();
        if (listItemState == null || (LJII = Lea.LJII(listItemState)) == null) {
            LJII = new ArrayList();
        }
        lsC.invoke(LJII);
        newState(DWM.LIZ(s.getListState(), (4h3) null, (4h3) null, (4h3) null, LJII, 7));
    }

    public void listSetItemsAt(int i, int i2, Collection<? extends ITEM> collection) {
        M12.LIZ(collection);
        withState(new C1717DeD(this, i, i2, collection));
    }

    public final void loadLatestInner(Cursor cursor, Ls2<Boolean> ls2, LsC<? super C1683Ddf<ITEM>, 2Pr> lsC) {
        Ls2<Boolean> ls22 = ls2;
        M12.LIZ(ls22);
        loadPage(C1663DdL.Prev, ls22, lsC, new C1703Ddz(this, cursor, (4r1<? super C1703Ddz>) null), new C1722DeI(this), new C1706De2(this), C1719DeF.LIZ);
    }

    public final void loadMoreInner(Cursor cursor, Ls2<Boolean> ls2, LsC<? super C1683Ddf<ITEM>, 2Pr> lsC) {
        Ls2<Boolean> ls22 = ls2;
        M12.LIZ(ls22);
        loadPage(C1663DdL.Next, ls22, lsC, new C1704De0(this, cursor, (4r1<? super C1704De0>) null), new C1723DeJ(this), new C1707De3(this), C1720DeG.LIZ);
    }

    public List<ITEM> onLoadPageAddData(C1663DdL ddL, List<? extends ITEM> list, List<? extends ITEM> list2) {
        M12.LIZ(ddL, list, list2);
        ArrayList arrayList = new ArrayList();
        int i = C1666DdO.LIZ[ddL.ordinal()];
        if (i == 1) {
            arrayList.addAll(list2);
        } else if (i == 2) {
            arrayList.addAll(list);
            arrayList.addAll(list2);
        } else if (i == 3) {
            arrayList.addAll(list2);
            arrayList.addAll(list);
        }
        return arrayList;
    }

    public static /* synthetic */ void manualListLoadLatest$default(AssemSingleListViewModel assemSingleListViewModel, Object obj, int i, Object obj2) {
        if (obj2 == null) {
            if ((i & 1) != 0) {
                obj = null;
            }
            assemSingleListViewModel.manualListLoadLatest(obj);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: manualListLoadLatest");
    }

    public static /* synthetic */ void manualListLoadMore$default(AssemSingleListViewModel assemSingleListViewModel, Object obj, int i, Object obj2) {
        if (obj2 == null) {
            if ((i & 1) != 0) {
                obj = null;
            }
            assemSingleListViewModel.manualListLoadMore(obj);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: manualListLoadMore");
    }

    public static /* synthetic */ void refreshInner$default(AssemSingleListViewModel assemSingleListViewModel, C1743Ded ded, LsC lsC, int i, Object obj) {
        if (obj == null) {
            if ((i & 1) != 0) {
                ded = C1743Ded.LIZ;
            }
            if ((i & 2) != 0) {
                lsC = null;
            }
            assemSingleListViewModel.refreshInner(ded, lsC);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: refreshInner");
    }

    public final void handleState(C1663DdL ddL, C1683Ddf<ITEM> ddf, LsE<? super DWM<ITEM>, ? super Cursor, ? super Cursor, DWM<ITEM>> lsE, LsD<? super DWM<ITEM>, ? super Throwable, DWM<ITEM>> lsD, Ls2<2Pr> ls2) {
        C1683Ddf<ITEM> ddf2 = ddf;
        C1663DdL ddL2 = ddL;
        LsE<? super DWM<ITEM>, ? super Cursor, ? super Cursor, DWM<ITEM>> lsE2 = lsE;
        LsD<? super DWM<ITEM>, ? super Throwable, DWM<ITEM>> lsD2 = lsD;
        M12.LIZ(ddL2, ddf2, lsE2, lsD2);
        withState(new C1695Ddr(ddf2, this, ddL2, lsE2, lsD2, ls2));
    }

    public static /* synthetic */ void loadLatestInner$default(AssemSingleListViewModel assemSingleListViewModel, Object obj, C1744Dee dee, LsC lsC, int i, Object obj2) {
        if (obj2 == null) {
            if ((i & 2) != 0) {
                dee = C1744Dee.LIZ;
            }
            if ((i & 4) != 0) {
                lsC = null;
            }
            assemSingleListViewModel.loadLatestInner(obj, dee, lsC);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: loadLatestInner");
    }

    public static /* synthetic */ void loadMoreInner$default(AssemSingleListViewModel assemSingleListViewModel, Object obj, C1745Def def, LsC lsC, int i, Object obj2) {
        if (obj2 == null) {
            if ((i & 2) != 0) {
                def = C1745Def.LIZ;
            }
            if ((i & 4) != 0) {
                lsC = null;
            }
            assemSingleListViewModel.loadMoreInner(obj, def, lsC);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: loadMoreInner");
    }

    private final void loadPage(C1663DdL ddL, Ls2<Boolean> ls2, LsC<? super C1683Ddf<ITEM>, 2Pr> lsC, LsC<? super 4r1<? super C1683Ddf<ITEM>>, ? extends Object> lsC2, Ls2<2Pr> ls22, LsE<? super DWM<ITEM>, ? super Cursor, ? super Cursor, DWM<ITEM>> lsE, LsD<? super DWM<ITEM>, ? super Throwable, DWM<ITEM>> lsD) {
        ls22.invoke();
        LsD<? super DWM<ITEM>, ? super Throwable, DWM<ITEM>> lsD2 = lsD;
        LsE<? super DWM<ITEM>, ? super Cursor, ? super Cursor, DWM<ITEM>> lsE2 = lsE;
        DBT unused = C0782DAc.LIZ(getAssemVMScope(), (C0746D8s) null, (DAU) null, new C1699Ddv(this, ls2, ddL, lsE2, lsD2, lsC2, lsC, (4r1<? super C1699Ddv>) null), 3);
    }

    public static /* synthetic */ void handleState$default(AssemSingleListViewModel assemSingleListViewModel, C1663DdL ddL, C1683Ddf ddf, LsE lsE, LsD lsD, Ls2 ls2, int i, Object obj) {
        if (obj == null) {
            if ((i & 16) != 0) {
                ls2 = null;
            }
            assemSingleListViewModel.handleState(ddL, ddf, lsE, lsD, ls2);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: handleState");
    }

    public static /* synthetic */ void loadPage$default(AssemSingleListViewModel assemSingleListViewModel, C1663DdL ddL, C1740Dea dea, LsC lsC, LsC lsC2, Ls2 ls2, LsE lsE, LsD lsD, int i, Object obj) {
        if (obj == null) {
            if ((i & 2) != 0) {
                dea = C1740Dea.LIZ;
            }
            if ((i & 4) != 0) {
                lsC = null;
            }
            assemSingleListViewModel.loadPage(ddL, dea, lsC, lsC2, ls2, lsE, lsD);
            return;
        }
        throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: loadPage");
    }
}
