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

import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.strmr.ps.R;
import com.strmr.ps.data.local.entity.RowConfigEntity;
import com.strmr.ps.data.local.entity.RowConfigExtensionsKt;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.ui.mobile.settings.MobileLayoutRowsFragment;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.io6;
import defpackage.k12;
import defpackage.m02;
import defpackage.m12;
import defpackage.s38;
import defpackage.sc2;
import defpackage.sf1;
import defpackage.vw2;
import defpackage.wj0;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
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.mobile.settings.MobileLayoutRowsFragment$showAddRowBottomSheet$1", f = "MobileLayoutRowsFragment.kt", i = {0}, l = {261}, m = "invokeSuspend", n = {"existingKeys"}, s = {"L$0"})
final class ax extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public Set a;
    public int b;
    public final /* synthetic */ MobileLayoutRowsFragment c;
    public final /* synthetic */ Context d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public ax(MobileLayoutRowsFragment mobileLayoutRowsFragment, Context context, Continuation continuation) {
        super(2, continuation);
        this.c = mobileLayoutRowsFragment;
        this.d = context;
    }

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

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

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        Object objF;
        Set set;
        List list;
        String strL;
        String str;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        MobileLayoutRowsFragment mobileLayoutRowsFragment = this.c;
        if (i == 0) {
            s38.b(obj);
            Set setG = mobileLayoutRowsFragment.p().g();
            m12 m12Var = sc2.a;
            m02 m02Var = m02.c;
            aw awVar = new aw(mobileLayoutRowsFragment, null);
            this.a = setG;
            this.b = 1;
            objF = wj0.f(m02Var, awVar, this);
            if (objF == ck1Var) {
                return ck1Var;
            }
            set = setG;
        } else {
            if (i != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            set = this.a;
            s38.b(obj);
            objF = obj;
        }
        TraktAccount traktAccount = (TraktAccount) objF;
        Context context = this.d;
        BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(context);
        ScrollView scrollView = new ScrollView(context);
        scrollView.setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
        LinearLayout linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(1);
        linearLayout.setPadding(0, mobileLayoutRowsFragment.o(8), 0, mobileLayoutRowsFragment.o(24));
        linearLayout.setBackgroundColor(sf1.getColor(context, R.color.dialog_glass_bg));
        TextView textView = new TextView(context);
        textView.setText("Add Row");
        textView.setTextColor(sf1.getColor(context, R.color.mobile_on_surface));
        textView.setTextSize(20.0f);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setPadding(mobileLayoutRowsFragment.o(24), mobileLayoutRowsFragment.o(16), mobileLayoutRowsFragment.o(24), mobileLayoutRowsFragment.o(16));
        linearLayout.addView(textView);
        MobileLayoutRowsFragment.m(mobileLayoutRowsFragment, linearLayout, "DEFAULT ROWS");
        int i2 = MobileLayoutRowsFragment.c.a[mobileLayoutRowsFragment.n.ordinal()];
        if (i2 == 1) {
            list = k12.a;
        } else if (i2 == 2) {
            list = k12.b;
        } else {
            if (i2 != 3) {
                throw new io6();
            }
            list = k12.c;
        }
        ArrayList<RowConfigEntity> arrayList = new ArrayList();
        for (Object obj2 : list) {
            RowConfigEntity rowConfigEntity = (RowConfigEntity) obj2;
            if (!cr4.b(rowConfigEntity.getRowType(), "continue_watching") && !cr4.b(rowConfigEntity.getRowType(), "continue_watching_movies") && !cr4.b(rowConfigEntity.getRowType(), "continue_watching_tv")) {
                arrayList.add(obj2);
            }
        }
        ArrayList arrayList2 = new ArrayList(y41.p(arrayList, 10));
        for (RowConfigEntity rowConfigEntity2 : arrayList) {
            String rowType = rowConfigEntity2.getRowType();
            Context contextRequireContext = mobileLayoutRowsFragment.requireContext();
            cr4.f(contextRequireContext, "requireContext(...)");
            arrayList2.add(new MobileLayoutRowsFragment.a(rowType, RowConfigExtensionsKt.resolveTitle(rowConfigEntity2, contextRequireContext), rowConfigEntity2.getContentType(), rowConfigEntity2.getPresentation(), rowConfigEntity2.getRequiresAuth(), null, rowConfigEntity2.getDataSourceUrl(), 32));
        }
        Iterator it = arrayList2.iterator();
        while (true) {
            boolean zHasNext = it.hasNext();
            String str2 = TtmlNode.COMBINE_ALL;
            if (!zHasNext) {
                break;
            }
            MobileLayoutRowsFragment.a aVar = (MobileLayoutRowsFragment.a) it.next();
            String str3 = aVar.a;
            String str4 = aVar.c;
            if (!cr4.b(str3, "trakt_list") || (str = aVar.g) == null) {
                if (str4 != null) {
                    str2 = str4;
                }
                strL = vw2.l(str3, ":", str2);
            } else {
                if (str4 != null) {
                    str2 = str4;
                }
                strL = str3 + ":" + str2 + ":" + str;
            }
            MobileLayoutRowsFragment.l(mobileLayoutRowsFragment, linearLayout, aVar, set.contains(strL), bottomSheetDialog);
        }
        if (traktAccount != null) {
            MobileLayoutRowsFragment.m(mobileLayoutRowsFragment, linearLayout, "TRAKT PERSONAL");
            for (MobileLayoutRowsFragment.a aVar2 : mobileLayoutRowsFragment.o) {
                String str5 = aVar2.a;
                String str6 = aVar2.c;
                if (str6 == null) {
                    str6 = TtmlNode.COMBINE_ALL;
                }
                MobileLayoutRowsFragment.l(mobileLayoutRowsFragment, linearLayout, aVar2, set.contains(str5 + ":" + str6), bottomSheetDialog);
            }
        }
        MobileLayoutRowsFragment.m(mobileLayoutRowsFragment, linearLayout, "GENRES");
        for (MobileLayoutRowsFragment.a aVar3 : mobileLayoutRowsFragment.p) {
            String str7 = aVar3.a;
            String str8 = aVar3.c;
            if (str8 == null) {
                str8 = TtmlNode.COMBINE_ALL;
            }
            MobileLayoutRowsFragment.l(mobileLayoutRowsFragment, linearLayout, aVar3, set.contains(str7 + ":" + str8), bottomSheetDialog);
        }
        MobileLayoutRowsFragment.m(mobileLayoutRowsFragment, linearLayout, "TRAKT LISTS");
        Context contextRequireContext2 = mobileLayoutRowsFragment.requireContext();
        cr4.f(contextRequireContext2, "requireContext(...)");
        LinearLayout linearLayout2 = new LinearLayout(contextRequireContext2);
        linearLayout2.setOrientation(0);
        linearLayout2.setGravity(16);
        linearLayout2.setPadding(mobileLayoutRowsFragment.o(24), mobileLayoutRowsFragment.o(14), mobileLayoutRowsFragment.o(24), mobileLayoutRowsFragment.o(14));
        linearLayout2.setClickable(true);
        linearLayout2.setFocusable(true);
        TypedValue typedValue = new TypedValue();
        contextRequireContext2.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
        linearLayout2.setBackgroundResource(typedValue.resourceId);
        linearLayout2.setOnClickListener(new h(bottomSheetDialog, mobileLayoutRowsFragment, 1));
        LinearLayout linearLayout3 = new LinearLayout(contextRequireContext2);
        linearLayout3.setOrientation(1);
        linearLayout3.setLayoutParams(new LinearLayout.LayoutParams(0, -2, 1.0f));
        TextView textView2 = new TextView(contextRequireContext2);
        textView2.setText("Browse Trakt Lists");
        textView2.setTextColor(sf1.getColor(contextRequireContext2, R.color.mobile_on_surface));
        textView2.setTextSize(15.0f);
        linearLayout3.addView(textView2);
        TextView textView3 = new TextView(contextRequireContext2);
        textView3.setText("Add from liked, trending, or popular lists");
        textView3.setTextColor(sf1.getColor(contextRequireContext2, R.color.mobile_on_surface_variant));
        textView3.setTextSize(12.0f);
        linearLayout3.addView(textView3);
        linearLayout2.addView(linearLayout3);
        TextView textView4 = new TextView(contextRequireContext2);
        textView4.setText(">");
        textView4.setTextColor(sf1.getColor(contextRequireContext2, R.color.mobile_on_surface_variant));
        textView4.setTextSize(16.0f);
        textView4.setPadding(mobileLayoutRowsFragment.o(12), 0, 0, 0);
        linearLayout2.addView(textView4);
        linearLayout.addView(linearLayout2);
        scrollView.addView(linearLayout);
        bottomSheetDialog.setContentView(scrollView);
        bottomSheetDialog.show();
        return e6a.a;
    }
}
