package com.strmr.ps.ui.mobile.actor;

import android.util.Log;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBPersonDetails;
import com.strmr.ps.data.model.tmdb.TMDBPersonMovieCredit;
import com.strmr.ps.data.model.tmdb.TMDBPersonMovieCredits;
import com.strmr.ps.data.model.tmdb.TMDBPersonTVCredit;
import com.strmr.ps.data.model.tmdb.TMDBPersonTVCredits;
import com.strmr.ps.ui.mobile.actor.MobileActorDetailsViewModel;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ig6;
import defpackage.ik2;
import defpackage.m02;
import defpackage.m12;
import defpackage.n89;
import defpackage.r06;
import defpackage.s06;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.y41;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.mobile.actor.MobileActorDetailsViewModel$loadActorDetails$1", f = "MobileActorDetailsViewModel.kt", i = {}, l = {55}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class g extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public int a;
    public final /* synthetic */ MobileActorDetailsViewModel b;
    public final /* synthetic */ int c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public g(MobileActorDetailsViewModel mobileActorDetailsViewModel, int i, Continuation continuation) {
        super(2, continuation);
        this.b = mobileActorDetailsViewModel;
        this.c = i;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new g(this.b, this.c, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((g) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        Object objF;
        MobileActorDetailsViewModel.a aVar;
        List listBj;
        List<TMDBPersonTVCredit> cast;
        List<TMDBPersonMovieCredit> cast2;
        MobileActorDetailsViewModel.a aVar2;
        Integer numBoxInt;
        MobileActorDetailsViewModel mobileActorDetailsViewModel = this.b;
        ig6 ig6Var = mobileActorDetailsViewModel.b;
        ck1 ck1Var = ck1.a;
        int i = this.a;
        try {
            if (i == 0) {
                s38.b(obj);
                ig6Var.setValue(MobileActorDetailsViewModel.b.a((MobileActorDetailsViewModel.b) ig6Var.getValue(), true, null));
                m12 m12Var = sc2.a;
                m02 m02Var = m02.c;
                f fVar = new f(mobileActorDetailsViewModel, this.c, null);
                this.a = 1;
                objF = wj0.f(m02Var, fVar, this);
                if (objF == ck1Var) {
                    return ck1Var;
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                objF = obj;
            }
            TMDBPersonDetails tMDBPersonDetails = (TMDBPersonDetails) objF;
            String name = tMDBPersonDetails.getName();
            String profileUrl = tMDBPersonDetails.getProfileUrl();
            String birthday = tMDBPersonDetails.getBirthday();
            String strB = birthday != null ? MobileActorDetailsViewModel.b(mobileActorDetailsViewModel, birthday) : null;
            String placeOfBirth = tMDBPersonDetails.getPlaceOfBirth();
            String biography = tMDBPersonDetails.getBiography();
            String str = (biography == null || n89.ab(biography)) ? null : biography;
            String knownForDepartment = tMDBPersonDetails.getKnownForDepartment();
            MobileActorDetailsViewModel.a aVar3 = new MobileActorDetailsViewModel.a(name, profileUrl, strB, placeOfBirth, str, knownForDepartment != null ? "Known for ".concat(knownForDepartment) : null);
            TMDBPersonMovieCredits movieCredits = tMDBPersonDetails.getMovieCredits();
            List listBj2 = ik2.a;
            if (movieCredits == null || (cast2 = movieCredits.getCast()) == null) {
                aVar = aVar3;
                listBj = listBj2;
            } else {
                ArrayList<TMDBPersonMovieCredit> arrayList = new ArrayList();
                for (Object obj2 : cast2) {
                    if (((TMDBPersonMovieCredit) obj2).getPosterPath() != null) {
                        arrayList.add(obj2);
                    }
                }
                ArrayList arrayList2 = new ArrayList(y41.p(arrayList, 10));
                for (TMDBPersonMovieCredit tMDBPersonMovieCredit : arrayList) {
                    int id = tMDBPersonMovieCredit.getId();
                    ContentItem.ItemType itemType = ContentItem.ItemType.MOVIE;
                    int id2 = tMDBPersonMovieCredit.getId();
                    String title = tMDBPersonMovieCredit.getTitle();
                    String overview = tMDBPersonMovieCredit.getOverview();
                    String posterUrl = tMDBPersonMovieCredit.getPosterUrl();
                    String backdropUrl = tMDBPersonMovieCredit.getBackdropUrl();
                    String year = tMDBPersonMovieCredit.getYear();
                    Double voteAverage = tMDBPersonMovieCredit.getVoteAverage();
                    Double voteAverage2 = tMDBPersonMovieCredit.getVoteAverage();
                    if (voteAverage2 != null) {
                        aVar2 = aVar3;
                        numBoxInt = Boxing.boxInt((int) (voteAverage2.doubleValue() * ((double) 10)));
                    } else {
                        aVar2 = aVar3;
                        numBoxInt = null;
                    }
                    arrayList2.add(new ContentItem(id, itemType, id2, null, title, overview, posterUrl, backdropUrl, null, null, year, voteAverage, numBoxInt, null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -1048064, 2047, null));
                    aVar3 = aVar2;
                }
                aVar = aVar3;
                listBj = y41.bj(new r06(), arrayList2);
            }
            TMDBPersonTVCredits tvCredits = tMDBPersonDetails.getTvCredits();
            if (tvCredits != null && (cast = tvCredits.getCast()) != null) {
                ArrayList<TMDBPersonTVCredit> arrayList3 = new ArrayList();
                for (Object obj3 : cast) {
                    if (((TMDBPersonTVCredit) obj3).getPosterPath() != null) {
                        arrayList3.add(obj3);
                    }
                }
                ArrayList arrayList4 = new ArrayList(y41.p(arrayList3, 10));
                for (TMDBPersonTVCredit tMDBPersonTVCredit : arrayList3) {
                    int id3 = tMDBPersonTVCredit.getId();
                    ContentItem.ItemType itemType2 = ContentItem.ItemType.TV_SHOW;
                    int id4 = tMDBPersonTVCredit.getId();
                    String name2 = tMDBPersonTVCredit.getName();
                    String overview2 = tMDBPersonTVCredit.getOverview();
                    String posterUrl2 = tMDBPersonTVCredit.getPosterUrl();
                    String backdropUrl2 = tMDBPersonTVCredit.getBackdropUrl();
                    String year2 = tMDBPersonTVCredit.getYear();
                    Double voteAverage3 = tMDBPersonTVCredit.getVoteAverage();
                    Double voteAverage4 = tMDBPersonTVCredit.getVoteAverage();
                    arrayList4.add(new ContentItem(id3, itemType2, id4, null, name2, overview2, posterUrl2, backdropUrl2, null, null, year2, voteAverage3, voteAverage4 != null ? Boxing.boxInt((int) (((double) 10) * voteAverage4.doubleValue())) : null, null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -1048064, 2047, null));
                }
                listBj2 = y41.bj(new s06(), arrayList4);
            }
            ig6Var.setValue(new MobileActorDetailsViewModel.b(aVar, listBj, listBj2, 16));
        } catch (Exception e) {
            Log.e("MobileActorDetailsVM", "Error loading actor details", e);
            ig6Var.setValue(MobileActorDetailsViewModel.b.a((MobileActorDetailsViewModel.b) ig6Var.getValue(), false, "Failed to load actor details"));
        }
        return e6a.a;
    }
}
