package com.yzx.escreen.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.escreen.R
import com.yzx.escreen.model.Visitor
import com.yzx.escreen.utils.toTime
import kotlinx.android.synthetic.main.layout_visitor_table.view.applyTime
import kotlinx.android.synthetic.main.layout_visitor_table.view.bottomLine
import kotlinx.android.synthetic.main.layout_visitor_table.view.inOutTime
import kotlinx.android.synthetic.main.layout_visitor_table.view.isDrive
import kotlinx.android.synthetic.main.layout_visitor_table.view.receptionUser
import kotlinx.android.synthetic.main.layout_visitor_table.view.statusName
import kotlinx.android.synthetic.main.layout_visitor_table.view.userName
import org.jetbrains.anko.textColor

class VisitorListAdapter(list: MutableList<Visitor>) :
    BaseQuickAdapter<Visitor, BaseViewHolder>(R.layout.layout_visitor_table, list) {

    init {
//        addChildClickViewIds(R.id.faceEmpty)
    }

    @SuppressLint("SetTextI18n", "Range")
    override fun convert(holder: BaseViewHolder, item: Visitor) {
        holder.itemView.userName.text = item.user_name
//        holder.itemView.userTypeName.text = when (item.user_type) {
//            0 -> ""
//            1 -> "老师"
//            2 -> "学生"
//            3 -> "访客"
//            else -> "--"
//        }
        holder.itemView.isDrive.text = if (item.is_drive == 1) {
            "是（${item.license_plate}）"
        } else {
            "否"
        }
        holder.itemView.receptionUser.text = item.reception_user
        holder.itemView.statusName.text = when (item.audit_status) {
            0 -> "待审核"
            1 -> "可通行"
            2 -> "审核拒绝"
            -1 -> "已失效"
            else -> "--"
        }
        holder.itemView.statusName.textColor = when (item.audit_status) {
            0 -> Color.parseColor("#333333")
            1 -> Color.parseColor("#3c7ef6")
            2 -> Color.parseColor("#ff4040")
            -1 -> Color.parseColor("#999999")
            else -> Color.parseColor("#333333")
        }

        holder.itemView.applyTime.text = item.add_time.toTime()
        holder.itemView.inOutTime.text =  "${item.start_time.toTime()} - ${item.end_time.toTime()}"

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