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

import androidx.lifecycle.ak;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.strmr.ps.data.local.entity.RowConfigEntity;
import com.strmr.ps.data.repository.ScreenConfigRepository;
import dagger.hilt.android.lifecycle.HiltViewModel;
import defpackage.bka;
import defpackage.cr4;
import defpackage.fx4;
import defpackage.ik2;
import defpackage.kp6;
import defpackage.n89;
import defpackage.re6;
import defpackage.rx4;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.xja;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@HiltViewModel
@Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001:\u0001\bB\u0019\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\u0007¨\u0006\t"}, d2 = {"Lcom/strmr/ps/ui/settings/viewmodel/RowCustomizationViewModel;", "Lxja;", "Lcom/strmr/ps/data/repository/ScreenConfigRepository;", "screenConfigRepository", "Landroidx/lifecycle/ak;", "savedStateHandle", "<init>", "(Lcom/strmr/ps/data/repository/ScreenConfigRepository;Landroidx/lifecycle/ak;)V", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class RowCustomizationViewModel extends xja {
    public final ScreenConfigRepository a;
    public final ak b;
    public final re6 c;
    public final re6 d;
    public final re6 e;
    public final re6 f;
    public fx4 g;

    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004¨\u0006\u0005"}, d2 = {"Lcom/strmr/ps/ui/settings/viewmodel/RowCustomizationViewModel$a;", "", "", "KEY_CURRENT_SCREEN", "Ljava/lang/String;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Inject
    public RowCustomizationViewModel(@kp6 ScreenConfigRepository screenConfigRepository, @kp6 ak akVar) {
        cr4.g(screenConfigRepository, "screenConfigRepository");
        cr4.g(akVar, "savedStateHandle");
        this.a = screenConfigRepository;
        this.b = akVar;
        re6 re6Var = new re6();
        this.c = re6Var;
        this.d = re6Var;
        re6 re6Var2 = new re6();
        this.e = re6Var2;
        this.f = re6Var2;
        h(f());
    }

    public final void b(String str, String str2, String str3, String str4, boolean z, ScreenConfigRepository.ScreenType screenType, String str5) {
        cr4.g(str, "rowType");
        cr4.g(str2, "title");
        cr4.g(str4, "presentation");
        cr4.g(screenType, "screenType");
        wj0.c(bka.a(this), null, null, new com.strmr.ps.ui.settings.viewmodel.a(this, str2, screenType, str3, str, str5, str4, z, null), 3);
    }

    public final void c(String str, String str2, String str3, ScreenConfigRepository.ScreenType screenType) {
        cr4.g(str, "title");
        cr4.g(screenType, "screenType");
        wj0.c(bka.a(this), null, null, new b(this, screenType, str, str2, str3, null), 3);
    }

    public final void d(RowConfigEntity rowConfigEntity) {
        cr4.g(rowConfigEntity, "row");
        if (cr4.b(rowConfigEntity.getPresentation(), "calendar")) {
            return;
        }
        wj0.c(bka.a(this), null, null, new c(rowConfigEntity, this, null), 3);
    }

    public final void e(RowConfigEntity rowConfigEntity) {
        cr4.g(rowConfigEntity, "row");
        if (rowConfigEntity.isSystemRow()) {
            this.e.l("System rows cannot be deleted, only disabled");
        } else {
            wj0.c(bka.a(this), null, null, new d(rowConfigEntity, this, null), 3);
        }
    }

    public final ScreenConfigRepository.ScreenType f() {
        ScreenConfigRepository.ScreenType screenTypeFromKey;
        String str = (String) this.b.b("current_screen");
        return (str == null || (screenTypeFromKey = ScreenConfigRepository.ScreenType.INSTANCE.fromKey(str)) == null) ? ScreenConfigRepository.ScreenType.HOME : screenTypeFromKey;
    }

    public final Set g() {
        String strL;
        Iterable iterable = (List) this.c.e();
        if (iterable == null) {
            iterable = ik2.a;
        }
        Iterable<RowConfigEntity> iterable2 = iterable;
        ArrayList arrayList = new ArrayList(y41.p(iterable2, 10));
        for (RowConfigEntity rowConfigEntity : iterable2) {
            boolean zB = cr4.b(rowConfigEntity.getRowType(), "trakt_list");
            String str = TtmlNode.COMBINE_ALL;
            if (!zB || rowConfigEntity.getDataSourceUrl() == null) {
                String rowType = rowConfigEntity.getRowType();
                String contentType = rowConfigEntity.getContentType();
                if (contentType != null) {
                    str = contentType;
                }
                strL = vw2.l(rowType, ":", str);
            } else {
                String rowType2 = rowConfigEntity.getRowType();
                String contentType2 = rowConfigEntity.getContentType();
                if (contentType2 != null) {
                    str = contentType2;
                }
                strL = rowType2 + ":" + str + ":" + rowConfigEntity.getDataSourceUrl();
            }
            arrayList.add(strL);
        }
        return y41.br(arrayList);
    }

    public final void h(ScreenConfigRepository.ScreenType screenType) {
        cr4.g(screenType, "screen");
        this.b.c(screenType.getKey(), "current_screen");
        fx4 fx4Var = this.g;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        this.g = wj0.c(bka.a(this), null, null, new f(this, screenType, null), 3);
    }

    public final void i(int i, int i2) {
        if (i == i2) {
            return;
        }
        re6 re6Var = this.c;
        List list = (List) re6Var.e();
        if (list != null) {
            ArrayList arrayListBp = y41.bp(list);
            if (i < 0 || i >= arrayListBp.size() || i2 < 0 || i2 >= arrayListBp.size()) {
                return;
            }
            arrayListBp.add(i2, (RowConfigEntity) arrayListBp.remove(i));
            re6Var.l(arrayListBp);
            ArrayList arrayList = new ArrayList(y41.p(arrayListBp, 10));
            Iterator it = arrayListBp.iterator();
            while (it.hasNext()) {
                arrayList.add(((RowConfigEntity) it.next()).getId());
            }
            wj0.c(bka.a(this), null, null, new g(this, arrayList, null), 3);
        }
    }

    public final void j(RowConfigEntity rowConfigEntity, String str) {
        cr4.g(rowConfigEntity, "row");
        cr4.g(str, "newTitle");
        if (n89.ab(str)) {
            this.e.l("Title cannot be empty");
        } else {
            wj0.c(bka.a(this), null, null, new h(this, rowConfigEntity, str, null), 3);
        }
    }

    public final void k() {
        wj0.c(bka.a(this), null, null, new i(this, null), 3);
    }

    public final void l(int i, int i2) {
        List list = (List) this.c.e();
        if (list != null) {
            ArrayList arrayListBp = y41.bp(list);
            if (i < 0 || i >= arrayListBp.size() || i2 < 0 || i2 >= arrayListBp.size()) {
                return;
            }
            wj0.c(bka.a(this), null, null, new j(arrayListBp, i, i2, this, null), 3);
        }
    }

    public final void m(RowConfigEntity rowConfigEntity) {
        cr4.g(rowConfigEntity, "row");
        wj0.c(bka.a(this), null, null, new k(rowConfigEntity, this, null), 3);
    }
}
