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

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CB;
import X.0CH;
import X.0HH;
import X.1hK;
import X.2GD;
import X.2kf;
import X.4UQ;
import X.6Is;
import X.7hA;
import X.C3292SSq;
import X.C3297SSv;
import X.C3310STi;
import X.C3320STs;
import X.C3829SfZ;
import X.CqM;
import X.KCT;
import X.KT7;
import X.LaM;
import X.M12;
import X.SV0;
import X.SWS;
import X.SX8;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.bullet.bridge.BaseBridgeMethod;
import com.ss.android.ugc.aweme.discover.model.SearchIntermediateViewModel;
import com.ss.android.ugc.aweme.search.activity.SearchResultActivity;
import kotlin.h.b.n;
import org.json.JSONArray;
import org.json.JSONObject;

public final class SearchKeywordChangeMethod extends BaseBridgeMethod implements 6Is {
    public static final C3297SSv LIZJ = new C3297SSv((byte) 0);
    public KCT LIZIZ;
    public final String LIZLLL = LaM.LIZ;

    static {
        Covode.recordClassIndex(65947);
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        SearchKeywordChangeMethod.super.onStateChanged(r1, r2);
    }

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

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

    public static 0Bx LIZ(1hK r2) {
        0Bx LIZ = 0By.LIZ(r2, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ, r2);
        }
        return LIZ;
    }

    private boolean LIZIZ(String str) {
        M12.LIZ(str);
        int hashCode = str.hashCode();
        if (hashCode != -1816950631) {
            if (hashCode != 1081985277) {
                if (hashCode == 1661687189 && str.equals("trending_topic")) {
                    return true;
                }
                return false;
            } else if (str.equals("search_history")) {
                return true;
            } else {
                return false;
            }
        } else if (str.equals("recom_search")) {
            return true;
        } else {
            return false;
        }
    }

    public final void LIZ(JSONObject jSONObject, KCT kct) {
        M12.LIZ(jSONObject, kct);
        SearchKeywordChangeMethod.super.LIZ(jSONObject, kct);
        this.LIZIZ = kct;
    }

    public final void LIZ(JSONObject jSONObject, 4UQ r14) {
        int i;
        M12.LIZ(jSONObject, r14);
        try {
            String optString = jSONObject.optString("enterMethod");
            String optString2 = jSONObject.optString("keyword");
            String optString3 = jSONObject.optString("type");
            String optString4 = jSONObject.optString("words_type");
            String optString5 = jSONObject.optString("event_id");
            if (jSONObject.has("avoid_record_history")) {
                i = jSONObject.optInt("avoid_record_history");
            } else {
                i = 0;
            }
            int i2 = 1;
            if (i == 1) {
                i2 = 0;
            }
            1hK LJIIIZ = C3829SfZ.LJIJ.LJIIIZ();
            if (LJIIIZ != null) {
                if (LJIIIZ instanceof SearchResultActivity) {
                    SearchIntermediateViewModel LIZ = LIZ(LJIIIZ).LIZ(SearchIntermediateViewModel.class);
                    n.LIZIZ(LIZ, "");
                    SearchIntermediateViewModel searchIntermediateViewModel = LIZ;
                    Integer num = (Integer) searchIntermediateViewModel.getSearchTabIndex().getValue();
                    if (num == null) {
                        num = 0;
                    }
                    n.LIZIZ(num, "");
                    String LIZ2 = C3320STs.LIZ(num.intValue());
                    if (optString.equals("search_history")) {
                        SX8.LIZ(5);
                        SWS.LIZJ = false;
                    }
                    SV0 sv0 = new SV0();
                    sv0.setSearchFrom(optString);
                    sv0.setKeyword(optString2);
                    sv0.setEnterMethod(optString);
                    n.LIZIZ(optString3, "");
                    sv0.setIndex(C3320STs.LIZ(optString3));
                    sv0.setWordType(optString4);
                    sv0.setShouldRecordInHistory(i2);
                    n.LIZIZ(sv0, "");
                    searchIntermediateViewModel.reFetchTheSearchData(LJIIIZ, sv0);
                    n.LIZIZ(optString, "");
                    if (LIZIZ(optString)) {
                        Integer num2 = (Integer) searchIntermediateViewModel.getIntermediateState().getValue();
                        if (num2 != null) {
                            if (num2.intValue() != 0) {
                            }
                        }
                        searchIntermediateViewModel.getOpenSearchParam().setValue(sv0);
                        searchIntermediateViewModel.hideIntermediate();
                    } else if (TextUtils.equals("click_more_general_list", optString)) {
                        CqM.LIZ(new C3310STi(C3320STs.LIZ(optString3)));
                    } else if (TextUtils.equals(LIZ2, optString3) || TextUtils.isEmpty(optString3)) {
                        CqM.LIZ(new C3292SSq(sv0));
                    }
                } else if (LJIIIZ instanceof 1hK) {
                    SearchIntermediateViewModel LIZ3 = LIZ(LJIIIZ).LIZ(SearchIntermediateViewModel.class);
                    n.LIZIZ(LIZ3, "");
                    SearchIntermediateViewModel searchIntermediateViewModel2 = LIZ3;
                    SV0 sv02 = new SV0();
                    sv02.setSearchFrom(optString);
                    sv02.setKeyword(optString2);
                    sv02.setEnterMethod(optString);
                    n.LIZIZ(optString3, "");
                    sv02.setIndex(C3320STs.LIZ(optString3));
                    sv02.setWordType(optString4);
                    sv02.setTrendingEventId(optString5);
                    sv02.setShouldRecordInHistory(i2);
                    n.LIZIZ(sv02, "");
                    searchIntermediateViewModel2.openSearch(LJIIIZ, sv02);
                    Integer num3 = (Integer) searchIntermediateViewModel2.getIntermediateState().getValue();
                    if (num3 != null) {
                        if (num3.intValue() != 0) {
                        }
                    }
                    searchIntermediateViewModel2.hideIntermediate();
                }
            }
            n.LIZIZ(optString, "");
            if (LIZIZ(optString)) {
                2kf.LIZ(4, "Search_history_middle_page_jsb", "SearchKeywordChangeMethod, params = ".concat(String.valueOf(jSONObject)));
            }
            r14.LIZ(new JSONArray());
        } catch (Exception e) {
            7hA.LIZ.LIZ(e, "SearchKeywordChangeMethod");
            r14.LIZ(0, e.getMessage());
            0HH.LIZ(e);
        }
    }
}
