package com.base.scanqrclear.luma

import android.app.Activity
import android.graphics.Color
import android.view.View
import android.view.WindowManager
import androidx.annotation.ColorInt
import androidx.core.view.WindowCompat

object StatusBarHelps {

    fun immersiveStatusBar(activity: Activity, @ColorInt statusBarColor: Int, isDark: Boolean) {
        activity.window.apply {
            // 透明状态栏
            addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
            this.statusBarColor = statusBarColor
            if (isDark) {
                decorView.systemUiVisibility =
                    decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            } else{
                decorView.systemUiVisibility =
                    decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
            }
        }
    }

    fun setDark(activity: Activity, isDark: Boolean) {
        activity.window.apply {
            if (isDark) {
                decorView.systemUiVisibility =
                    decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            } else {
                decorView.systemUiVisibility =
                    decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
            }
        }
    }

    fun immersive(activity: Activity, @ColorInt statusBarColor: Int) {
        immersiveStatusBar(activity, statusBarColor, false)
    }

    fun immersive(activity: Activity) {
        // 设置状态栏透明
        activity.window.statusBarColor = Color.TRANSPARENT
        WindowCompat.setDecorFitsSystemWindows(activity.window, false)
    }
}