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.ChangeActivity
import com.yzx.escreen.utils.setSrc
import com.yzx.escreen.utils.toTime
import kotlinx.android.synthetic.main.layout_leave_step.view.*
import org.jetbrains.anko.dip

class ChangeDialogStepAdapter(list: MutableList<ChangeActivity>) :
    BaseQuickAdapter<ChangeActivity, BaseViewHolder>(R.layout.layout_leave_step, list) {

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: ChangeActivity) {
        holder.itemView.inImg.visibility = View.GONE
        holder.itemView.visibility = View.VISIBLE
        holder.itemView.addUserTypeName.visibility = View.GONE
        holder.itemView.activityName.visibility = View.GONE
        holder.itemView.addUserName.visibility = View.VISIBLE
        when (item.is_approve) {
            0 -> {

                holder.itemView.addUserTypeName.visibility = View.GONE
                holder.itemView.addUserName.text = "${item.add_user_name}发起异动申请${
                    if (item.is_auto_pass == 1) {
                        "（直接通过）"
                    } else {
                        ""
                    }
                }"
                holder.itemView.approvalComments.visibility = View.GONE
            }
            1 -> {
                holder.itemView.addUserName.text = "班主任审批"
                holder.itemView.statusName.text = when (item.approval_status) {
                    0,1 -> "（待审批）"
                    2 -> "（通过）"
                    3 -> "（拒绝）"
                    else -> ""
                }
                holder.itemView.statusName.setTextColor(when (item.approval_status) {
                    0,1 -> Color.parseColor("#3c7ef6")
                    2 -> Color.parseColor("#07c160")
                    3 -> Color.parseColor("#ff4040")
                    else -> 0
                })
                holder.itemView.approvalComments.visibility = View.VISIBLE
                var str = "审批人：${item.add_user_name}"
                if (item.approval_comments.isNotEmpty()) {
                    str += "。${item.approval_comments}"
                }
                holder.itemView.approvalComments.text = str
            }
            2->{
                holder.itemView.addUserName.text = "提前结束"
                holder.itemView.approvalComments.visibility = View.VISIBLE
                var str = "操作人：${item.add_user_name}"
                if (item.approval_comments.isNotEmpty()) {
                    str += "。${item.approval_comments}"
                }
                holder.itemView.approvalComments.text = str
            }
            else -> {
                holder.itemView.visibility = View.GONE
            }
        }

        holder.itemView.signImg.visibility = if(item.sign_key?.isNotEmpty() == true){
            holder.itemView.signImg.setSrc(item.sign_identity,item.sign_key)
            View.VISIBLE
        }else{
            View.GONE
        }

        holder.itemView.stepTime.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))
        }
    }
}