package com.base.pdfreaderallpdfreader.ui.main.bookmark

import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.base.pdfreaderallpdfreader.bean.DocumentBean
import com.base.pdfreaderallpdfreader.bean.DocumentBean.Companion.TYPE_PDF
import com.base.pdfreaderallpdfreader.ui.main.getAllDocument
import com.base.pdfreaderallpdfreader.ui.main.pdfCheck
import com.base.pdfreaderallpdfreader.utils.SpStringUtils
import com.base.pdfreaderallpdfreader.utils.SpStringUtils.BOOKMARK_KEY

class BookmarkViewModel : ViewModel() {

    private val _text = MutableLiveData<String>().apply {
        value = "This is gallery Fragment"
    }
    val text: LiveData<String> = _text


    fun getBookmarkDocument(context: Context): List<DocumentBean> {
        val all = getAllDocument(context)
        val bookmarkList = SpStringUtils.getSpStringList(BOOKMARK_KEY)
        all.map {
            if (it.type == TYPE_PDF) {
                context.pdfCheck(it)
            }
            it.isBookmarked = bookmarkList.contains(it.path)
        }
        return all.filter { it.isBookmarked }
    }

}