package com.strmr.ps.ui.usercollection;

import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.tmdb.TMDBCast;
import com.strmr.ps.data.model.tmdb.TMDBCredits;
import com.strmr.ps.data.model.tmdb.TMDBExternalIds;
import com.strmr.ps.data.model.tmdb.TMDBGenre;
import com.strmr.ps.data.model.tmdb.TMDBImagesKt;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.remote.api.TMDBApiService;
import defpackage.ak1;
import defpackage.cba;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.n89;
import defpackage.s38;
import defpackage.vx8;
import defpackage.y41;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
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;", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Lcom/strmr/ps/data/model/ContentItem;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.usercollection.UserCollectionContentViewModel$fetchShowDetailsWithTimeout$2", f = "UserCollectionContentViewModel.kt", i = {}, l = {534}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class s extends SuspendLambda implements gr3<ak1, Continuation<? super ContentItem>, Object> {
    public int a;
    public final /* synthetic */ UserCollectionContentViewModel b;
    public final /* synthetic */ int c;
    public final /* synthetic */ String d;
    public final /* synthetic */ Integer e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public s(UserCollectionContentViewModel userCollectionContentViewModel, int i, String str, Integer num, Continuation continuation) {
        super(2, continuation);
        this.b = userCollectionContentViewModel;
        this.c = i;
        this.d = str;
        this.e = num;
    }

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

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

    /* JADX WARN: Removed duplicated region for block: B:36:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00b3  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00ca  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object showDetails;
        String str;
        String string;
        TMDBCredits credits;
        List<TMDBCast> cast;
        Integer num;
        ck1 ck1Var = ck1.a;
        int i = this.a;
        int i2 = this.c;
        UserCollectionContentViewModel userCollectionContentViewModel = this.b;
        if (i == 0) {
            s38.b(obj);
            TMDBApiService tMDBApiService = userCollectionContentViewModel.c;
            this.a = 1;
            showDetails = tMDBApiService.getShowDetails(i2, "images,external_ids,credits,content_ratings", this);
            if (showDetails == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            showDetails = obj;
        }
        TMDBShowDetails tMDBShowDetails = (TMDBShowDetails) showDetails;
        ContentItem.ItemType itemType = ContentItem.ItemType.TV_SHOW;
        TMDBExternalIds externalIds = tMDBShowDetails.getExternalIds();
        String strAi = null;
        String imdbId = externalIds != null ? externalIds.getImdbId() : null;
        String name = tMDBShowDetails.getName();
        if (name == null && (name = this.d) == null) {
            name = "";
        }
        String str2 = name;
        String overview = tMDBShowDetails.getOverview();
        String posterUrl$default = TMDBShowDetails.getPosterUrl$default(tMDBShowDetails, null, 1, null);
        String preferredBackdropPath$default = TMDBImagesKt.getPreferredBackdropPath$default(tMDBShowDetails.getImages(), null, 1, null);
        if (preferredBackdropPath$default == null) {
            preferredBackdropPath$default = tMDBShowDetails.getBackdropPath();
        }
        String strConcat = preferredBackdropPath$default != null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath$default) : null;
        String logoUrl$default = TMDBShowDetails.getLogoUrl$default(tMDBShowDetails, null, 1, null);
        String firstAirDate = tMDBShowDetails.getFirstAirDate();
        if (firstAirDate != null) {
            string = n89.bb(4, firstAirDate);
        } else {
            Integer num2 = this.e;
            if (num2 == null) {
                str = null;
                Double voteAverage = tMDBShowDetails.getVoteAverage();
                Integer ratingPercentage = tMDBShowDetails.getRatingPercentage();
                List<TMDBGenre> genres = tMDBShowDetails.getGenres();
                String strAi2 = genres == null ? y41.ai(genres, ",", null, null, new cba(1), 30) : null;
                List<Integer> episodeRunTime = tMDBShowDetails.getEpisodeRunTime();
                String string2 = (episodeRunTime != null || (num = (Integer) y41.ab(episodeRunTime)) == null) ? null : num.toString();
                credits = tMDBShowDetails.getCredits();
                if (credits != null && (cast = credits.getCast()) != null) {
                    strAi = y41.ai(cast, ", ", null, null, new cba(2), 30);
                }
                String certification = tMDBShowDetails.getCertification();
                Double progress = userCollectionContentViewModel.d.getProgress(i2, itemType);
                int i3 = this.c;
                return new ContentItem(i3, itemType, i3, imdbId, str2, overview, posterUrl$default, strConcat, logoUrl$default, null, str, voteAverage, ratingPercentage, strAi2, string2, strAi, certification, null, null, null, progress, null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -2096640, 2047, null);
            }
            string = num2.toString();
        }
        str = string;
        Double voteAverage2 = tMDBShowDetails.getVoteAverage();
        Integer ratingPercentage2 = tMDBShowDetails.getRatingPercentage();
        List<TMDBGenre> genres2 = tMDBShowDetails.getGenres();
        if (genres2 == null) {
        }
        List<Integer> episodeRunTime2 = tMDBShowDetails.getEpisodeRunTime();
        if (episodeRunTime2 != null) {
        }
        credits = tMDBShowDetails.getCredits();
        if (credits != null) {
            strAi = y41.ai(cast, ", ", null, null, new cba(2), 30);
        }
        String certification2 = tMDBShowDetails.getCertification();
        Double progress2 = userCollectionContentViewModel.d.getProgress(i2, itemType);
        int i32 = this.c;
        return new ContentItem(i32, itemType, i32, imdbId, str2, overview, posterUrl$default, strConcat, logoUrl$default, null, str, voteAverage2, ratingPercentage2, strAi2, string2, strAi, certification2, null, null, null, progress2, null, null, null, false, null, null, null, null, null, 0, null, null, null, null, null, null, null, null, null, null, null, null, -2096640, 2047, null);
    }
}
