package com.strmr.ps.ui.details;

import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.media3.container.NalUnitUtil;
import com.strmr.ps.data.model.ContentItem;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.m02;
import defpackage.m12;
import defpackage.n89;
import defpackage.s38;
import defpackage.sc2;
import defpackage.wj0;
import java.util.concurrent.CancellationException;
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;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.details.DetailsFragment$fetchDetailsData$1", f = "DetailsFragment.kt", i = {}, l = {806, 814, 819, 841, 844}, m = "invokeSuspend", n = {}, s = {})
final class d extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public int a;
    public final /* synthetic */ ContentItem b;
    public final /* synthetic */ DetailsFragment c;

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public /* synthetic */ class a {
        public static final /* synthetic */ int[] a;

        static {
            int[] iArr = new int[ContentItem.ItemType.values().length];
            try {
                iArr[ContentItem.ItemType.MOVIE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[ContentItem.ItemType.TV_SHOW.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            a = iArr;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public d(ContentItem contentItem, DetailsFragment detailsFragment, Continuation continuation) {
        super(2, continuation);
        this.b = contentItem;
        this.c = detailsFragment;
    }

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

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

    /* JADX WARN: Removed duplicated region for block: B:49:0x00c1 A[PHI: r3
      0x00c1: PHI (r3v15 int) = (r3v7 int), (r3v7 int), (r3v7 int), (r3v7 int), (r3v7 int), (r3v22 int) binds: [B:34:0x008a, B:36:0x0090, B:41:0x009d, B:44:0x00a5, B:39:0x0098, B:48:0x00bb] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00c3 A[Catch: Exception -> 0x0026, CancellationException -> 0x0029, TryCatch #2 {CancellationException -> 0x0029, Exception -> 0x0026, blocks: (B:9:0x0022, B:17:0x0034, B:55:0x00f1, B:58:0x00fb, B:60:0x00ff, B:62:0x010e, B:64:0x0119, B:66:0x011f, B:68:0x0136, B:69:0x013b, B:70:0x013c, B:74:0x014d, B:77:0x0156, B:79:0x015a, B:86:0x0177, B:87:0x017c, B:18:0x003c, B:48:0x00bb, B:50:0x00c3, B:52:0x00cd, B:19:0x0043, B:32:0x007f, B:35:0x008c, B:37:0x0092, B:40:0x0099, B:42:0x009f, B:45:0x00a6, B:22:0x004c, B:24:0x0052, B:26:0x0058, B:29:0x005f, B:33:0x0086), top: B:91:0x0016 }] */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00fb A[Catch: Exception -> 0x0026, CancellationException -> 0x0029, TryCatch #2 {CancellationException -> 0x0029, Exception -> 0x0026, blocks: (B:9:0x0022, B:17:0x0034, B:55:0x00f1, B:58:0x00fb, B:60:0x00ff, B:62:0x010e, B:64:0x0119, B:66:0x011f, B:68:0x0136, B:69:0x013b, B:70:0x013c, B:74:0x014d, B:77:0x0156, B:79:0x015a, B:86:0x0177, B:87:0x017c, B:18:0x003c, B:48:0x00bb, B:50:0x00c3, B:52:0x00cd, B:19:0x0043, B:32:0x007f, B:35:0x008c, B:37:0x0092, B:40:0x0099, B:42:0x009f, B:45:0x00a6, B:22:0x004c, B:24:0x0052, B:26:0x0058, B:29:0x005f, B:33:0x0086), top: B:91:0x0016 }] */
    /* JADX WARN: Removed duplicated region for block: B:70:0x013c A[Catch: Exception -> 0x0026, CancellationException -> 0x0029, TryCatch #2 {CancellationException -> 0x0029, Exception -> 0x0026, blocks: (B:9:0x0022, B:17:0x0034, B:55:0x00f1, B:58:0x00fb, B:60:0x00ff, B:62:0x010e, B:64:0x0119, B:66:0x011f, B:68:0x0136, B:69:0x013b, B:70:0x013c, B:74:0x014d, B:77:0x0156, B:79:0x015a, B:86:0x0177, B:87:0x017c, B:18:0x003c, B:48:0x00bb, B:50:0x00c3, B:52:0x00cd, B:19:0x0043, B:32:0x007f, B:35:0x008c, B:37:0x0092, B:40:0x0099, B:42:0x009f, B:45:0x00a6, B:22:0x004c, B:24:0x0052, B:26:0x0058, B:29:0x005f, B:33:0x0086), top: B:91:0x0016 }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        int tmdbId;
        String imdbId;
        Object objF;
        String sourceAddonUrl;
        String stremioId;
        Object objF2;
        ContentItem contentItem;
        Object objF3;
        ck1 ck1Var = ck1.a;
        int i = this.a;
        e6a e6aVar = e6a.a;
        DetailsFragment detailsFragment = this.c;
        ContentItem contentItem2 = this.b;
        try {
            if (i == 0) {
                s38.b(obj);
                if (contentItem2.getTmdbId() <= 0 && (imdbId = contentItem2.getImdbId()) != null && !n89.ab(imdbId)) {
                    contentItem2.getImdbId();
                    String imdbId2 = contentItem2.getImdbId();
                    ContentItem.ItemType itemType = contentItem2.getItemType();
                    this.a = 1;
                    int i2 = DetailsFragment.cn;
                    m12 m12Var = sc2.a;
                    objF = wj0.f(m02.c, new ac(imdbId2, detailsFragment, itemType, null), this);
                    if (objF == ck1Var) {
                        return ck1Var;
                    }
                }
                tmdbId = contentItem2.getTmdbId();
                if (tmdbId <= 0 || (sourceAddonUrl = contentItem2.getSourceAddonUrl()) == null || n89.ab(sourceAddonUrl) || (stremioId = contentItem2.getStremioId()) == null || n89.ab(stremioId)) {
                    if (tmdbId <= 0) {
                    }
                    contentItem = contentItem2;
                    if (tmdbId > 0) {
                    }
                    return e6aVar;
                }
                this.a = 2;
                int i3 = DetailsFragment.cn;
                m12 m12Var2 = sc2.a;
                objF2 = wj0.f(m02.c, new ae(contentItem2, detailsFragment, null), this);
                if (objF2 == ck1Var) {
                }
                tmdbId = ((Number) objF2).intValue();
                if (tmdbId <= 0) {
                }
                contentItem = contentItem2;
                if (tmdbId > 0) {
                }
                return e6aVar;
                return ck1Var;
            }
            if (i != 1) {
                if (i == 2) {
                    s38.b(obj);
                    objF2 = obj;
                    tmdbId = ((Number) objF2).intValue();
                    if (tmdbId <= 0 || n89.ab(contentItem2.getTitle())) {
                        contentItem = contentItem2;
                        if (tmdbId > 0) {
                        }
                        return e6aVar;
                    }
                    String title = contentItem2.getTitle();
                    String year = contentItem2.getYear();
                    ContentItem.ItemType itemType2 = contentItem2.getItemType();
                    this.a = 3;
                    int i4 = DetailsFragment.cn;
                    m12 m12Var3 = sc2.a;
                    contentItem = contentItem2;
                    objF3 = wj0.f(m02.c, new af(year, title, detailsFragment, itemType2, null), this);
                    if (objF3 == ck1Var) {
                        return ck1Var;
                    }
                    tmdbId = ((Number) objF3).intValue();
                    if (tmdbId > 0) {
                    }
                    return e6aVar;
                }
                if (i != 3) {
                    if (i != 4 && i != 5) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    s38.b(obj);
                    return e6aVar;
                }
                s38.b(obj);
                objF3 = obj;
                contentItem = contentItem2;
                tmdbId = ((Number) objF3).intValue();
                if (tmdbId > 0) {
                    TextView textView = detailsFragment.r;
                    if (textView == null) {
                        cr4.n("overview");
                        throw null;
                    }
                    CharSequence text = textView.getText();
                    cr4.f(text, "getText(...)");
                    if (n89.ab(text)) {
                        Log.w("DetailsFragment", "Unable to resolve TMDB ID for item: " + contentItem.getTitle());
                        DetailsFragment.r(detailsFragment);
                        return e6aVar;
                    }
                    contentItem.getTitle();
                    if (contentItem.getItemType() == ContentItem.ItemType.TV_SHOW) {
                        DetailsFragment.o(detailsFragment, detailsFragment.i);
                        return e6aVar;
                    }
                } else {
                    int i5 = a.a[contentItem.getItemType().ordinal()];
                    if (i5 == 1) {
                        LinearLayout linearLayout = detailsFragment.aj;
                        if (linearLayout == null) {
                            cr4.n("tvShowSection");
                            throw null;
                        }
                        linearLayout.setVisibility(8);
                        this.a = 4;
                        m12 m12Var4 = sc2.a;
                        Object objF4 = wj0.f(m02.c, new g(tmdbId, detailsFragment, null), this);
                        if (objF4 != ck1Var) {
                            objF4 = e6aVar;
                        }
                        if (objF4 == ck1Var) {
                            return ck1Var;
                        }
                    } else if (i5 == 2) {
                        this.a = 5;
                        if (DetailsFragment.m(tmdbId, detailsFragment, this) == ck1Var) {
                            return ck1Var;
                        }
                    }
                }
                return e6aVar;
            }
            s38.b(obj);
            objF = obj;
            tmdbId = ((Number) objF).intValue();
            if (tmdbId <= 0) {
                if (tmdbId <= 0) {
                }
                contentItem = contentItem2;
                if (tmdbId > 0) {
                }
                return e6aVar;
            }
            return ck1Var;
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("DetailsFragment", "Error fetching details data", e2);
            DetailsFragment.r(detailsFragment);
            return e6aVar;
        }
    }
}
