package com.yidian.shenghuoquan.newscontent.personnel.ui

import android.content.Intent
import android.os.Bundle
import androidx.core.content.ContextCompat
import com.yidian.bcommon.XRouterPathConstants
import com.yidian.bcommon.XRouterPathConstants.Companion.PERSONAL_STAFF_INFO
import com.yidian.bcommon.base.BaseActivity
import com.yidian.bcommon.extensions.clickAntiShake
import com.yidian.shenghuoquan.newscontent.R
import com.yidian.shenghuoquan.newscontent.databinding.ActivityStaffInfoBinding
import com.yidian.shenghuoquan.newscontent.personnel.bean.AccountUser
import com.yidian.shenghuoquan.newscontent.utils.SensitiveInfoUtil
import com.yidian.xpage.XPageManager

/**
 *  员工信息
 */
class StaffInfoActivity : BaseActivity<ActivityStaffInfoBinding>() {

  private var staffInfo: AccountUser? = null

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

  override fun getXPageName(): String {
    return PERSONAL_STAFF_INFO
  }

  override fun init(savedInstanceState: Bundle?) {
    super.init(savedInstanceState)
    initTitle()
    getIntentData(intent)
  }

  private fun initTitle() {
    viewBind.include.tvTitle.text = "员工信息"
    viewBind.include.ivBack.clickAntiShake {
      XPageManager.pop(null)
    }
    viewBind.include.tvMenu.text = "管理"
    viewBind.include.tvMenu.setTextColor(ContextCompat.getColor(this, R.color.color_1852F1))
    viewBind.include.tvMenu.clickAntiShake {
      val hashMap = HashMap<String, Any?>()
      hashMap["staffInfo"] = staffInfo
      XPageManager.push(XRouterPathConstants.PERSONAL_STAFF_MANAGE, hashMap)
    }

  }

  private fun getIntentData(intent: Intent?) {
    val paramsMap = intent?.getSerializableExtra(XRouterPathConstants.ParamsKey)
    if (paramsMap != null) {
      paramsMap as HashMap<*, *>
      staffInfo = paramsMap["staffInfo"] as AccountUser
      viewBind.tvUserName.text = staffInfo?.nickName
      viewBind.tvLoginAccount.text = staffInfo?.mobile?.let {
        SensitiveInfoUtil.mobileEncrypt(it)
      }
      val sb = StringBuilder()
      staffInfo?.roleList?.forEachIndexed { index, s ->
        sb.append(s)
        if (index < staffInfo!!.roleList!!.size - 1) {
          sb.append("｜")
        }
      }
      viewBind.tvCurrentRole.text = sb
    }
  }
}
