package com.ss.android.ugc.aweme.ecommercelive.business.audience.flashsale;

import X.1Bn;
import X.3Ok;
import X.C5847Hq4;
import X.C5852Hq9;
import X.C5871HqS;
import X.C5873HqU;
import X.C5878HqZ;
import X.LsC;
import X.M12;
import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import androidx.lifecycle.AndroidViewModel;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.List;

public final class FlashSaleViewModel extends AndroidViewModel {
    public static final C5873HqU LIZLLL = new C5873HqU((byte) 0);
    public boolean LIZ;
    public final 1Bn<List<C5878HqZ>> LIZIZ = new 1Bn<>();
    public final 1Bn<List<C5878HqZ>> LIZJ = new 1Bn<>();
    public List<? extends C5878HqZ> LJ;
    public final Handler LJFF = new Handler(Looper.getMainLooper());

    static {
        Covode.recordClassIndex(73194);
    }

    public final void onCleared() {
        FlashSaleViewModel.super.onCleared();
        LIZ();
        this.LJ = null;
    }

    public final void LIZ() {
        if (this.LIZ) {
            this.LJFF.removeCallbacksAndMessages((Object) null);
            this.LIZ = false;
            this.LIZIZ.setValue(new ArrayList());
            this.LIZJ.setValue(new ArrayList());
        }
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public FlashSaleViewModel(Application application) {
        super(application);
        M12.LIZ(application);
    }

    public final void LIZ(List<? extends C5878HqZ> list) {
        M12.LIZ(list);
        if (!this.LIZ) {
            this.LIZ = true;
            this.LJ = list;
            LIZIZ(list);
        }
    }

    public final C5878HqZ LIZ(LsC<? super C5878HqZ, Boolean> lsC) {
        M12.LIZ(lsC);
        List<? extends C5878HqZ> list = this.LJ;
        if (list == null) {
            return null;
        }
        for (C5878HqZ hqZ : list) {
            if (((Boolean) lsC.invoke(hqZ)).booleanValue()) {
                return hqZ;
            }
        }
        return null;
    }

    public final void LIZIZ(List<? extends C5878HqZ> list) {
        C5847Hq4 LIZIZ2;
        if (list != null && !list.isEmpty()) {
            long elapsedRealtime = SystemClock.elapsedRealtime();
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            boolean z = false;
            for (C5878HqZ hqZ : list) {
                if (hqZ.LIZ() && (LIZIZ2 = hqZ.LIZIZ()) != null) {
                    3Ok r1 = new 3Ok();
                    r1.element = false;
                    LIZIZ2.LIZ(new C5852Hq9(arrayList, hqZ, r1));
                    if (LIZIZ2.LIZ() || LIZIZ2.LIZIZ()) {
                        r1.element = true;
                        z = true;
                    }
                    if (r1.element) {
                        arrayList2.add(hqZ);
                    }
                }
            }
            if (!arrayList2.isEmpty()) {
                this.LIZJ.setValue(arrayList2);
            }
            if (!arrayList.isEmpty()) {
                this.LIZIZ.setValue(arrayList);
            }
            if (z) {
                this.LJFF.postDelayed(new C5871HqS(this, list), Math.max(0, 1000 - (SystemClock.elapsedRealtime() - elapsedRealtime)));
            }
        }
    }
}
