package com.yidian.shenghuoquan.newscontent.ui.auth

import android.os.Bundle
import android.view.View
import com.yidian.common.XRouterPathConstants
import com.yidian.common.base.BaseActivity
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.constant.Constant
import com.yidian.shenghuoquan.newscontent.databinding.ActivityLifeAccountEnterpriseAuthCompleteBinding
import com.yidian.shenghuoquan.newscontent.utils.SensitiveInfoUtil
import com.yidian.xpage.XPageManager

/**
 * author: yinjiacheng
 * date: 6/16/21 11:36 PM
 * description: 生活号企业认证提交成功页面
 */
class LifeAccountEnterpriseAuthCompleteActivity :
  BaseActivity<ActivityLifeAccountEnterpriseAuthCompleteBinding>(), View.OnClickListener {

  companion object {
    const val REGISTRATION_NAME = "registrationName"
    const val REGISTRATION_CODE = "registrationCode"
    const val ID_CARD_NAME = "idCardName"
    const val ID_CARD_NUM = "idCardNum"
    const val EXTRA_LIFE_ACCOUNT_ID = "life_account_id"
  }

  /**
   * 由企业认证页传递的参数
   */
  private val params by lazy {
    intent.getSerializableExtra(XRouterPathConstants.ParamsKey)?.let {
      it as HashMap<*, *>
    }
  }

  override fun createViewBinding(): ActivityLifeAccountEnterpriseAuthCompleteBinding {
    return ActivityLifeAccountEnterpriseAuthCompleteBinding.inflate(layoutInflater)
  }

  override fun getXPageName(): String {
    return XRouterPathConstants.LIFE_ACCOUNT_ENTERPRISE_AUTH_COMPLETE
  }

  override fun init(savedInstanceState: Bundle?) {
    super.init(savedInstanceState)
    initView()
    initListener()
    initData()
  }

  private fun initView() {
    // 此页面不可返回
    viewBind.bvTopBar.setBackVisibility(false)
  }

  private fun initListener() {
    viewBind.tvCreateLifeAccount.setOnClickListener(this)
  }

  private fun initData() {
    viewBind.ivEnterpriseAuthInfo.fillAuthInfo(
      -1,
      Constant.STATUS_AUDIT_UNDER,
      params?.get(REGISTRATION_NAME)?.let { it as String },
      params?.get(REGISTRATION_CODE)
        ?.let { it as String },
      params?.get(ID_CARD_NAME)?.let { it as String },
      SensitiveInfoUtil.idCardNumEncrypt(params?.get(ID_CARD_NUM)?.let { it as String } ?: "")
    )
  }

  override fun onClick(v: View?) {
    if (v?.id == R.id.tv_create_life_account) {
      // 跳转创建生活号页面
      XPageManager.push(
        XRouterPathConstants.LIFE_ACCOUNT_CREATE,
        hashMapOf(
          Pair(
            LifeAccountCreateActivity.LIFE_ACCOUNT_ID,
            params?.get(EXTRA_LIFE_ACCOUNT_ID)
          )
        )
      )
    }
  }
}
