package com.ss.android.ugc.aweme.feed.assem.corss.language;

import X.1hK;
import X.2Pr;
import X.2UX;
import X.2nK;
import X.2zq;
import X.33t;
import X.3Jg;
import X.3Jo;
import X.3YB;
import X.4HR;
import X.4hw;
import X.4hx;
import X.4o1;
import X.4wQ;
import X.7W7;
import X.7df;
import X.7dj;
import X.7he;
import X.9Y3;
import X.C6529Opg;
import X.C6538Opp;
import X.C6549Oq0;
import X.C6551Oq2;
import X.C6569OqK;
import X.C6577OqS;
import X.C6584OqZ;
import X.C6587Oqc;
import X.C6596Oql;
import X.C6597Oqm;
import X.C6598Oqn;
import X.CqM;
import X.Crj;
import X.Ls2;
import X.M12;
import android.os.SystemClock;
import com.bytedance.covode.number.Covode;
import com.bytedance.tux.sheet.sheet.TuxSheet;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.feed.assem.base.FeedBaseViewModel;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.CaptionItemModel;
import com.ss.android.ugc.aweme.feed.model.CaptionLanguage;
import com.ss.android.ugc.aweme.feed.model.CaptionModel;
import com.ss.android.ugc.aweme.feed.model.Video;
import com.ss.android.ugc.aweme.feed.model.VideoItemParams;
import com.ss.android.ugc.aweme.setting.services.ITranslatedCaptionService;
import com.ss.android.ugc.trill.setting.TranslatedCaptionCacheServiceImpl;
import java.util.Iterator;
import java.util.List;
import kotlin.h.b.n;

public final class VideoCLACaptionViewModel extends FeedBaseViewModel<C6587Oqc> {
    public long LIZIZ = -1;
    public boolean LIZJ = (!4o1.LIZ.LIZ());
    public boolean LIZLLL;
    public boolean LJ;
    public boolean LJFF;
    public boolean LJIILIIL;
    public String LJIILJJIL = "";
    public boolean LJIILL;
    public long LJIILLIIL = -1;
    public boolean LJIIZILJ;
    public boolean LJIJ;
    public boolean LJIJI;
    public String LJIJJ = "<";
    public final Crj LJIJJLI = 7he.LIZ(new C6584OqZ(this));

    static {
        Covode.recordClassIndex(77106);
    }

    public final C6551Oq2 LIZIZ() {
        return (C6551Oq2) this.LJIJJLI.getValue();
    }

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

    public final void LIZJ() {
        setState(new C6569OqK(this));
    }

    public final boolean LJII() {
        if (!this.LJIIZILJ || !this.LJIJI || this.LIZJ) {
            return false;
        }
        return true;
    }

    public final boolean LJIIJ() {
        if (!4hx.LIZ() || this.LIZJ) {
            return false;
        }
        return true;
    }

    public final boolean LJ() {
        Aweme aweme;
        4o1 r1 = 4o1.LIZ;
        VideoItemParams videoItemParams = (VideoItemParams) LIZ();
        if (videoItemParams != null) {
            aweme = videoItemParams.mAweme;
        } else {
            aweme = null;
        }
        return r1.LJFF(aweme);
    }

    public final boolean LJI() {
        Aweme aweme;
        VideoItemParams videoItemParams = (VideoItemParams) LIZ();
        if (videoItemParams == null || (aweme = videoItemParams.mAweme) == null || !3Jg.LIZ(aweme)) {
            return false;
        }
        return true;
    }

    public final String LJIIIZ() {
        Aweme aweme;
        VideoItemParams videoItemParams = (VideoItemParams) LIZ();
        if (videoItemParams == null || (aweme = videoItemParams.mAweme) == null) {
            return null;
        }
        return aweme.getAid();
    }

    public final void LJFF() {
        Aweme aweme;
        if (LIZLLL()) {
            VideoItemParams videoItemParams = (VideoItemParams) LIZ();
            if (videoItemParams == null || (aweme = videoItemParams.mAweme) == null || !3Jg.LIZ(aweme) || 4hw.LIZ()) {
                this.LIZLLL = TranslatedCaptionCacheServiceImpl.LJJIJ().LIZIZ();
            } else {
                this.LIZLLL = !TranslatedCaptionCacheServiceImpl.LJJIJ().LJIIL();
            }
        }
        this.LJIIZILJ = TranslatedCaptionCacheServiceImpl.LJJIJ().LJ();
    }

