package com.yzx.escreen.adapter

import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.graphics.Color
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yzx.escreen.R
import com.yzx.escreen.model.StuLeave
import com.yzx.escreen.utils.setSrc
import com.yzx.escreen.utils.toTime
import kotlinx.android.synthetic.main.layout_leave_table2.view.*

class HomeGridAdapter(list: MutableList<StuLeave>) :
    BaseQuickAdapter<StuLeave, BaseViewHolder>(R.layout.layout_leave_table2, list) {

    init {
        addChildClickViewIds(R.id.faceEmpty,R.id.statusName)

    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: StuLeave) {
        holder.itemView.studentName.text = item.leave_student_name
        if (item.face_key.isNullOrBlank()) {
            holder.itemView.faceEmpty.visibility = View.VISIBLE
            holder.itemView.faceImg.visibility = View.GONE
        } else {
            holder.itemView.faceImg.visibility = View.VISIBLE
            holder.itemView.faceEmpty.visibility = View.GONE
            holder.itemView.faceImg.setSrc(item.face_identity, item.face_key)
        }
        holder.itemView.className.text = "${item.grade_name}${item.class_name}"
        holder.itemView.statusName.text = when (item.status) {
            1 -> "待处理"
            2 -> "已确认"
            3 -> "已拒绝"
            4 -> "正常销假"
            5 -> "超时销假"
            else -> "--"
        }
        holder.itemView.statusName.setBackgroundColor(
            when (item.status) {
                1 -> Color.parseColor("#cccccc")
                2 -> Color.parseColor("#3c7ef6")
                3 -> Color.parseColor("#ff4040")
                4 -> Color.parseColor("#3c7ef6")
                5 -> Color.parseColor("#ff4040")
                else -> Color.parseColor("#cccccc")
            }
        )
        holder.itemView.statusName.setStrokeColors(
            ColorStateList.valueOf(
                when (item.status) {
                    1 -> Color.parseColor("#cccccc")
                    2 -> Color.parseColor("#3c7ef6")
                    3 -> Color.parseColor("#ff4040")
                    4 -> Color.parseColor("#3c7ef6")
                    5 -> Color.parseColor("#ff4040")
                    else -> Color.parseColor("#cccccc")
                }
            )
        )
        holder.itemView.applyTime.text = item.add_time.toTime()


    }
}