package com.yidian.shenghuoquan.bmanagercenter.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.yidian.shenghuoquan.bmanagercenter.R
import com.yidian.shenghuoquan.bmanagercenter.constant.Constant
import com.yidian.shenghuoquan.bmanagercenter.databinding.ViewLifeAccountEnterpriseAuthInfoBinding
import com.yidian.bcommon.utils.SensitiveInfoUtil

/**
 * author: yinjiacheng
 * date: 6/15/21 4:43 PM
 * description: 商户管理中心-基本信息-生活号企业认证信息
 */
class LifeAccountEnterpriseAuthInfoView @JvmOverloads constructor(
  context: Context,
  attrs: AttributeSet? = null,
  defStyle: Int = 0
) : CardView(context, attrs, defStyle) {

  private val viewBinding by lazy {
    ViewLifeAccountEnterpriseAuthInfoBinding.bind(
      View.inflate(
        getContext(),
        R.layout.view_life_account_enterprise_auth_info,
        this
      )
    )
  }

  /**
   * 填充认证信息
   * @param authType 认证类型
   * @param auditStatus 审核状态
   * @param registrationName 公司名称
   * @param registrationCode 统一社会信用代码
   * @param realName 经营者姓名或法人姓名
   * @param idCardNo 经营者身份证号或法人身份证号
   */
  fun fillAuthInfo(
    authType: Int?,
    auditStatus: Int?,
    registrationName: String?,
    registrationCode: String?,
    realName: String?,
    idCardNo: String?
  ) {
    viewBinding.tvContentRegistrationName.text = registrationName
    viewBinding.tvContentRegistrationCode.text = registrationCode
    viewBinding.tvContentManagerInfo.text =
      String.format(
        "%s %s",
        realName,
        SensitiveInfoUtil.idCardNumEncrypt(idCardNo.toString())
      )
    when (authType) {
      Constant.TYPE_AUTH_INDIVIDUAL_BUSINESS -> {
        // 个体工商户
        viewBinding.tvAuthType.text = resources.getText(R.string.individual_business)
        viewBinding.tvTitleManagerInfo.text =
          resources.getText(R.string.operator_information)
      }
      Constant.TYPE_AUTH_COMMON_ENTERPRISE -> {
        // 普通企业
        viewBinding.tvAuthType.text = resources.getText(R.string.enterprise_auth)
        viewBinding.tvTitleManagerInfo.text = resources.getText(R.string.legal_person_info)
      }
      else -> {
        // 不区分
        viewBinding.tvAuthType.text = resources.getText(R.string.enterprise_auth)
        viewBinding.tvTitleManagerInfo.text =
          resources.getText(R.string.operator_information)
      }
    }
    when (auditStatus) {
      Constant.STATUS_AUDIT_UNDER -> {
        // 审核中
        viewBinding.tvAuditStatus.text = resources.getText(R.string.under_audit)
        viewBinding.tvAuditStatus.setBackgroundResource(R.drawable.shape_life_account_status_audit)
        viewBinding.tvAuditStatus.setTextColor(
          ContextCompat.getColor(
            context,
            R.color.color_FFF26E3D
          )
        )
      }
      Constant.STATUS_AUDIT_PASS -> {
        // 审核通过(已开通)
        viewBinding.tvAuditStatus.text = resources.getText(R.string.audit_pass)
        viewBinding.tvAuditStatus.setBackgroundResource(R.drawable.shape_life_account_status_open)
        viewBinding.tvAuditStatus.setTextColor(
          ContextCompat.getColor(
            context,
            R.color.color_FF6BB81F
          )
        )
      }
      Constant.STATUS_AUDIT_REJECT -> {
        // 审核驳回
        viewBinding.tvAuditStatus.text = resources.getText(R.string.audit_reject)
        viewBinding.tvAuditStatus.setBackgroundResource(R.drawable.shape_life_account_status_reject)
        viewBinding.tvAuditStatus.setTextColor(
          ContextCompat.getColor(
            context,
            R.color.color_FFFF3A3A
          )
        )
      }
      else -> {
        // 待审核 企业认证提交后
        viewBinding.tvAuditStatus.text = resources.getText(R.string.pending_audit)
        viewBinding.tvAuditStatus.setBackgroundResource(R.drawable.shape_life_account_status_audit)
        viewBinding.tvAuditStatus.setTextColor(
          ContextCompat.getColor(
            context,
            R.color.color_FFF26E3D
          )
        )
      }
    }
  }

}
