package rasel.lunar.launcher.helpers

import android.content.Context
import android.content.SharedPreferences

object PrefHelper {
    val D_PREFIX = "rasel.lunar.launcher.helpers"
    val BOOL_PRE = D_PREFIX.plus(".BOOL.")
    val LONG_PRE = D_PREFIX.plus(".LONG.")
    fun inject(SharedPreferences : SharedPreferences) {
        this.sharedPreferences = SharedPreferences
    }
    var sharedPreferences : SharedPreferences? = null

    fun location(boolean: Boolean) {
        sharedPreferences?.edit()?.putBoolean(BOOL_PRE.plus("location"), boolean)?.apply()
    }

    fun isLocationOn() = sharedPreferences?.getBoolean(BOOL_PRE.plus("location") , false) ?: false

    var shortTimePeriod : Long
        get() {
            return sharedPreferences?.getLong(LONG_PRE.plus("shortTimePeriod"), 20L) ?: 20L
        }
        set(value) {
            sharedPreferences?.edit()?.putLong(LONG_PRE.plus("shortTimePeriod"),value)?.apply()
        }
    var longTimePeriod : Long
        get() {
            return sharedPreferences?.getLong(LONG_PRE.plus("longTimePeriod"), 60L) ?: 60L
        }
        set(value) {
            sharedPreferences?.edit()?.putLong(LONG_PRE.plus("longTimePeriod"),value)?.apply()
        }
    var midTimePeriod : Long
        get() {
            return sharedPreferences?.getLong(LONG_PRE.plus("midTimePeriod"), 30L) ?: 30L
        }
        set(value) {
            sharedPreferences?.edit()?.putLong(LONG_PRE.plus("midTimePeriod"),value)?.apply()
        }

}

typealias BLOCK = ()->Unit
inline fun Boolean.letTrue(block: BLOCK) {
    if (this) {
        block.invoke()
    } else {
//        elseblock.invoke()
    }
}