package com.ss.android.ugc.aweme.discover.ui.search.jsbridge;

import X.0CB;
import X.0CH;
import X.0CN;
import X.2cN;
import X.4UQ;
import X.6Is;
import X.7hA;
import X.C3839Sfj;
import X.KT7;
import X.Las;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.PgV;
import X.PhE;
import X.PlI;
import X.SSD;
import X.SSG;
import X.SSH;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.bullet.bridge.BaseBridgeMethod;
import com.ss.android.ugc.aweme.discover.api.SearchApiNew;
import org.json.JSONObject;

public final class HorizontalLoadMoreMethod extends BaseBridgeMethod implements 6Is {
    public static final SSG LIZLLL = new SSG((byte) 0);
    public 2cN LIZIZ;
    public C3839Sfj LIZJ;
    public final String LJ = "horizontalLoadMore";

    static {
        Covode.recordClassIndex(65896);
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        HorizontalLoadMoreMethod.super.onStateChanged(r2, r3);
        if (r3 == 0CB.ON_DESTROY) {
            disposableObservable();
        }
    }

    public final String LIZLLL() {
        return this.LJ;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void disposableObservable() {
        2cN r0 = this.LIZIZ;
        if (r0 != null) {
            r0.dispose();
        }
    }

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

    public final void LIZ(JSONObject jSONObject, 4UQ r17) {
        String str;
        String str2;
        4UQ r3 = r17;
        JSONObject jSONObject2 = jSONObject;
        M12.LIZ(jSONObject2, r3);
        this.LIZIZ = null;
        int optInt = jSONObject2.optInt("sessionId", -1);
        JSONObject optJSONObject = jSONObject2.optJSONObject("params");
        C3839Sfj LIZIZ2 = Las.LIZJ.LIZIZ(optInt);
        this.LIZJ = LIZIZ2;
        if (optJSONObject == null || LIZIZ2 == null) {
            r3.LIZ(-1, "params null");
            return;
        }
        try {
            SearchApiNew.RealApi realApi = SSH.LIZ;
            String optString = optJSONObject.optString("search_id");
            String str3 = "";
            if (optString == null) {
                optString = str3;
            }
            String optString2 = optJSONObject.optString("query");
            if (optString2 == null) {
                optString2 = str3;
            }
            String optString3 = optJSONObject.optString("backtrace");
            if (optString3 == null) {
                optString3 = str3;
            }
            String optString4 = optJSONObject.optString("log_id");
            if (optString4 == null) {
                optString4 = str3;
            }
            String optString5 = optJSONObject.optString("token_type");
            if (optString5 == null) {
                optString5 = str3;
            }
            long optLong = optJSONObject.optLong("cursor", 0);
            C3839Sfj sfj = this.LIZJ;
            if (sfj == null || (str = sfj.LJIIL) == null || str.length() == 0) {
                PgV.LIZ(realApi.horizontalLoadmore(optString, optString2, optString3, optString4, optString5, optLong)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).a_(new SSD(this, r3));
                return;
            }
            C3839Sfj sfj2 = this.LIZJ;
            if (!(sfj2 == null || (str2 = sfj2.LJIIL) == null)) {
                str3 = str2;
            }
            r3.LIZ(str3);
        } catch (Exception e) {
            7hA.LIZ.LIZ(e, "LoadMoreSearchVideoList");
            r3.LIZ(-1, e.getMessage());
        }
    }
}
