package cc;

import android.app.UiModeManager;
import android.content.Context;
import android.os.Build;

/* loaded from: classes4.dex */
public final class d3 {

    /* renamed from: a, reason: collision with root package name */
    public static final d3 f11413a = new d3();

    /* loaded from: classes4.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f11414a;

        static {
            int[] iArr = new int[z2.values().length];
            try {
                iArr[z2.USE_SYSTEM_SETTINGS.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[z2.ALWAYS_ON.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[z2.ALWAYS_OFF.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            f11414a = iArr;
        }
    }

    private d3() {
    }

    private final void d(Context context) {
        if (Build.VERSION.SDK_INT <= 30) {
            i.e.G(2);
            return;
        }
        Object systemService = context.getSystemService("uimode");
        kotlin.jvm.internal.t.e(systemService, "null cannot be cast to non-null type android.app.UiModeManager");
        ((UiModeManager) systemService).setApplicationNightMode(2);
    }

    private final void e(Context context) {
        if (Build.VERSION.SDK_INT <= 30) {
            i.e.G(1);
            return;
        }
        Object systemService = context.getSystemService("uimode");
        kotlin.jvm.internal.t.e(systemService, "null cannot be cast to non-null type android.app.UiModeManager");
        ((UiModeManager) systemService).setApplicationNightMode(1);
    }

    private final void f(Context context) {
        if (Build.VERSION.SDK_INT <= 30) {
            i.e.G(-1);
            return;
        }
        Object systemService = context.getSystemService("uimode");
        kotlin.jvm.internal.t.e(systemService, "null cannot be cast to non-null type android.app.UiModeManager");
        ((UiModeManager) systemService).setApplicationNightMode(0);
    }

    public final z2 a(ja.d sharedPreferencesService) {
        kotlin.jvm.internal.t.g(sharedPreferencesService, "sharedPreferencesService");
        z2 z2Var = z2.USE_SYSTEM_SETTINGS;
        String string = sharedPreferencesService.getString("PREF_SELECTED_THEME_KEY", z2Var.toString());
        z2 z2Var2 = z2.ALWAYS_ON;
        if (!kotlin.jvm.internal.t.b(string, z2Var2.toString())) {
            z2Var2 = z2.ALWAYS_OFF;
            if (!kotlin.jvm.internal.t.b(string, z2Var2.toString())) {
                return z2Var;
            }
        }
        return z2Var2;
    }

    public final int b(ja.d sharedPreferencesService) {
        kotlin.jvm.internal.t.g(sharedPreferencesService, "sharedPreferencesService");
        String string = sharedPreferencesService.getString("PREF_SELECTED_THEME_KEY", z2.USE_SYSTEM_SETTINGS.toString());
        if (kotlin.jvm.internal.t.b(string, z2.ALWAYS_ON.toString())) {
            return 2;
        }
        return kotlin.jvm.internal.t.b(string, z2.ALWAYS_OFF.toString()) ? 1 : -1;
    }

    public final void c(rm.v selectedOption, ja.d sharedPreferencesService, Context context) {
        kotlin.jvm.internal.t.g(selectedOption, "selectedOption");
        kotlin.jvm.internal.t.g(sharedPreferencesService, "sharedPreferencesService");
        kotlin.jvm.internal.t.g(context, "context");
        sharedPreferencesService.putString("PREF_SELECTED_THEME_KEY", ((z2) selectedOption.d()).toString());
        int i10 = a.f11414a[((z2) selectedOption.d()).ordinal()];
        if (i10 == 1) {
            f(context);
        } else if (i10 == 2) {
            d(context);
        } else {
            if (i10 != 3) {
                return;
            }
            e(context);
        }
    }
}
