package com.base.appzxhy.ui.main

import android.content.Context
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.base.appzxhy.ui.recyclebin.RecycleBinUtils.getRecycleBinData
import com.base.appzxhy.utils.PermissionUtils.checkStorePermission
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.io.File

class MainViewModel : ViewModel() {

    var dialogFlow: MutableStateFlow<String> = MutableStateFlow("")
    var nextShowDialog: Boolean = true

    fun checkDialog(context: Context) {
        if (!context.checkStorePermission()) {
            dialogFlow.update { "StoreDialog" }
            return
        }

//        if (!context.checkNotificationPermission()) {
//            dialogFlow.update { "NotificationDialog" }
//            return
//        }
    }

    var recycleBinFileFlow: MutableStateFlow<List<File>> = MutableStateFlow(listOf())

    fun refreshRecycleBin() = viewModelScope.launch(Dispatchers.IO) {
        recycleBinFileFlow.update { getRecycleBinData() }
    }
}