package com.module.backstage.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.module.backstage.R
import com.module.backstage.databinding.BackstageItemErrorstatBinding
import com.module.database.room.entity.WarringBean
import java.text.SimpleDateFormat
import java.util.Date


// 假设有一个Item布局文件item_layout.xml，对应的ViewBinding类为BackstageItemErrorstatBinding
// 以及一个数据模型类DataModel  
  
class ErrorAdapter(var productList: MutableList<WarringBean>? = null) :
    BaseBindingAdapter<WarringBean, BackstageItemErrorstatBinding>(productList) {
  
    override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): BackstageItemErrorstatBinding {
        return BackstageItemErrorstatBinding.inflate(inflater, parent, false)
    }  
  
    @SuppressLint("SetTextI18n", "SimpleDateFormat")
    override fun convert(holder: BaseBindViewHolder<BackstageItemErrorstatBinding>, warringBean: WarringBean) {
        // 其他数据绑定操作...

        // 使用ViewBinding来绑定数据  
        holder.binding.run {
//            if (holder.layoutPosition == 0) {
//                tvTime.text = "时间"
//                tvThingError.text = "错误事件"
//                tvRemark.text = "备注"
//                return
//            }
            var formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
            val curDate = Date(warringBean.time)
            val time = formatter.format(curDate)
            tvTime.text = ""+holder.layoutPosition+". "+time
            tvThingError.text = warringBean.thingError
            tvRemark.text = warringBean.remark
        }
    }  
}