package com.ss.android.ugc.aweme.im.sdk.share.ui.textbox;

import X.0Bt;
import X.1Bn;
import X.2ce;
import X.3VC;
import X.4PN;
import X.C0939Ia2;
import X.C2177Iu0;
import X.C2178Iu1;
import X.C2190IuD;
import X.C2191IuE;
import X.C2192IuF;
import X.C2197IuK;
import X.C2198IuL;
import X.C2201IuO;
import X.C2202IuP;
import X.C2203IuQ;
import X.C2204IuR;
import X.C2207IuU;
import X.C2214Iub;
import X.C2242Iv3;
import X.C3491Ja6;
import X.Lel;
import X.M12;
import androidx.lifecycle.LiveData;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.im.message.template.service.SendMessageTemplateTask;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.BaseContent;
import com.ss.android.ugc.aweme.im.sdk.common.controller.providedservices.SendMessageTemplateServiceImpl;
import com.ss.android.ugc.aweme.im.service.model.IMContact;
import com.ss.android.ugc.aweme.profile.model.User;
import com.ss.android.ugc.aweme.sharer.ui.SharePackage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import kotlin.h.b.n;

public final class ShareTextBoxViewModel extends 0Bt implements C2204IuR {
    public static final C2203IuQ LJIJ = new C2203IuQ((byte) 0);
    public C2207IuU LIZ;
    public final 1Bn<Integer> LIZIZ;
    public final LiveData<Integer> LIZJ;
    public final 1Bn<C2198IuL> LIZLLL;
    public final LiveData<C2198IuL> LJ;
    public final LiveData<C2197IuK> LJFF;
    public final 1Bn<Float> LJI;
    public final LiveData<Float> LJII;
    public final LiveData<Boolean> LJIIIIZZ;
    public final 1Bn<List<User>> LJIIIZ;
    public final LiveData<List<User>> LJIIJ;
    public final 2ce<Boolean> LJIIJJI;
    public final LiveData<Boolean> LJIIL;
    public List<? extends IMContact> LJIILIIL;
    public final SharePackage LJIILJJIL;
    public final C2202IuP LJIILL;
    public final C2201IuO LJIILLIIL = null;
    public final 1Bn<Boolean> LJIIZILJ;
    public final 1Bn<C2197IuK> LJIJI;
    public final 1Bn<Boolean> LJIJJ;
    public final C2204IuR LJIJJLI;

    static {
        Covode.recordClassIndex(87187);
    }

    public final List<IMContact> LIZ() {
        List<? extends IMContact> list = this.LJIILIIL;
        ArrayList arrayList = new ArrayList();
        for (T next : list) {
            if (!(next instanceof C3491Ja6)) {
                arrayList.add(next);
            }
        }
        return arrayList;
    }

    public final void LIZIZ() {
        C2207IuU iuU = this.LIZ;
        if (iuU != null && iuU.LIZIZ) {
            this.LJIJI.postValue(new C2197IuK(2131825523));
        } else if (this.LJIILIIL.size() <= 1) {
            this.LJIJI.postValue(new C2197IuK(2131825977));
        } else {
            this.LJIJI.postValue(new C2197IuK(2131832100, this.LJIILIIL.size()));
        }
    }

    public final void LIZIZ(boolean z) {
        C2204IuR iuR = this.LJIJJLI;
        if (iuR != null) {
            iuR.LIZIZ(z);
        }
    }

    public final void LIZ(boolean z) {
        LIZIZ();
        C2204IuR iuR = this.LJIJJLI;
        if (iuR != null) {
            iuR.LIZ(z);
        }
    }

    public final void LIZJ(boolean z) {
        C2204IuR iuR = this.LJIJJLI;
        if (iuR != null) {
            iuR.LIZIZ(z);
        }
        this.LJIJJ.setValue(Boolean.valueOf(z));
        if (!z) {
            C2207IuU iuU = this.LIZ;
            if (iuU != null) {
                iuU.LIZJ = false;
            }
            LIZIZ();
        }
    }

    private final void LIZ(SharePackage sharePackage, int i) {
        C2207IuU iuU = this.LIZ;
        if (iuU == null || !iuU.LIZIZ) {
            sharePackage.LJIILJJIL.putInt("is_create_group_chat", 0);
        } else {
            sharePackage.LJIILJJIL.putInt("is_create_group_chat", 1);
        }
        sharePackage.LJIILJJIL.putInt("friends_shared_cnt", i);
    }

    public final void LIZ(List<? extends IMContact> list, String str) {
        this.LJIIZILJ.setValue(true);
        SendMessageTemplateTask sendMessageTemplateTask = this.LJIILJJIL.LJIILL;
        if (sendMessageTemplateTask != null) {
            SendMessageTemplateServiceImpl.Companion.getINSTANCE().enqueueSendTask(list, sendMessageTemplateTask, str, new C2191IuE(this, list));
            C2178Iu1.LIZ.LIZ(this.LJIILJJIL, sendMessageTemplateTask, list);
        }
    }

    public final void LIZ(List<? extends IMContact> list, String str, BaseContent baseContent, boolean z) {
        List<? extends IMContact> list2 = list;
        M12.LIZ(list2);
        this.LJIIZILJ.setValue(true);
        String uuid = UUID.randomUUID().toString();
        n.LIZIZ(uuid, "");
        C2202IuP iuP = this.LJIILL;
        if (iuP != null) {
            iuP.LIZJ(this.LJIILJJIL);
        }
        C2242Iv3.LIZ(this.LJIILJJIL, list2);
        LIZ(this.LJIILJJIL, 4PN.LIZ(list2));
        String str2 = str;
        BaseContent baseContent2 = baseContent;
        C2177Iu0.LIZ((List<IMContact>) list2, str2, this.LJIILJJIL, baseContent2, uuid, !z, (C2190IuD) new C2192IuF(this, list2, uuid, str2));
        if (C0939Ia2.LIZ(this.LJIILJJIL)) {
            3VC.LIZ(list2.size());
        }
    }

    public ShareTextBoxViewModel(SharePackage sharePackage, C2202IuP iuP, C2204IuR iuR, 1Bn<Boolean> r6, C2214Iub iub, boolean z, boolean z2) {
        M12.LIZ(sharePackage, r6, iub);
        this.LJIILJJIL = sharePackage;
        this.LJIILL = iuP;
        this.LJIJJLI = iuR;
        this.LJIIZILJ = r6;
        1Bn<Integer> r0 = new 1Bn<>();
        this.LIZIZ = r0;
        this.LIZJ = r0;
        1Bn<C2198IuL> r02 = new 1Bn<>();
        this.LIZLLL = r02;
        this.LJ = r02;
        1Bn<C2197IuK> r03 = new 1Bn<>();
        this.LJIJI = r03;
        this.LJFF = r03;
        1Bn<Float> r04 = new 1Bn<>();
        this.LJI = r04;
        this.LJII = r04;
        1Bn<Boolean> r05 = new 1Bn<>();
        this.LJIJJ = r05;
        this.LJIIIIZZ = r05;
        1Bn<List<User>> r06 = new 1Bn<>();
        this.LJIIIZ = r06;
        this.LJIIJ = r06;
        2ce<Boolean> r07 = new 2ce<>();
        this.LJIIJJI = r07;
        this.LJIIL = r07;
        this.LJIILIIL = Lel.INSTANCE;
        if (z2) {
            C2207IuU iuU = new C2207IuU(iub, sharePackage, this, z);
            iuU.LIZJ();
            this.LIZ = iuU;
        }
    }
}
