package com.ss.android.ugc.aweme.viewmodel;

import X.2GM;
import X.2J6;
import X.2kf;
import X.2yN;
import X.4Bn;
import X.4HR;
import X.AQB;
import X.B6M;
import X.B6Q;
import X.C0946AMk;
import X.C0947AMl;
import X.C0949AMn;
import X.C0956AMu;
import X.C1804Ai8;
import X.PMi;
import X.PMp;
import android.view.View;
import com.bytedance.assem.arch.viewModel.AssemViewModel;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeStatistics;
import kotlin.h.b.n;

public final class PostModeFavoriteViewModel extends AssemViewModel<C0946AMk> {
    public static final /* synthetic */ PMp[] LIZ = {new PMi(PostModeFavoriteViewModel.class, "context", "getContext()Landroid/content/Context;", 0)};
    public Aweme LIZIZ;
    public final C1804Ai8 LIZJ = new C1804Ai8(C0956AMu.LIZ);
    public long LIZLLL = -1;
    public B6M LJ;

    public final /* synthetic */ 4HR defaultState() {
        return new C0946AMk();
    }

    static {
        Covode.recordClassIndex(123663);
    }

    public final void LIZ(boolean z) {
        setState(new C0949AMn(z));
    }

    public final void LIZ(Aweme aweme) {
        String str;
        if (aweme != null) {
            long j = this.LIZLLL;
            long j2 = 0;
            if (aweme.isCollected()) {
                if (j <= -1) {
                    j2 = 1;
                } else {
                    j2 = j + 1;
                }
            } else if (j > 0) {
                j2 = j - 1;
            }
            this.LIZLLL = j2;
            try {
                str = 2yN.LIZ(j2);
            } catch (Exception e) {
                2kf.LIZ(e);
                str = "0";
            }
            setState(new C0947AMl(str));
        }
    }

    public final String LIZIZ(Aweme aweme) {
        long j;
        if (aweme == null || 2J6.LIZ(aweme)) {
            return "0";
        }
        AwemeStatistics statistics = aweme.getStatistics();
        if (statistics != null) {
            j = statistics.getCollectCount();
        } else {
            j = -1;
        }
        if (aweme.isCollected() && j == -1) {
            j = 1;
        }
        this.LIZLLL = j;
        try {
            String LIZ2 = 2yN.LIZ(j);
            n.LIZIZ(LIZ2, "");
            return LIZ2;
        } catch (Exception e) {
            2kf.LIZ(e);
            return "0";
        }
    }

    public final void LIZ(View view, B6Q b6q) {
        int i;
        String str;
        int i2;
        if (this.LJ == null) {
            this.LJ = new B6M();
        }
        B6M b6m = this.LJ;
        if (b6m != null) {
            b6m.LIZLLL = "graphic_detail";
        }
        B6M b6m2 = this.LJ;
        if (b6m2 != null) {
            b6m2.a_(b6q);
        }
        B6M b6m3 = this.LJ;
        if (b6m3 != null) {
            b6m3.LJIIJJI = view;
        }
        Aweme aweme = this.LIZIZ;
        if (aweme == null || !aweme.isCollected()) {
            i = 1;
        } else {
            i = 0;
        }
        B6M b6m4 = this.LJ;
        if (b6m4 != null) {
            Object[] objArr = new Object[4];
            objArr[0] = 2;
            Aweme aweme2 = this.LIZIZ;
            if (aweme2 != null) {
                str = aweme2.getAid();
            } else {
                str = null;
            }
            objArr[1] = str;
            objArr[2] = Integer.valueOf(i);
            Aweme aweme3 = this.LIZIZ;
            if (aweme3 != null) {
                i2 = aweme3.getAwemeType();
            } else {
                i2 = 0;
            }
            objArr[3] = Integer.valueOf(i2);
            b6m4.LIZ(objArr);
        }
        Aweme aweme4 = this.LIZIZ;
        if (aweme4 != null) {
            LIZ(aweme4.isCollected());
            String aid = aweme4.getAid();
            n.LIZIZ(aid, "");
            AQB.LJI.LIZ((2GM) new 4Bn(aid, i, false));
        }
    }
}
