package com.ss.android.ugc.aweme.discover.ui.suggest;

import X.0CB;
import X.0CH;
import X.0EB;
import X.0EC;
import X.1hK;
import X.7he;
import X.ARA;
import X.C3449SYr;
import X.C3527Sah;
import X.C4459Spj;
import X.Cbz;
import X.Crj;
import X.DZp;
import X.DaP;
import X.M12;
import X.Qeg;
import X.Qen;
import X.QuZ;
import X.Qua;
import X.Qub;
import X.Quc;
import X.QxI;
import X.QxL;
import X.QxM;
import X.SV0;
import X.SV5;
import X.SXD;
import X.SZO;
import android.content.Context;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.jedi.ext.adapter.JediSimpleViewHolder;
import com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem;
import com.ss.android.ugc.aweme.discover.model.suggest.Word;
import com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class DiscoverySuggestSearchViewHolder extends JediSimpleViewHolder<DiscoverSectionItem> implements QxL, QxL {
    public final ArrayList<DaP> LJFF = new ArrayList<>();
    public SearchEnterViewModel LJI;
    public DZp LJIIIZ;
    public Qeg LJIIJ;
    public final Crj LJIIJJI;
    public final Crj LJIIL;

    static {
        Covode.recordClassIndex(65982);
    }

    private final QuZ LJIIL() {
        return (QuZ) this.LJIIL.getValue();
    }

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

    private void LIZ(0EC r2) {
        M12.LIZ(r2);
        while (this.LJIIIZ.getItemDecorationCount() > 0) {
            this.LJIIIZ.LIZLLL();
        }
        this.LJIIIZ.LIZ(r2);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0049, code lost:
        if (r0 == null) goto L_0x004b;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final /* synthetic */ void LIZ(java.lang.Object r9) {
        /*
            r8 = this;
            com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem r9 = (com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem) r9
            X.M12.LIZ(r9)
            boolean r0 = r9 instanceof com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem.SuggestSearchSection
            if (r0 == 0) goto L_0x0127
            X.MO4 r0 = X.MO4.LIZIZ
            boolean r0 = r0.LIZ()
            r4 = 0
            r3 = 1
            if (r0 == 0) goto L_0x0127
            boolean r0 = X.MO4.LIZ
            if (r0 == 0) goto L_0x0127
            com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem$SuggestSearchSection r9 = (com.ss.android.ugc.aweme.discover.model.DiscoverSectionItem.SuggestSearchSection) r9
            com.ss.android.ugc.aweme.discover.model.suggest.SuggestWordResponse r0 = r9.suggestSearch
            java.util.List r0 = r0.data
            if (r0 == 0) goto L_0x0127
            java.util.Iterator r7 = r0.iterator()
        L_0x0023:
            boolean r0 = r7.hasNext()
            if (r0 == 0) goto L_0x0127
            java.lang.Object r5 = r7.next()
            com.ss.android.ugc.aweme.discover.model.suggest.TypeWords r5 = (com.ss.android.ugc.aweme.discover.model.suggest.TypeWords) r5
            com.ss.android.ugc.aweme.discover.model.suggest.SuggestWordResponse r0 = r9.suggestSearch
            java.lang.String r0 = r0.logId
            r5.logId = r0
            X.M12.LIZ(r5)
            java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word> r0 = r5.words
            if (r0 == 0) goto L_0x0055
            java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word> r0 = r5.words
            r6 = 0
            if (r0 == 0) goto L_0x0124
            int r0 = r0.size()
            java.lang.Integer r0 = java.lang.Integer.valueOf(r0)
            if (r0 != 0) goto L_0x004e
        L_0x004b:
            kotlin.h.b.n.LIZIZ()
        L_0x004e:
            int r1 = r0.intValue()
            r0 = 5
            if (r1 >= r0) goto L_0x005d
        L_0x0055:
            X.DZp r1 = r8.LJIIIZ
            r0 = 8
            X.Cbz.LIZ(r1, r0)
            goto L_0x0023
        L_0x005d:
            X.DZp r0 = r8.LJIIIZ
            X.Cbz.LIZ(r0, r4)
            java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word> r0 = r5.words
            if (r0 == 0) goto L_0x00af
            java.util.ArrayList r6 = new java.util.ArrayList
            r6.<init>()
            java.util.Iterator r2 = r0.iterator()
        L_0x006f:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x008b
            java.lang.Object r1 = r2.next()
            r0 = r1
            com.ss.android.ugc.aweme.discover.model.suggest.Word r0 = (com.ss.android.ugc.aweme.discover.model.suggest.Word) r0
            java.lang.String r0 = r0.getWord()
            boolean r0 = android.text.TextUtils.isEmpty(r0)
            r0 = r0 ^ r3
            if (r0 == 0) goto L_0x006f
            r6.add(r1)
            goto L_0x006f
        L_0x008b:
            java.util.List r6 = (java.util.List) r6
            X.Qx2 r1 = new X.Qx2
            r0 = 4
            r1.<init>(r3, r0)
            java.util.List r6 = X.Lea.LIZ(r6, r1)
            if (r6 == 0) goto L_0x00af
            java.util.Iterator r2 = r6.iterator()
        L_0x009d:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x00af
            java.lang.Object r1 = r2.next()
            com.ss.android.ugc.aweme.discover.model.suggest.Word r1 = (com.ss.android.ugc.aweme.discover.model.suggest.Word) r1
            java.lang.String r0 = r5.logId
            r1.setImplId(r0)
            goto L_0x009d
        L_0x00af:
            X.9Y3 r1 = X.9Y3.LIZ()
            java.lang.String r0 = "discover_suggested_words_style"
            int r0 = X.9Y3.LIZ(r1, r3, r0, r4)
            switch(r0) {
                case 1: goto L_0x0120;
                case 2: goto L_0x011c;
                case 3: goto L_0x0118;
                case 4: goto L_0x0114;
                case 5: goto L_0x0110;
                case 6: goto L_0x010c;
                default: goto L_0x00bc;
            }
        L_0x00bc:
            if (r6 == 0) goto L_0x0023
            android.view.View r0 = r8.itemView
            java.lang.String r5 = ""
            kotlin.h.b.n.LIZIZ(r0, r5)
            android.content.Context r1 = r0.getContext()
            X.Sag r2 = new X.Sag
            r2.<init>()
            int r0 = r6.size()
            java.lang.Integer r0 = java.lang.Integer.valueOf(r0)
            r2.LIZJ(r0)
            java.lang.String r0 = "recom_search"
            r2.LJJI(r0)
            r2.LJJII(r5)
            r0 = -1
            java.lang.Integer r0 = java.lang.Integer.valueOf(r0)
            r2.LIZ((java.lang.Integer) r0)
            java.lang.String r0 = "discovery"
            r2.LJJIII(r0)
            boolean r0 = r1 instanceof X.1hK
            if (r0 == 0) goto L_0x0107
            X.SAJ r0 = com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel.LIZJ
            X.1hK r1 = (X.1hK) r1
            com.ss.android.ugc.aweme.discover.viewmodel.SearchEnterViewModel r0 = r0.LIZ(r1)
            X.SV5 r1 = r0.LIZIZ()
            java.lang.String r0 = "tab_name"
            java.lang.Object r0 = r1.obtainLogData(r0)
            r2.LIZ(r0)
        L_0x0107:
            r2.LJFF()
            goto L_0x0023
        L_0x010c:
            r8.LIZIZ((java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word>) r6, (boolean) r3)
            goto L_0x00bc
        L_0x0110:
            r8.LIZIZ((java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word>) r6, (boolean) r4)
            goto L_0x00bc
        L_0x0114:
            r8.LIZJ(r6, r3)
            goto L_0x00bc
        L_0x0118:
            r8.LIZJ(r6, r4)
            goto L_0x00bc
        L_0x011c:
            r8.LIZ((java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word>) r6, (boolean) r3)
            goto L_0x00bc
        L_0x0120:
            r8.LIZ((java.util.List<com.ss.android.ugc.aweme.discover.model.suggest.Word>) r6, (boolean) r4)
            goto L_0x00bc
        L_0x0124:
            r0 = r6
            goto L_0x004b
        L_0x0127:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.discover.ui.suggest.DiscoverySuggestSearchViewHolder.LIZ(java.lang.Object):void");
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public DiscoverySuggestSearchViewHolder(View view, 1hK r6) {
        super(view);
        M12.LIZ(view);
        DZp findViewById = view.findViewById(2131370840);
        n.LIZIZ(findViewById, "");
        this.LJIIIZ = findViewById;
        Qeg findViewById2 = view.findViewById(2131364114);
        n.LIZIZ(findViewById2, "");
        this.LJIIJ = findViewById2;
        this.LJIIIZ.setItemAnimator((0EB) null);
        this.LJIIIZ.LIZ(new Class[]{DiscoverySuggestSearchSingleLineCell.class, DiscoverySuggestSearchBreakLineCell.class});
        this.LJI = SearchEnterViewModel.LIZJ.LIZ(r6);
        this.LJIIJJI = 7he.LIZ(Quc.LIZ);
        this.LJIIL = 7he.LIZ(Qua.LIZ);
    }

    private void LIZ(List<Word> list, boolean z) {
        int i;
        Qeg qeg = this.LJIIJ;
        if (z) {
            i = 0;
        } else {
            i = 8;
        }
        Cbz.LIZ(qeg, i);
        LIZ((0EC) LJIIL());
        Qen.LIZIZ(this.LJIIIZ, 0, (Integer) null, (Integer) null, Integer.valueOf((int) ARA.LIZ(8)), false, 16);
        View view = this.itemView;
        n.LIZIZ(view, "");
        view.getContext();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
        linearLayoutManager.LIZIZ(0);
        this.LJIIIZ.setLayoutManager(linearLayoutManager);
        this.LJIIIZ.getState().LIZ();
        if (list != null) {
            for (Word qxM : list) {
                this.LJIIIZ.getState().LIZ(new QxM(qxM, 0, this));
            }
        }
    }

    private void LIZIZ(List<Word> list, boolean z) {
        int i;
        int LIZ;
        Qeg qeg = this.LJIIJ;
        if (z) {
            i = 0;
        } else {
            i = 8;
        }
        Cbz.LIZ(qeg, i);
        LIZ((0EC) LJIIL());
        DZp dZp = this.LJIIIZ;
        if (z) {
            LIZ = 0;
        } else {
            LIZ = (int) ARA.LIZ(4);
        }
        Qen.LIZIZ(dZp, 0, Integer.valueOf(LIZ), (Integer) null, Integer.valueOf((int) ARA.LIZ(12)), false, 16);
        View view = this.itemView;
        n.LIZIZ(view, "");
        view.getContext();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager();
        linearLayoutManager.LIZIZ(0);
        this.LJIIIZ.setLayoutManager(linearLayoutManager);
        this.LJIIIZ.getState().LIZ();
        if (list != null) {
            for (Word qxI : list) {
                this.LJIIIZ.getState().LIZ(new QxI(qxI, this));
            }
        }
    }

    private void LIZJ(List<Word> list, boolean z) {
        int i;
        Qeg qeg = this.LJIIJ;
        if (z) {
            i = 0;
        } else {
            i = 8;
        }
        Cbz.LIZ(qeg, i);
        LIZ((0EC) (Qub) this.LJIIJJI.getValue());
        Qen.LIZIZ(this.LJIIIZ, Integer.valueOf((int) ARA.LIZ(16)), 0, Integer.valueOf((int) ARA.LIZ(16)), Integer.valueOf((int) ARA.LIZ(8)), false, 16);
        View view = this.itemView;
        n.LIZIZ(view, "");
        view.getContext();
        this.LJIIIZ.setLayoutManager(new GridLayoutManager(2));
        this.LJIIIZ.getState().LIZ();
        if (list != null) {
            for (Word qxM : list) {
                this.LJIIIZ.getState().LIZ(new QxM(qxM, 1, this));
            }
        }
    }

    public final void LIZ(int i, Word word) {
        SV5 sv5;
        if (word != null) {
            SV0 sv0 = new SV0();
            sv0.setSearchFrom("recom_search");
            sv0.setKeyword(word.getWord());
            sv0.setWordType(word.getWordType());
            SearchEnterViewModel searchEnterViewModel = this.LJI;
            if (searchEnterViewModel != null) {
                sv5 = searchEnterViewModel.LIZ;
            } else {
                sv5 = null;
            }
            if (sv5 != null) {
                sv5.setFromDiscoverSuggestSearch(true);
            }
            C4459Spj spj = C4459Spj.LIZ;
            View view = this.itemView;
            n.LIZIZ(view, "");
            Context context = view.getContext();
            n.LIZIZ(sv0, "");
            spj.LIZ(new C3449SYr(context, sv0, sv5, (SXD) null, 120));
            M12.LIZ(word);
            SZO szo = new SZO();
            szo.LJJI("recom_search");
            szo.LIZLLL(Integer.valueOf(i));
            szo.LJJII("");
            szo.LJJIFFI(word.getWord());
            szo.LIZ((Integer) -1);
            szo.LJJIII("discovery");
            szo.LJIIIIZZ(word.getId());
            szo.LIZLLL(word.getImplId());
            szo.LJFF();
        }
    }

    public final void LIZIZ(int i, Word word) {
        if (word != null) {
            M12.LIZ(word);
            C3527Sah sah = new C3527Sah();
            sah.LJJI("recom_search");
            sah.LIZLLL(Integer.valueOf(i));
            sah.LJJII("");
            sah.LJJIFFI(word.getWord());
            sah.LIZ((Integer) -1);
            sah.LJJIII("discovery");
            sah.LJIIIIZZ(word.getId());
            sah.LIZLLL(word.getImplId());
            sah.LJFF();
        }
    }
}
