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.AuditRecordOut
import com.yzx.ebrand.utils.toTime
import kotlinx.android.synthetic.main.layout_visitor_step.view.*
import org.jetbrains.anko.dip
import org.jetbrains.anko.textColor

class VisitorDialogStepAdapter(list: MutableList<AuditRecordOut>) :
    BaseQuickAdapter<AuditRecordOut, BaseViewHolder>(R.layout.layout_visitor_step, list) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: AuditRecordOut) {

        holder.itemView.visibility = View.VISIBLE
        holder.itemView.addUserName.text = item.getTitle()
        holder.itemView.approvalComments.visibility = if(item.audit_user_name.isNotEmpty()){
            holder.itemView.approvalComments.text = "审批人：${item.audit_user_name}。${item.audit_remark}"
            holder.itemView.approvalComments.textColor = when (item.audit_status) {
                0 -> Color.parseColor("#ff4040")
                1 -> Color.parseColor("#3c7ef6")
                2 -> Color.parseColor("#ff4040")
                -1 -> Color.parseColor("#999999")
                else -> Color.parseColor("#333333")
            }
            View.VISIBLE
        }else{
            View.GONE
        }
        holder.itemView.approvalTime.text = item.add_time.toTime()
        if (holder.adapterPosition == 0) {
            holder.itemView.line1.setBackgroundResource(R.color.transparent)
        } else {
            holder.itemView.line1.setBackgroundResource(R.color.gray_1)
        }

        if (holder.adapterPosition == data.size - 1) {
            holder.itemView.contentLayout.setPadding(0, 0, 0, 0)
        } else {
            holder.itemView.contentLayout.setPadding(0, 0, 0, holder.itemView.contentLayout.dip(20))
        }
    }
}