package M5;

import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import androidx.constraintlayout.widget.Group;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.domain.model.Movie;
import com.martsnew.domain.type.MediaType;
import com.martsnew.tv.R;
import com.martsnew.tv.customviews.TvButton;
import com.martsnew.tv.ui.movie_detail.TvMovieDetailFragment;
import u5.AbstractC1603C;
import y5.C1763h;

/* JADX INFO: loaded from: classes.dex */
public final class f extends G6.i implements O6.p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public /* synthetic */ Object f4303u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final /* synthetic */ TvMovieDetailFragment f4304v;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public f(E6.d dVar, TvMovieDetailFragment tvMovieDetailFragment) {
        super(2, dVar);
        this.f4304v = tvMovieDetailFragment;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) throws Throwable {
        f fVar = (f) m((E6.d) obj2, (C1763h) obj);
        A6.n nVar = A6.n.f457a;
        fVar.p(nVar);
        return nVar;
    }

    @Override // G6.a
    public final E6.d m(E6.d dVar, Object obj) {
        f fVar = new f(dVar, this.f4304v);
        fVar.f4303u = obj;
        return fVar;
    }

    @Override // G6.a
    public final Object p(Object obj) throws Throwable {
        SpannableString spannableString;
        C1.N(obj);
        Object objA = ((C1763h) this.f4303u).a();
        if (objA != null) {
            q qVar = (q) objA;
            boolean z8 = qVar instanceof n;
            int i = R.string.label_watch_now;
            TvMovieDetailFragment tvMovieDetailFragment = this.f4304v;
            if (z8) {
                tvMovieDetailFragment.u0();
                n nVar = (n) qVar;
                long j8 = nVar.f4317c;
                boolean z9 = j8 > 0;
                Group group = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17502Q;
                P6.g.d(group, "groupWatched");
                group.setVisibility(z9 ? 0 : 8);
                TvButton tvButton = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17497L;
                P6.g.d(tvButton, "buttonContinueWatch");
                tvButton.setVisibility(!z9 ? 4 : 0);
                TvButton tvButton2 = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17500O;
                P6.g.d(tvButton2, "buttonRemoveFromContinue");
                tvButton2.setVisibility(z9 ? 0 : 8);
                AbstractC1603C abstractC1603C = (AbstractC1603C) tvMovieDetailFragment.f0();
                if (z9) {
                    i = R.string.title_watch_from_beginning;
                }
                abstractC1603C.f17501P.setText(i);
                if (j8 > 0) {
                    Movie movie = tvMovieDetailFragment.s0().f4313a;
                    MediaType mediaType = MediaType.f11106s;
                    if (movie.f11076x == mediaType) {
                        int i5 = nVar.f4318d;
                        Integer num = new Integer(i5);
                        long j9 = nVar.f4319e;
                        spannableString = new SpannableString(tvMovieDetailFragment.u(R.string.format_tv_series_continue_watch, num, new Long(j9), s7.l.k(j8), s7.l.l(tvMovieDetailFragment.s0().f4313a.f11075w)));
                        ((AbstractC1603C) tvMovieDetailFragment.f0()).f17497L.setText(tvMovieDetailFragment.u(R.string.format_button_continue_watch, new Integer(i5), new Long(j9)));
                    } else {
                        spannableString = new SpannableString(tvMovieDetailFragment.u(R.string.format_movie_continue_watch, s7.l.k(j8), s7.l.l(tvMovieDetailFragment.s0().f4313a.f11075w)));
                        ((AbstractC1603C) tvMovieDetailFragment.f0()).f17497L.setText(tvMovieDetailFragment.t(R.string.title_resume));
                    }
                    ((AbstractC1603C) tvMovieDetailFragment.f0()).f17497L.requestFocus();
                    try {
                        spannableString.setSpan(new ForegroundColorSpan(tvMovieDetailFragment.Z().getColor(R.color.colorAccent)), tvMovieDetailFragment.s0().f4313a.f11076x == mediaType ? X6.e.T(spannableString, "]", 0, 6) + 1 : 0, X6.e.T(spannableString, "/", 0, 6), 34);
                    } catch (Exception unused) {
                    }
                    ((AbstractC1603C) tvMovieDetailFragment.f0()).f17520j0.setText(spannableString);
                }
            } else if (qVar.equals(o.f4320a)) {
                Group group2 = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17502Q;
                P6.g.d(group2, "groupWatched");
                group2.setVisibility(8);
                tvMovieDetailFragment.u0();
            } else if (qVar.equals(o.f4322c)) {
                Group group3 = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17502Q;
                P6.g.d(group3, "groupWatched");
                group3.setVisibility(8);
                TvButton tvButton3 = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17500O;
                P6.g.d(tvButton3, "buttonRemoveFromContinue");
                tvButton3.setVisibility(8);
                TvButton tvButton4 = ((AbstractC1603C) tvMovieDetailFragment.f0()).f17497L;
                P6.g.d(tvButton4, "buttonContinueWatch");
                tvButton4.setVisibility(4);
                ((AbstractC1603C) tvMovieDetailFragment.f0()).f17501P.setText(R.string.label_watch_now);
                ((AbstractC1603C) tvMovieDetailFragment.f0()).f17501P.requestFocus();
            } else if (qVar instanceof p) {
                if (((p) qVar).f4323a) {
                    ((AbstractC1603C) tvMovieDetailFragment.f0()).f17499N.setText(tvMovieDetailFragment.t(R.string.title_remove_from_my_list));
                } else {
                    ((AbstractC1603C) tvMovieDetailFragment.f0()).f17499N.setText(tvMovieDetailFragment.t(R.string.title_add_to_my_list));
                }
            } else if (!qVar.equals(o.f4321b)) {
                throw new A6.b();
            }
        }
        return A6.n.f457a;
    }
}
