package com.ss.android.ugc.aweme.discover.mixfeed.cs;

import X.0Bt;
import X.0CM;
import X.0Gf;
import X.0Gp;
import X.2Pr;
import X.3Hc;
import X.7he;
import X.C3485Sa1;
import X.C3838Sfi;
import X.C3861Sg5;
import X.C4035Sit;
import X.C4098Sju;
import X.C4163Skx;
import X.C4164Sky;
import X.C4165Skz;
import X.Crj;
import X.LsC;
import X.M12;
import X.OeM;
import X.SYM;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.widgets.NextLiveData;
import com.ss.android.ugc.aweme.discover.api.SuggestWordsApi;
import com.ss.android.ugc.aweme.discover.model.suggest.ClickSearchResponse;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import java.lang.ref.WeakReference;
import java.util.List;
import kotlin.h.b.n;

public final class ClickSearchViewModel extends 0Bt {
    public WeakReference<Fragment> LIZ;
    public final Crj LIZIZ = 7he.LIZ(C4164Sky.LIZ);
    public final Crj LIZJ = 7he.LIZ(C4163Skx.LIZ);
    public final Crj LIZLLL = 7he.LIZ(C4165Skz.LIZ);

    static {
        Covode.recordClassIndex(64993);
    }

    private final NextLiveData<Integer> LIZLLL() {
        return (NextLiveData) this.LIZLLL.getValue();
    }

    public final NextLiveData<C3861Sg5> LIZ() {
        return (NextLiveData) this.LIZIZ.getValue();
    }

    public final NextLiveData<C4035Sit> LIZIZ() {
        return (NextLiveData) this.LIZJ.getValue();
    }

    public final void LIZJ() {
        LIZ().setValue(new C3861Sg5());
        LIZIZ().setValue((Object) null);
    }

    public final void LIZ(Integer num) {
        LIZLLL().setValue(num);
    }

    private final void LIZIZ(LsC<? super C4035Sit, 2Pr> lsC) {
        lsC.invoke(LIZIZ().getValue());
    }

    public final void LIZ(int i) {
        C4035Sit sit = (C4035Sit) LIZIZ().getValue();
        if (sit != null && sit.LIZ == i) {
            LIZIZ().setValue(new C4035Sit(i, C4098Sju.FINISHED));
        }
    }

    public final void LIZIZ(0CM<Integer> r3) {
        Fragment fragment;
        M12.LIZ(r3);
        NextLiveData<Integer> LIZLLL2 = LIZLLL();
        WeakReference<Fragment> weakReference = this.LIZ;
        if (weakReference != null) {
            fragment = (Fragment) weakReference.get();
        } else {
            fragment = null;
        }
        3Hc.LIZ(LIZLLL2, fragment, r3);
    }

    public final void LIZ(0CM<C3861Sg5> r3) {
        Fragment fragment;
        M12.LIZ(r3);
        WeakReference<Fragment> weakReference = this.LIZ;
        if (weakReference != null && (fragment = (Fragment) weakReference.get()) != null) {
            LIZ().observe(fragment, r3);
        }
    }

    public final void LIZ(LsC<? super C3861Sg5, 2Pr> lsC) {
        M12.LIZ(lsC);
        lsC.invoke(LIZ().getValue());
    }

    public final void LIZ(Fragment fragment) {
        M12.LIZ(fragment);
        this.LIZ = new WeakReference<>(fragment);
    }

    public final void LIZ(Aweme aweme, String str, int i) {
        OeM<ClickSearchResponse> oeM;
        ClickSearchResponse clickSearchResponse;
        List list;
        ClickSearchResponse clickSearchResponse2;
        List list2;
        String str2 = str;
        M12.LIZ(aweme, str2);
        int i2 = i;
        LIZIZ().setValue(new C4035Sit(i2, C4098Sju.DATA_FETCHING));
        String aid = aweme.getAid();
        C3861Sg5 sg5 = (C3861Sg5) LIZ().getValue();
        if (sg5 == null || (oeM = sg5.LIZLLL) == null || (clickSearchResponse = (ClickSearchResponse) oeM.LIZIZ) == null || (list = clickSearchResponse.wordsList) == null || list.size() <= 0 || sg5.LIZ != i2) {
            SuggestWordsApi suggestWordsApi = SuggestWordsApi.LIZIZ;
            SYM sym = new SYM();
            sym.LJFF = str2;
            sym.LJI = aid;
            suggestWordsApi.LIZLLL(sym).LIZ(new C3485Sa1(this, i2, aid, str2), 0Gp.LIZIZ, (0Gf) null);
            return;
        }
        OeM<ClickSearchResponse> oeM2 = sg5.LIZLLL;
        if (!(oeM2 == null || (clickSearchResponse2 = (ClickSearchResponse) oeM2.LIZIZ) == null || (list2 = clickSearchResponse2.wordsList) == null)) {
            Integer.valueOf(list2.size());
        }
        n.LIZIZ(aid, "");
        LIZ(i2, aid, str2, sg5.LIZLLL, false);
    }

    public final void LIZ(int i, String str, String str2, OeM<ClickSearchResponse> oeM, boolean z) {
        LIZIZ((LsC<? super C4035Sit, 2Pr>) new C3838Sfi(this, i, str, str2, oeM, z));
    }
}
