package com.zj365.mime.act

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.getImageUrl
import com.xty.common.setImageUser
import com.zj365.mime.R
import com.zj365.mime.databinding.ActMyKeeperBinding
import com.zj365.mime.vm.MyKeeperVm


/**
 * 我的管家   我的界面入口
 */
@Route(path = ARouterUrl.MY_KEEPER)
class MyKeeperAct : BaseVmAct<MyKeeperVm>() {
    val binding by lazy { ActMyKeeperBinding.inflate(layoutInflater) }
    var fromUserId:String=""
    override fun setLayout(): View = binding.root

    override fun initData() {
        super.initData()
        isDarkBar = true
        fromUserId= intent.extras!!.getString("fromUserId")!!.toString()
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = getString(R.string.server_2)
        binding.title.mIvBack.setOnClickListener { finish() }
        mViewModel.getKeeper()
    }

    override fun liveObserver() {
        val name = this
        mViewModel.keeperLive.observe(this) {
            if (it.data.size<1){
                return@observe
            }

            binding.mDocName.text = it.data[0].realname
            if ( it.data[0].gender == 1) {
                binding.mSex.text = "男"
            } else {
                binding.mSex.text = "女"
            }
            binding.mPosition.text = it.data[0].positionName
            binding.phone.text = it.data[0].phone
            if (com.alibaba.android.arouter.utils.TextUtils.isEmpty(it.data[0].experience) ){
                binding.detail.text= "--"
            }else{
                binding.detail.text = it.data[0].experience
            }
            if (com.alibaba.android.arouter.utils.TextUtils.isEmpty( it.data[0].intro) ){
                binding.mTvLoc.text= "健康管家"
            }else{
                binding.mTvLoc.text  =  it.data[0].intro
            }
            binding.mPhoto.apply {
                setImageUser(
                    name, getImageUrl(it.data[0].avatar)
                )
            }
            binding.llLeft.setOnClickListener { itt ->
          /*      TUIConversationUtils.startAYSingleChatActivity(
                    "man_" + it.data[0].id,
                    it.data[0].realname,
                    it.data[0].avatar
                );*/
            }


            binding.llRight.setOnClickListener {itd ->
                bundle.clear()
                bundle.putSerializable("bean", it.data[0] )
                RouteManager.goAct(ARouterUrl.ONLINE_MAKE, bundle)
            }

        }
    }


}