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.StuLeave
import com.yzx.ebrand.utils.durationStr
import com.yzx.ebrand.utils.setSrc
import com.yzx.ebrand.utils.toTime
import kotlinx.android.synthetic.main.layout_leave_table.view.*
import org.jetbrains.anko.textColor

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

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

    }

    @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.typeName.text = item.leave_request_type_name
        holder.itemView.leaveTime.text =
            "${item.start_time.toTime()} -- -- ${item.end_time.toTime()}"
        holder.itemView.durationStrName.text = (item.end_time - item.start_time).durationStr()
        holder.itemView.statusName.text = when (item.status) {
            1 -> "待处理"
            2 -> "已确认"
            3 -> "已拒绝"
            4 -> "正常销假"
            5 -> "超时销假"
            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")
        }
        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.cancelBtn.visibility = if(item.is_cancel_leave ==1 ){
            holder.itemView.placeHolder.visibility = View.GONE
            View.VISIBLE
        }else{
            holder.itemView.placeHolder.visibility = View.VISIBLE
            View.GONE
        }

    }
}