package com.foxx.androidcast;

/*********************************************************************
 * CastThemeHelper.java
 * Created at: Sun 17 May 2026 18:17:14 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastThemeHelper
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 64 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	4dbc0e930b62735a65a2f278bc3b0164948feb338e9eb3d0d516eca92515339f
**********************************************************************/
import android.app.Activity;
import android.content.Context;

import androidx.appcompat.app.AppCompatDelegate;

/** Applies user-selected app theme before {@link Activity#setContentView}. */
public final class CastThemeHelper {
    private CastThemeHelper() {}

    public enum AppThemeMode {
        SYSTEM,
        DARK,
        LIGHT,
        INVERTED
    }

    public static void applyTheme(Activity activity) {
        AppThemeMode mode = AppPreferences.getThemeMode(activity);
        switch (mode) {
            case DARK:
                activity.setTheme(R.style.Theme_AndroidCast_Dark);
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                break;
            case LIGHT:
                activity.setTheme(R.style.Theme_AndroidCast_Light);
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                break;
            case INVERTED:
                activity.setTheme(R.style.Theme_AndroidCast_Inverted);
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                break;
            case SYSTEM:
            default:
                activity.setTheme(R.style.Theme_AndroidCast);
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                break;
        }
    }

    public static void applyNightMode(Context context) {
        switch (AppPreferences.getThemeMode(context)) {
            case DARK:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                break;
            case LIGHT:
            case INVERTED:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                break;
            case SYSTEM:
            default:
                AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
                break;
        }
    }
}
