package com.base.browserwhite.utils

object SearchRecordUtils {

    const val SEARCH_RECORD_SP_KEY = "SEARCH_RECORD_SP_KEY"


    private fun getSearchRecord(): List<String> {
        val sp = AppPreferences.getInstance().getString(SEARCH_RECORD_SP_KEY, "")
        return if (sp.equals("")) {
            listOf()
        } else {
            sp.split(",")
        }
    }

    fun deleteSearchRecord(value: String) {
        val list = getSearchRecord().toMutableList()
        list.remove(value)
        val string = list.joinToString(separator = ",")

        AppPreferences.getInstance().put(SEARCH_RECORD_SP_KEY, string)
    }

    fun addSearchRecord(value: String) {
        val list = getSearchRecord().toMutableList()
        list.add(value)
        val string = list.joinToString(separator = ",")
        AppPreferences.getInstance().put(SEARCH_RECORD_SP_KEY, string)
    }


    fun clearSearchRecord() {
        AppPreferences.getInstance().put(SEARCH_RECORD_SP_KEY, "")
    }


}