package com.strmr.ps.ui.networkcontent;

import android.util.Log;
import androidx.lifecycle.ak;
import androidx.media3.container.NalUnitUtil;
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.TMDBMovieDetails;
import com.strmr.ps.data.model.tmdb.TMDBShowDetails;
import com.strmr.ps.data.remote.api.TMDBApiService;
import com.strmr.ps.data.remote.api.TraktApiService;
import com.strmr.ps.data.repository.PreferencesRepository;
import com.strmr.ps.data.repository.WatchStatusRepository;
import dagger.hilt.android.lifecycle.HiltViewModel;
import defpackage.bka;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.dg8;
import defpackage.ik2;
import defpackage.jl6;
import defpackage.kp6;
import defpackage.l24;
import defpackage.lo9;
import defpackage.n41;
import defpackage.n89;
import defpackage.pw7;
import defpackage.q07;
import defpackage.q38;
import defpackage.qo9;
import defpackage.re6;
import defpackage.s38;
import defpackage.s49;
import defpackage.tp5;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.xf8;
import defpackage.xja;
import defpackage.y41;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
import javax.inject.Inject;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;

/* JADX INFO: loaded from: classes3.dex */
@HiltViewModel
@Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0007\u0018\u00002\u00020\u0001B1\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006\u0012\u0006\u0010\t\u001a\u00020\b\u0012\u0006\u0010\u000b\u001a\u00020\n¢\u0006\u0004\b\f\u0010\r¨\u0006\u000e"}, d2 = {"Lcom/strmr/ps/ui/networkcontent/NetworkContentViewModel;", "Lxja;", "Lcom/strmr/ps/data/remote/api/TraktApiService;", "traktApiService", "Lcom/strmr/ps/data/remote/api/TMDBApiService;", "tmdbApiService", "Lcom/strmr/ps/data/repository/WatchStatusRepository;", "watchStatusRepository", "Lcom/strmr/ps/data/repository/PreferencesRepository;", "preferencesRepository", "Landroidx/lifecycle/ak;", "savedStateHandle", "<init>", "(Lcom/strmr/ps/data/remote/api/TraktApiService;Lcom/strmr/ps/data/remote/api/TMDBApiService;Lcom/strmr/ps/data/repository/WatchStatusRepository;Lcom/strmr/ps/data/repository/PreferencesRepository;Landroidx/lifecycle/ak;)V", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class NetworkContentViewModel extends xja {
    public final TraktApiService a;
    public String aa;
    public String ab;
    public final TMDBApiService b;
    public final WatchStatusRepository c;
    public final PreferencesRepository d;
    public final String e;
    public final String f;
    public final jl6 g;
    public final re6 h;
    public final re6 i;
    public final re6 j;
    public final re6 k;
    public final re6 l;
    public final re6 m;
    public final re6 n;
    public final re6 o;
    public int p;
    public int q;
    public boolean r;
    public boolean s;
    public boolean t;
    public final String u;
    public final String v;
    public final String w;
    public final String x;
    public final xf8 y;
    public final String z;

    @Inject
    public NetworkContentViewModel(@kp6 TraktApiService traktApiService, @kp6 TMDBApiService tMDBApiService, @kp6 WatchStatusRepository watchStatusRepository, @kp6 PreferencesRepository preferencesRepository, @kp6 ak akVar) {
        Object next;
        q07 q07VarI;
        cr4.g(traktApiService, "traktApiService");
        cr4.g(tMDBApiService, "tmdbApiService");
        cr4.g(watchStatusRepository, "watchStatusRepository");
        cr4.g(preferencesRepository, "preferencesRepository");
        cr4.g(akVar, "savedStateHandle");
        this.a = traktApiService;
        this.b = tMDBApiService;
        this.c = watchStatusRepository;
        this.d = preferencesRepository;
        String str = (String) akVar.b("network_id");
        this.e = str == null ? "" : str;
        String str2 = (String) akVar.b("network_name");
        this.f = str2 == null ? "Network" : str2;
        Iterator it = s49.e.iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            } else {
                next = it.next();
                if (((jl6) next).a.equals(this.e)) {
                    break;
                }
            }
        }
        jl6 jl6Var = (jl6) next;
        this.g = jl6Var;
        re6 re6Var = new re6(ik2.a);
        this.h = re6Var;
        this.i = re6Var;
        re6 re6Var2 = new re6(Boolean.FALSE);
        this.j = re6Var2;
        this.k = re6Var2;
        re6 re6Var3 = new re6();
        this.l = re6Var3;
        this.m = re6Var3;
        re6 re6Var4 = new re6();
        this.n = re6Var4;
        this.o = re6Var4;
        this.p = 1;
        this.q = 1;
        this.r = true;
        this.s = true;
        this.y = dg8.a(5);
        String strN = n41.n("network:", this.e);
        this.z = strN;
        this.aa = this.d.getSubPageSortBy(strN);
        this.ab = this.d.getSubPageSortHow(strN);
        if (jl6Var != null) {
            String str3 = jl6Var.e;
            q07 q07VarI2 = i(jl6Var.d);
            if (q07VarI2 != null) {
                String str4 = (String) q07VarI2.a;
                String str5 = (String) q07VarI2.b;
                this.u = str4;
                this.v = str5;
            }
            if (str3 != null && (q07VarI = i(str3)) != null) {
                String str6 = (String) q07VarI.a;
                String str7 = (String) q07VarI.b;
                this.w = str6;
                this.x = str7;
            }
            if (str3 == null) {
                this.s = false;
            }
        }
        h();
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object b(NetworkContentViewModel networkContentViewModel, String str, String str2, int i, ContinuationImpl continuationImpl) {
        e eVar;
        int i2;
        if (continuationImpl instanceof e) {
            eVar = (e) continuationImpl;
            int i3 = eVar.d;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                eVar.d = i3 - Integer.MIN_VALUE;
            } else {
                eVar = new e(networkContentViewModel, continuationImpl);
            }
        }
        e eVar2 = eVar;
        Object listMovies$default = eVar2.b;
        ck1 ck1Var = ck1.a;
        int i4 = eVar2.d;
        if (i4 == 0) {
            s38.b(listMovies$default);
            try {
                TraktApiService traktApiService = networkContentViewModel.a;
                String str3 = networkContentViewModel.aa;
                String str4 = networkContentViewModel.ab;
                Long lBoxLong = str3 != null ? Boxing.boxLong(System.currentTimeMillis()) : null;
                eVar2.a = i;
                eVar2.d = 1;
                listMovies$default = TraktApiService.DefaultImpls.getListMovies$default(traktApiService, str, str2, null, null, i, 20, str3, str4, lBoxLong, eVar2, 12, null);
                if (listMovies$default == ck1Var) {
                    return ck1Var;
                }
                i2 = i;
            } catch (Exception e) {
                e = e;
                i2 = i;
                Log.e("NetworkContentVM", "Error fetching movies list page " + i2, e);
                return ik2.a;
            }
        } else {
            if (i4 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i2 = eVar2.a;
            try {
                s38.b(listMovies$default);
            } catch (Exception e2) {
                e = e2;
                Log.e("NetworkContentVM", "Error fetching movies list page " + i2, e);
                return ik2.a;
            }
        }
        return (List) listMovies$default;
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object c(NetworkContentViewModel networkContentViewModel, String str, String str2, int i, ContinuationImpl continuationImpl) {
        f fVar;
        int i2;
        if (continuationImpl instanceof f) {
            fVar = (f) continuationImpl;
            int i3 = fVar.d;
            if ((i3 & Integer.MIN_VALUE) != 0) {
                fVar.d = i3 - Integer.MIN_VALUE;
            } else {
                fVar = new f(networkContentViewModel, continuationImpl);
            }
        }
        f fVar2 = fVar;
        Object listShows$default = fVar2.b;
        ck1 ck1Var = ck1.a;
        int i4 = fVar2.d;
        if (i4 == 0) {
            s38.b(listShows$default);
            try {
                TraktApiService traktApiService = networkContentViewModel.a;
                String str3 = networkContentViewModel.aa;
                String str4 = networkContentViewModel.ab;
                Long lBoxLong = str3 != null ? Boxing.boxLong(System.currentTimeMillis()) : null;
                fVar2.a = i;
                fVar2.d = 1;
                listShows$default = TraktApiService.DefaultImpls.getListShows$default(traktApiService, str, str2, null, null, i, 20, str3, str4, lBoxLong, fVar2, 12, null);
                if (listShows$default == ck1Var) {
                    return ck1Var;
                }
                i2 = i;
            } catch (Exception e) {
                e = e;
                i2 = i;
                Log.e("NetworkContentVM", "Error fetching shows list page " + i2, e);
                return ik2.a;
            }
        } else {
            if (i4 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            i2 = fVar2.a;
            try {
                s38.b(listShows$default);
            } catch (Exception e2) {
                e = e2;
                Log.e("NetworkContentVM", "Error fetching shows list page " + i2, e);
                return ik2.a;
            }
        }
        return (List) listShows$default;
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x0088  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x008d  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0106  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x010e  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0115  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x001c  */
    /* JADX WARN: Removed duplicated region for block: B:87:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object d(NetworkContentViewModel networkContentViewModel, int i, String str, Integer num, ContinuationImpl continuationImpl) {
        g gVar;
        String str2;
        Integer num2;
        String str3;
        Object objA;
        int i2;
        Integer num3;
        TMDBMovieDetails tMDBMovieDetails;
        String str4;
        String str5;
        String string;
        TMDBCredits credits;
        List<TMDBCast> cast;
        NetworkContentViewModel networkContentViewModel2 = networkContentViewModel;
        int i3 = i;
        networkContentViewModel2.getClass();
        if (continuationImpl instanceof g) {
            gVar = (g) continuationImpl;
            int i4 = gVar.i;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                gVar.i = i4 - Integer.MIN_VALUE;
            } else {
                gVar = new g(networkContentViewModel2, continuationImpl);
            }
        }
        Object movieDetails = gVar.e;
        ck1 ck1Var = ck1.a;
        int i5 = gVar.i;
        if (i5 == 0) {
            s38.b(movieDetails);
            try {
                TMDBApiService tMDBApiService = networkContentViewModel2.b;
                gVar.a = networkContentViewModel2;
                str2 = str;
                try {
                    gVar.b = str2;
                    num2 = num;
                    try {
                        gVar.c = num2;
                        gVar.d = i3;
                        gVar.i = 1;
                        movieDetails = tMDBApiService.getMovieDetails(i3, "images,credits,external_ids,release_dates", gVar);
                        if (movieDetails == ck1Var) {
                            return ck1Var;
                        }
                        str3 = str2;
                        objA = (TMDBMovieDetails) movieDetails;
                        Integer num4 = num2;
                        i2 = i3;
                        num3 = num4;
                    } catch (Throwable th) {
                        th = th;
                        objA = s38.a(th);
                        Integer num5 = num2;
                        i2 = i3;
                        num3 = num5;
                        str3 = str2;
                        String strAi = null;
                        if (objA instanceof q38.b) {
                        }
                        tMDBMovieDetails = (TMDBMovieDetails) objA;
                        if (tMDBMovieDetails != null) {
                        }
                    }
                } catch (Throwable th2) {
                    th = th2;
                    num2 = num;
                    objA = s38.a(th);
                    Integer num52 = num2;
                    i2 = i3;
                    num3 = num52;
                    str3 = str2;
                    String strAi2 = null;
                    if (objA instanceof q38.b) {
                    }
                    tMDBMovieDetails = (TMDBMovieDetails) objA;
                    if (tMDBMovieDetails != null) {
                    }
                }
            } catch (Throwable th3) {
                th = th3;
                str2 = str;
            }
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            int i6 = gVar.d;
            Integer num6 = gVar.c;
            str3 = gVar.b;
            NetworkContentViewModel networkContentViewModel3 = gVar.a;
            try {
                s38.b(movieDetails);
                num2 = num6;
                i3 = i6;
                networkContentViewModel2 = networkContentViewModel3;
            } catch (Throwable th4) {
                th = th4;
                num2 = num6;
                str2 = str3;
                i3 = i6;
                networkContentViewModel2 = networkContentViewModel3;
                objA = s38.a(th);
                Integer num522 = num2;
                i2 = i3;
                num3 = num522;
                str3 = str2;
                String strAi22 = null;
                if (objA instanceof q38.b) {
                }
                tMDBMovieDetails = (TMDBMovieDetails) objA;
                if (tMDBMovieDetails != null) {
                }
            }
            try {
                objA = (TMDBMovieDetails) movieDetails;
                Integer num42 = num2;
                i2 = i3;
                num3 = num42;
            } catch (Throwable th5) {
                th = th5;
                str2 = str3;
                objA = s38.a(th);
                Integer num5222 = num2;
                i2 = i3;
                num3 = num5222;
                str3 = str2;
            }
        }
        String strAi222 = null;
        if (objA instanceof q38.b) {
            objA = null;
        }
        tMDBMovieDetails = (TMDBMovieDetails) objA;
        if (tMDBMovieDetails != null) {
            return null;
        }
        ContentItem.ItemType itemType = ContentItem.ItemType.MOVIE;
        String imdbId = tMDBMovieDetails.getImdbId();
        String title = tMDBMovieDetails.getTitle();
        if (title == null) {
            if (str3 == null) {
                str3 = "";
            }
            str4 = str3;
        } else {
            str4 = title;
        }
        String overview = tMDBMovieDetails.getOverview();
        String posterUrl$default = TMDBMovieDetails.getPosterUrl$default(tMDBMovieDetails, null, 1, null);
        String preferredBackdropPath$default = TMDBImagesKt.getPreferredBackdropPath$default(tMDBMovieDetails.getImages(), null, 1, null);
        if (preferredBackdropPath$default == null) {
            preferredBackdropPath$default = tMDBMovieDetails.getBackdropPath();
        }
        String strConcat = preferredBackdropPath$default != null ? "https://image.tmdb.org/t/p/w1280".concat(preferredBackdropPath$default) : null;
        String logoUrl$default = TMDBMovieDetails.getLogoUrl$default(tMDBMovieDetails, null, 1, null);
        String releaseDate = tMDBMovieDetails.getReleaseDate();
        if (releaseDate != null) {
            string = n89.bb(4, releaseDate);
        } else {
            if (num3 == null) {
                str5 = null;
                Double voteAverage = tMDBMovieDetails.getVoteAverage();
                Integer ratingPercentage = tMDBMovieDetails.getRatingPercentage();
                List<TMDBGenre> genres = tMDBMovieDetails.getGenres();
                String strAi3 = genres == null ? y41.ai(genres, ",", null, null, new l24(22), 30) : null;
                Integer runtime = tMDBMovieDetails.getRuntime();
                String string2 = runtime == null ? runtime.toString() : null;
                credits = tMDBMovieDetails.getCredits();
                if (credits != null && (cast = credits.getCast()) != null) {
                    strAi222 = y41.ai(cast, ", ", null, null, new l24(23), 30);
                }
                return new ContentItem(i2, itemType, i2, imdbId, str4, overview, posterUrl$default, strConcat, logoUrl$default, null, str5, voteAverage, ratingPercentage, strAi3, string2, strAi222, tMDBMovieDetails.getCertification(), null, null, null, networkContentViewModel2.c.getProgress(i2, itemType), 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 = num3.toString();
        }
        str5 = string;
        Double voteAverage2 = tMDBMovieDetails.getVoteAverage();
        Integer ratingPercentage2 = tMDBMovieDetails.getRatingPercentage();
        List<TMDBGenre> genres2 = tMDBMovieDetails.getGenres();
        if (genres2 == null) {
        }
        Integer runtime2 = tMDBMovieDetails.getRuntime();
        if (runtime2 == null) {
        }
        credits = tMDBMovieDetails.getCredits();
        if (credits != null) {
            strAi222 = y41.ai(cast, ", ", null, null, new l24(23), 30);
        }
        return new ContentItem(i2, itemType, i2, imdbId, str4, overview, posterUrl$default, strConcat, logoUrl$default, null, str5, voteAverage2, ratingPercentage2, strAi3, string2, strAi222, tMDBMovieDetails.getCertification(), null, null, null, networkContentViewModel2.c.getProgress(i2, itemType), 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);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object e(NetworkContentViewModel networkContentViewModel, int i, String str, Integer num, ContinuationImpl continuationImpl) {
        h hVar;
        Exception exc;
        networkContentViewModel.getClass();
        if (continuationImpl instanceof h) {
            hVar = (h) continuationImpl;
            int i2 = hVar.d;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                hVar.d = i2 - Integer.MIN_VALUE;
            } else {
                hVar = new h(networkContentViewModel, continuationImpl);
            }
        }
        Object objB = hVar.b;
        ck1 ck1Var = ck1.a;
        int i3 = hVar.d;
        try {
            if (i3 == 0) {
                s38.b(objB);
                try {
                } catch (lo9 unused) {
                } catch (Exception e) {
                    e = e;
                    exc = e;
                    Log.w("NetworkContentVM", "Failed to fetch movie details for TMDB ID: " + i, exc);
                    return null;
                }
                try {
                    i iVar = new i(networkContentViewModel, i, str, num, null);
                    hVar.a = i;
                    hVar.d = 1;
                    objB = qo9.b(10000L, iVar, hVar);
                    if (objB == ck1Var) {
                        return ck1Var;
                    }
                    i = i;
                } catch (lo9 unused2) {
                    i = i;
                    n41.x(i, "Timeout fetching movie details for TMDB ID: ", "NetworkContentVM");
                    return null;
                } catch (Exception e2) {
                    exc = e2;
                    i = i;
                    Log.w("NetworkContentVM", "Failed to fetch movie details for TMDB ID: " + i, exc);
                    return null;
                }
            } else {
                if (i3 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i = hVar.a;
                try {
                    s38.b(objB);
                } catch (lo9 unused3) {
                    n41.x(i, "Timeout fetching movie details for TMDB ID: ", "NetworkContentVM");
                    return null;
                } catch (Exception e3) {
                    e = e3;
                    exc = e;
                    Log.w("NetworkContentVM", "Failed to fetch movie details for TMDB ID: " + i, exc);
                    return null;
                }
            }
            return (ContentItem) objB;
        } catch (CancellationException e4) {
            throw e4;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x0088  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x008f  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00f5  */
    /* JADX WARN: Removed duplicated region for block: B:70:0x0111  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0128  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x001c  */
    /* JADX WARN: Removed duplicated region for block: B:94:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object f(NetworkContentViewModel networkContentViewModel, int i, String str, Integer num, ContinuationImpl continuationImpl) {
        j jVar;
        String str2;
        Integer num2;
        String str3;
        Object objA;
        int i2;
        Integer num3;
        TMDBShowDetails tMDBShowDetails;
        String str4;
        String str5;
        String string;
        TMDBCredits credits;
        List<TMDBCast> cast;
        Integer num4;
        NetworkContentViewModel networkContentViewModel2 = networkContentViewModel;
        int i3 = i;
        networkContentViewModel2.getClass();
        if (continuationImpl instanceof j) {
            jVar = (j) continuationImpl;
            int i4 = jVar.i;
            if ((i4 & Integer.MIN_VALUE) != 0) {
                jVar.i = i4 - Integer.MIN_VALUE;
            } else {
                jVar = new j(networkContentViewModel2, continuationImpl);
            }
        }
        Object showDetails = jVar.e;
        ck1 ck1Var = ck1.a;
        int i5 = jVar.i;
        if (i5 == 0) {
            s38.b(showDetails);
            try {
                TMDBApiService tMDBApiService = networkContentViewModel2.b;
                jVar.a = networkContentViewModel2;
                str2 = str;
                try {
                    jVar.b = str2;
                    num2 = num;
                    try {
                        jVar.c = num2;
                        jVar.d = i3;
                        jVar.i = 1;
                        showDetails = tMDBApiService.getShowDetails(i3, "images,external_ids,credits,content_ratings", jVar);
                        if (showDetails == ck1Var) {
                            return ck1Var;
                        }
                        str3 = str2;
                        objA = (TMDBShowDetails) showDetails;
                        Integer num5 = num2;
                        i2 = i3;
                        num3 = num5;
                    } catch (Throwable th) {
                        th = th;
                        objA = s38.a(th);
                        Integer num6 = num2;
                        i2 = i3;
                        num3 = num6;
                        str3 = str2;
                        String strAi = null;
                        if (objA instanceof q38.b) {
                        }
                        tMDBShowDetails = (TMDBShowDetails) objA;
                        if (tMDBShowDetails != null) {
                        }
                    }
                } catch (Throwable th2) {
                    th = th2;
                    num2 = num;
                    objA = s38.a(th);
                    Integer num62 = num2;
                    i2 = i3;
                    num3 = num62;
                    str3 = str2;
                    String strAi2 = null;
                    if (objA instanceof q38.b) {
                    }
                    tMDBShowDetails = (TMDBShowDetails) objA;
                    if (tMDBShowDetails != null) {
                    }
                }
            } catch (Throwable th3) {
                th = th3;
                str2 = str;
            }
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            int i6 = jVar.d;
            Integer num7 = jVar.c;
            str3 = jVar.b;
            NetworkContentViewModel networkContentViewModel3 = jVar.a;
            try {
                s38.b(showDetails);
                num2 = num7;
                i3 = i6;
                networkContentViewModel2 = networkContentViewModel3;
            } catch (Throwable th4) {
                th = th4;
                num2 = num7;
                str2 = str3;
                i3 = i6;
                networkContentViewModel2 = networkContentViewModel3;
                objA = s38.a(th);
                Integer num622 = num2;
                i2 = i3;
                num3 = num622;
                str3 = str2;
                String strAi22 = null;
                if (objA instanceof q38.b) {
                }
                tMDBShowDetails = (TMDBShowDetails) objA;
                if (tMDBShowDetails != null) {
                }
            }
            try {
                objA = (TMDBShowDetails) showDetails;
                Integer num52 = num2;
                i2 = i3;
                num3 = num52;
            } catch (Throwable th5) {
                th = th5;
                str2 = str3;
                objA = s38.a(th);
                Integer num6222 = num2;
                i2 = i3;
                num3 = num6222;
                str3 = str2;
            }
        }
        String strAi222 = null;
        if (objA instanceof q38.b) {
            objA = null;
        }
        tMDBShowDetails = (TMDBShowDetails) objA;
        if (tMDBShowDetails != null) {
            return null;
        }
        ContentItem.ItemType itemType = ContentItem.ItemType.TV_SHOW;
        TMDBExternalIds externalIds = tMDBShowDetails.getExternalIds();
        String imdbId = externalIds != null ? externalIds.getImdbId() : null;
        String name = tMDBShowDetails.getName();
        if (name == null) {
            if (str3 == null) {
                str3 = "";
            }
            str4 = str3;
        } else {
            str4 = 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 {
            if (num3 == null) {
                str5 = null;
                Double voteAverage = tMDBShowDetails.getVoteAverage();
                Integer ratingPercentage = tMDBShowDetails.getRatingPercentage();
                List<TMDBGenre> genres = tMDBShowDetails.getGenres();
                String strAi3 = genres == null ? y41.ai(genres, ",", null, null, new l24(20), 30) : null;
                List<Integer> episodeRunTime = tMDBShowDetails.getEpisodeRunTime();
                String string2 = (episodeRunTime != null || (num4 = (Integer) y41.ab(episodeRunTime)) == null) ? null : num4.toString();
                credits = tMDBShowDetails.getCredits();
                if (credits != null && (cast = credits.getCast()) != null) {
                    strAi222 = y41.ai(cast, ", ", null, null, new l24(21), 30);
                }
                return new ContentItem(i2, itemType, i2, imdbId, str4, overview, posterUrl$default, strConcat, logoUrl$default, null, str5, voteAverage, ratingPercentage, strAi3, string2, strAi222, tMDBShowDetails.getCertification(), null, null, null, networkContentViewModel2.c.getProgress(i2, itemType), 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 = num3.toString();
        }
        str5 = 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) {
            strAi222 = y41.ai(cast, ", ", null, null, new l24(21), 30);
        }
        return new ContentItem(i2, itemType, i2, imdbId, str4, overview, posterUrl$default, strConcat, logoUrl$default, null, str5, voteAverage2, ratingPercentage2, strAi3, string2, strAi222, tMDBShowDetails.getCertification(), null, null, null, networkContentViewModel2.c.getProgress(i2, itemType), 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);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object g(NetworkContentViewModel networkContentViewModel, int i, String str, Integer num, ContinuationImpl continuationImpl) {
        k kVar;
        Exception exc;
        networkContentViewModel.getClass();
        if (continuationImpl instanceof k) {
            kVar = (k) continuationImpl;
            int i2 = kVar.d;
            if ((i2 & Integer.MIN_VALUE) != 0) {
                kVar.d = i2 - Integer.MIN_VALUE;
            } else {
                kVar = new k(networkContentViewModel, continuationImpl);
            }
        }
        Object objB = kVar.b;
        ck1 ck1Var = ck1.a;
        int i3 = kVar.d;
        try {
            if (i3 == 0) {
                s38.b(objB);
                try {
                } catch (lo9 unused) {
                } catch (Exception e) {
                    e = e;
                    exc = e;
                    Log.w("NetworkContentVM", "Failed to fetch show details for TMDB ID: " + i, exc);
                    return null;
                }
                try {
                    l lVar = new l(networkContentViewModel, i, str, num, null);
                    kVar.a = i;
                    kVar.d = 1;
                    objB = qo9.b(10000L, lVar, kVar);
                    if (objB == ck1Var) {
                        return ck1Var;
                    }
                    i = i;
                } catch (lo9 unused2) {
                    i = i;
                    n41.x(i, "Timeout fetching show details for TMDB ID: ", "NetworkContentVM");
                    return null;
                } catch (Exception e2) {
                    exc = e2;
                    i = i;
                    Log.w("NetworkContentVM", "Failed to fetch show details for TMDB ID: " + i, exc);
                    return null;
                }
            } else {
                if (i3 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                i = kVar.a;
                try {
                    s38.b(objB);
                } catch (lo9 unused3) {
                    n41.x(i, "Timeout fetching show details for TMDB ID: ", "NetworkContentVM");
                    return null;
                } catch (Exception e3) {
                    e = e3;
                    exc = e;
                    Log.w("NetworkContentVM", "Failed to fetch show details for TMDB ID: " + i, exc);
                    return null;
                }
            }
            return (ContentItem) objB;
        } catch (CancellationException e4) {
            throw e4;
        }
    }

    public static q07 i(String str) {
        tp5 tp5VarB = new pw7("trakt\\.tv/users/([^/]+)/lists/([^/?]+)").b(str);
        if (tp5VarB != null) {
            return new q07((String) tp5VarB.b().get(1), (String) tp5VarB.b().get(2));
        }
        return null;
    }

    public final void h() {
        if (this.g != null) {
            wj0.c(bka.a(this), null, null, new n(this, null), 3);
            return;
        }
        this.l.l("Network not found: " + this.e);
    }

    public final void j() {
        this.p = 1;
        this.q = 1;
        this.r = true;
        jl6 jl6Var = this.g;
        this.s = (jl6Var != null ? jl6Var.e : null) != null;
        this.h.l(ik2.a);
        h();
    }
}
