package com.hx.utils.application.ui.home

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.blankj.utilcode.util.StringUtils
import com.hx.utils.application.R

class HomeViewModel : ViewModel() {
    private val _items = MutableLiveData<MutableList<String>>().apply {
        value = mutableListOf(
            StringUtils.getString(R.string.webview_test),
            StringUtils.getString(R.string.sms_tool),
            StringUtils.getString(R.string.language),
            StringUtils.getString(R.string.calendar),
            StringUtils.getString(R.string.iziLiveness),
            StringUtils.getString(R.string.wait)
        )
    }
    val items: LiveData<MutableList<String>> = _items

    private val _itemsImg = MutableLiveData<MutableList<Int>>().apply {
        value = mutableListOf(
            R.drawable.twotone_connected_tv_24,
            R.drawable.twotone_email_24,
            R.drawable.twotone_language_24,
            R.drawable.baseline_calendar_month_24,
            R.drawable.baseline_tag_faces_24,
            R.drawable.twotone_watch_later_24
        )
    }
    val itemsImg: LiveData<MutableList<Int>> = _itemsImg

    fun updateItems(newItems: List<String>) {
        _items.value?.clear()  // 清空旧数据
        _items.value?.addAll(newItems)  // 添加新数据
        _items.value = _items.value  // 触发 LiveData 更新
    }

    fun addItem(item: String) {
        _items.value?.add(item)  // 直接修改现有列表
        _items.value = _items.value // 通知 LiveData 更新
    }

}