    public final boolean LIZLLL() {
        Aweme aweme;
        Aweme aweme2;
        VideoItemParams videoItemParams = (VideoItemParams) LIZ();
        if (videoItemParams == null || (aweme2 = videoItemParams.mAweme) == null || !3Jg.LIZ(aweme2) || 4hw.LIZ()) {
            4o1 r1 = 4o1.LIZ;
            VideoItemParams videoItemParams2 = (VideoItemParams) LIZ();
            if (videoItemParams2 != null) {
                aweme = videoItemParams2.mAweme;
            } else {
                aweme = null;
            }
            return r1.LIZ(aweme);
        } else if ((!4hx.LIZ() || this.LIZJ) && !TranslatedCaptionCacheServiceImpl.LJJIJ().LJIIL()) {
            return false;
        } else {
            return true;
        }
    }

    public final int LJIIIIZZ() {
        Aweme aweme;
        Video video;
        CaptionModel captionModel;
        List captionList;
        Long l;
        Aweme aweme2;
        Video video2;
        CaptionModel captionModel2;
        CaptionLanguage originalCaptionLanguage;
        if (!this.LIZJ) {
            return 0;
        }
        VideoItemParams videoItemParams = (VideoItemParams) LIZ();
        if (videoItemParams == null || (aweme = videoItemParams.mAweme) == null || (video = aweme.getVideo()) == null || (captionModel = video.getCaptionModel()) == null || (captionList = captionModel.getCaptionList()) == null || captionList.isEmpty()) {
            return 8;
        }
        VideoItemParams videoItemParams2 = (VideoItemParams) LIZ();
        if (videoItemParams2 == null || (aweme2 = videoItemParams2.mAweme) == null || (video2 = aweme2.getVideo()) == null || (captionModel2 = video2.getCaptionModel()) == null || (originalCaptionLanguage = captionModel2.getOriginalCaptionLanguage()) == null) {
            l = null;
        } else {
            l = Long.valueOf(originalCaptionLanguage.getLanguageId());
        }
        Iterator it = captionList.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            CaptionItemModel captionItemModel = (CaptionItemModel) it.next();
            long languageId = captionItemModel.getLanguageId();
            if (l != null && languageId == l.longValue()) {
                if (captionItemModel.isAutoGenerated()) {
                    return 0;
                }
            }
        }
        return 8;
    }

    public final C6538Opp LJIIJJI() {
        if (!LIZLLL()) {
            return C6538Opp.HIDDEN;
        }
        if (LJIIJ()) {
            return C6538Opp.EXPANDED;
        }
        if (4hw.LIZ()) {
            if (!TranslatedCaptionCacheServiceImpl.LJJIJ().LJIIL()) {
                return C6538Opp.HIDDEN;
            }
            if (this.LIZLLL || TranslatedCaptionCacheServiceImpl.LJJIJ().LIZLLL(LJIIIZ())) {
                return C6538Opp.COLLAPSED;
            }
            return C6538Opp.EXPANDED;
        } else if (!3Jo.LIZ() || 4hw.LIZ()) {
            return C6538Opp.EXPANDED;
        } else {
            if (this.LIZLLL || TranslatedCaptionCacheServiceImpl.LJJIJ().LIZLLL(LJIIIZ())) {
                return C6538Opp.HIDDEN;
            }
            return C6538Opp.EXPANDED;
        }
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        this.LJIJJ = str;
        LIZJ();
    }

    public final void LIZ(C6529Opg opg) {
        M12.LIZ(opg);
        LIZIZ().LIZIZ(this.LIZJ, LJII(), opg);
    }

    public final void LIZIZ(C6529Opg opg) {
        M12.LIZ(opg);
        LIZIZ().LIZ(this.LIZJ, LJII(), opg);
    }

    public final void LIZ(boolean z) {
        this.LIZLLL = z;
        TranslatedCaptionCacheServiceImpl.LJJIJ().LIZ(this.LIZLLL);
        CqM.LIZ(new C6549Oq0(!this.LIZLLL));
    }

    public final void LIZ(1hK r5) {
        if (LJII()) {
            LIZIZ().LIZJ(this.LIZJ, LJII());
        } else {
            LIZIZ().LIZIZ(this.LIZJ, LJII());
        }
        C6598Oqn.LIZ.LIZIZ();
        2zq r3 = new 2zq(r5, (byte) 0);
        3YB r0 = new 3YB();
        r0.LIZ(r3);
        TuxSheet tuxSheet = r0.LIZ;
        r3.getBtnDismiss().setOnClickListener(new C6596Oql(tuxSheet));
        r3.getIvClose().setOnClickListener(new C6597Oqm(tuxSheet));
        C6577OqS oqS = new C6577OqS(this, r5, tuxSheet);
        r3.getTvGoSetting().setOnClickListener(oqS);
        r3.LIZ(oqS, LJII());
        tuxSheet.show(r5.getSupportFragmentManager(), "feed_caption_intro");
    }

    public final void LIZIZ(boolean z) {
        String str;
        Aweme aweme;
        if (this.LJIILLIIL != -1 && z) {
            long elapsedRealtime = SystemClock.elapsedRealtime() - this.LJIILLIIL;
            2UX r4 = new 2UX();
            VideoItemParams videoItemParams = (VideoItemParams) LIZ();
            if (videoItemParams == null || (str = videoItemParams.mEventType) == null) {
                str = "";
            }
            r4.LIZ("enter_from", str);
            VideoItemParams videoItemParams2 = (VideoItemParams) LIZ();
            Aweme aweme2 = null;
            if (videoItemParams2 != null) {
                aweme = videoItemParams2.mAweme;
            } else {
                aweme = null;
            }
            r4.LIZ("group_id", 4wQ.LJ(aweme));
            VideoItemParams videoItemParams3 = (VideoItemParams) LIZ();
            if (videoItemParams3 != null) {
                aweme2 = videoItemParams3.mAweme;
            }
            r4.LIZ("author_id", 4wQ.LIZ(aweme2));
            r4.LIZ("duration", elapsedRealtime);
            r4.LIZ("enable_experiment", 9Y3.LIZ(9Y3.LIZ(), true, "player_enable_opt_subload_time", 1));
            2nK.LIZ("cla_caption_switch_language_time", r4.LIZ);
        }
    }

    public final void LIZ(boolean z, Ls2<2Pr> ls2) {
        int i;
        int i2;
        Aweme aweme;
        String aid;
        DataCenter dataCenter;
        Aweme aweme2;
        Aweme aweme3;
        M12.LIZ(ls2);
        if (z != this.LIZJ) {
            this.LJIILLIIL = SystemClock.elapsedRealtime();
            this.LJIILIIL = true;
            VideoItemParams videoItemParams = (VideoItemParams) LIZ();
            if (videoItemParams == null || (aweme3 = videoItemParams.mAweme) == null) {
                i = 0;
            } else {
                i = 33t.LIZIZ(aweme3);
            }
            VideoItemParams videoItemParams2 = (VideoItemParams) LIZ();
            if (videoItemParams2 == null || (aweme2 = videoItemParams2.mAweme) == null) {
                i2 = 0;
            } else {
                i2 = 33t.LIZ(aweme2);
            }
            7W7 LJJJI = 7df.LJJJI();
            String str = "";
            n.LIZIZ(LJJJI, str);
            7dj LJJIJL = LJJJI.LJJIJL();
            if (!this.LIZJ) {
                i = i2;
            }
            LJJIJL.LIZ(i);
            VideoItemParams videoItemParams3 = (VideoItemParams) LIZ();
            if (!(videoItemParams3 == null || (dataCenter = videoItemParams3.dataCenter) == null)) {
                dataCenter.LIZ("use_translated_caption", Boolean.valueOf(this.LIZJ));
            }
            if (!this.LIZJ) {
                ITranslatedCaptionService LJJIJ = TranslatedCaptionCacheServiceImpl.LJJIJ();
                VideoItemParams videoItemParams4 = (VideoItemParams) LIZ();
                if (!(videoItemParams4 == null || (aweme = videoItemParams4.mAweme) == null || (aid = aweme.getAid()) == null)) {
                    str = aid;
                }
                LJJIJ.LIZ(str);
            }
            this.LIZJ = true ^ this.LIZJ;
            LIZIZ().LIZLLL(this.LIZJ, LJII());
            this.LJFF = false;
            ls2.invoke();
        }
    }
}
