package com.dlc.chemical.ui.widget

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.dlc.chemical.R
import com.dlc.chemical.databinding.WidgetPersonAuthBinding

/**
 * info
 *
 * @author ReiChin_
 */
class PersonAuthView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) :
        ConstraintLayout(context, attrs, defStyleAttr) {

    private val viewBinding =
            WidgetPersonAuthBinding.inflate(LayoutInflater.from(context), this)

    init {
        resetStatus()
    }

    fun resetStatus() {
        viewBinding.pName.text = "姓名："
        viewBinding.pPhone.text = "电话："
        viewBinding.status.text = "请刷卡"

        viewBinding.pName.setTextColor(Color.parseColor("#333333"))
        viewBinding.pPhone.setTextColor(Color.parseColor("#333333"))
        viewBinding.status.setTextColor(Color.parseColor("#333333"))
        viewBinding.cardImg.setImageResource(R.mipmap.icon_wsk)
        viewBinding.cardImg.setBackgroundResource(R.drawable.shape_rect_round_6_solid_d1)
        setBackgroundResource(R.drawable.shape_rect_round_6_solid_f5)
    }

    @SuppressLint("SetTextI18n")
    fun updateStatus(pName: String?, pPhone: String?) {
        viewBinding.pName.text = "姓名：${pName ?: ""}"
        viewBinding.pPhone.text = "电话：${pPhone ?: ""}"
        viewBinding.status.text = "已刷卡"

        viewBinding.pName.setTextColor(Color.WHITE)
        viewBinding.pPhone.setTextColor(Color.WHITE)
        viewBinding.status.setTextColor(Color.WHITE)
        viewBinding.cardImg.setImageResource(R.mipmap.icon_ysk)
        viewBinding.cardImg.setBackgroundResource(R.drawable.shape_rect_round_6_solid_0a7ffa)
        setBackgroundResource(R.drawable.shape_rect_round_6_solid_0d8afa)
    }

    fun isAuthSuccess(): Boolean {
        return "已刷卡" == viewBinding.status.text
    }

}