package com.yzx.ebrand.adapter

import android.annotation.SuppressLint
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.ebrand.R
import com.yzx.ebrand.model.StuChange
import com.yzx.ebrand.utils.setSrc
import com.yzx.ebrand.utils.toDay
import com.yzx.ebrand.utils.toTime
import kotlinx.android.synthetic.main.layout_change_table.view.*
import org.jetbrains.anko.textColor

class ChangeListAdapter(list: MutableList<StuChange>) :
    BaseQuickAdapter<StuChange, BaseViewHolder>(R.layout.layout_change_table, list) {

    init {
        addChildClickViewIds(R.id.cancelBtn,R.id.faceEmpty)
    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: StuChange) {
        holder.itemView.studentName.text = item.status_change_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.typeName.text = item.status_change_type_name

        var time = "--"
        if (item.start_time > 0) {
            time = item.start_time.toDay()
        }
        if (item.end_time > 0) {
            time = "$time -- ${item.end_time.toDay()}"
        }
        holder.itemView.leaveTime.text = time

        holder.itemView.statusName.text = when (item.status) {
            1 -> "待处理"
            2 -> "已确认"
            3 -> "已拒绝"
            else -> "--"
        }
        holder.itemView.statusName.textColor = when (item.status) {
            1 -> Color.parseColor("#333333")
            2 -> Color.parseColor("#3c7ef6")
            3 -> Color.parseColor("#ff4040")
            4 -> Color.parseColor("#3c7ef6")
            5 -> Color.parseColor("#ff4040")
            else -> Color.parseColor("#333333")
        }
        if (item.getSubStatusName().isNotEmpty()) {
            holder.itemView.subStatusName.text = "（${item.getSubStatusName()}）"
            holder.itemView.subStatusName.textColor = when (item.sub_status) {
                0, 2 -> Color.parseColor("#ff4040")
                1, 3 -> Color.parseColor("#07c160")
                else -> Color.parseColor("#333333")
            }
        } else {
            holder.itemView.subStatusName.text = ""
        }

        holder.itemView.applyTime.text = item.add_time.toTime()

        holder.itemView.bottomLine.visibility = if (holder.adapterPosition == data.size - 1) {
            View.GONE
        } else {
            View.VISIBLE
        }
        holder.itemView.addUser.text = item.add_user_name
    }
}