package com.ss.android.ugc.aweme.profile.editprofile.pronouns.viewmodel;

import X.AnonymousClass3ZC;
import X.AnonymousClass4HR;
import X.BGS;
import X.C01442Jq;
import X.C213033y;
import X.C22983Ak;
import X.C51834Nj;
import X.C51844Nk;
import X.C51904Nq;
import X.C52064Og;
import X.Lel;
import X.QNf;
import android.animation.ValueAnimator;
import android.content.Context;
import android.text.Editable;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.bytedance.assem.arch.viewModel.AssemViewModel;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import kotlin.h.b.n;

public final class ProfileEditPronounsSearchAndDisplayViewModel extends AssemViewModel<C51844Nk> {
    public static final C51904Nq LJIIIIZZ = new C51904Nq((byte) 0);
    public final SpannableStringBuilder LIZ = new SpannableStringBuilder();
    public final List<String> LIZIZ = new ArrayList();
    public final Map<C01442Jq, List<String>> LIZJ = new LinkedHashMap();
    public List<String> LIZLLL = Lel.INSTANCE;
    public int LJ = 4;
    public Boolean LJFF;
    public int LJI = Integer.MAX_VALUE;
    public final Map<Integer, Integer> LJII = new LinkedHashMap();
    public boolean LJIIIZ = true;
    public int LJIIJ;

    static {
        Covode.recordClassIndex(98534);
    }

    public final /* synthetic */ AnonymousClass4HR defaultState() {
        return new C51844Nk();
    }

    public final void onCleared() {
        this.LIZJ.clear();
        ProfileEditPronounsSearchAndDisplayViewModel.super.onCleared();
    }

    private final C213033y LIZ() {
        int i = this.LJIIJ;
        this.LJIIJ = i + 1;
        this.LJII.put(Integer.valueOf(i), Integer.valueOf(this.LIZ.length() - 1));
        return new C51834Nj(this, i);
    }

    private final C22983Ak LIZIZ(Context context, String str) {
        C22983Ak r1 = new C22983Ak(context, (byte) 0);
        r1.LIZ(str);
        return r1;
    }

    private final BGS<C22983Ak> LIZ(Context context, String str) {
        BGS<C22983Ak> bgs = new BGS<>(LIZIZ(context, str));
        bgs.LIZIZ = (int) C52064Og.LIZ(8.0f);
        return bgs;
    }

    private final void LIZIZ(EditText editText, int i) {
        Editable text = editText.getText();
        int selectionEnd = Selection.getSelectionEnd(text);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
        SpannableStringBuilder append = spannableStringBuilder.append(this.LIZ);
        n.LIZIZ(text, "");
        append.append(text.subSequence(this.LIZ.length(), i).toString());
        editText.setText(spannableStringBuilder);
        Editable text2 = editText.getText();
        if (selectionEnd > text2.length()) {
            selectionEnd = text2.length();
        }
        Selection.setSelection(text2, selectionEnd);
    }

    private final void LIZ(View view, int i) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.widget.LinearLayout.LayoutParams");
        LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) layoutParams;
        int i2 = layoutParams2.topMargin;
        ValueAnimator ofInt = ValueAnimator.ofInt(new int[]{0, i});
        n.LIZIZ(ofInt, "");
        ofInt.setDuration(100);
        ofInt.addUpdateListener(new AnonymousClass3ZC(layoutParams2, i2, view));
        ofInt.start();
    }

    public final void LIZ(Context context, List<String> list) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            this.LIZ.append("*");
            this.LIZIZ.add(list.get(i));
            BGS<C22983Ak> LIZ2 = LIZ(context, list.get(i));
            C213033y LIZ3 = LIZ();
            int length = this.LIZ.length() - 1;
            int length2 = this.LIZ.length();
            this.LIZ.setSpan(LIZ2, length, length2, 33);
            this.LIZ.setSpan(LIZ3, length, length2, 33);
        }
        this.LIZ.setSpan(new QNf(71), 0, this.LIZ.length(), 33);
    }

    public final void LIZ(boolean z, View view) {
        if (!n.LIZ(this.LJFF, true)) {
            if (z) {
                if (!this.LJIIIZ) {
                    this.LJIIIZ = true;
                    LIZ(view, view.getHeight());
                }
            } else if (this.LJIIIZ) {
                this.LJIIIZ = false;
                LIZ(view, -view.getHeight());
            }
        }
    }

    public final boolean LIZ(EditText editText, int i) {
        if (editText.getText().length() <= i) {
            return false;
        }
        LIZIZ(editText, i);
        return true;
    }
}
