package com.zj365.health.act.psychological

import android.graphics.Rect
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.base.vm.BaseVm
import com.xty.common.arouter.ARouterUrl
import com.zj365.health.adapter.psychological.PsychologicalRecommendAdapter
import com.zj365.health.databinding.ActPsychologicalResultBinding
import com.zj365.health.vm.PsychologicalResultVm
@Route(path = ARouterUrl.PSYCHOLOGICAL_RESULT_ACT)
class PsychologicalResultAct: BaseVmAct<PsychologicalResultVm>() {
    val binding by lazy { ActPsychologicalResultBinding.inflate(layoutInflater) }

    val mAdapter by lazy { PsychologicalRecommendAdapter() }

    var answerId:Long = 0

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text ="性格测试总结"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }
        answerId = intent.extras!!.getLong("answerId",0)

        mViewModel.getPsychologicalResult(answerId)

        binding.recycler.layoutManager = LinearLayoutManager(this)
        binding.recycler.adapter = mAdapter
        binding.recycler.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
                super.getItemOffsets(outRect, itemPosition, parent)
                outRect.bottom = 12

            }
        })
    }

    override fun liveObserver() {

        mViewModel.psychologicalResultData.observe(this){
            binding.tvSummaryContent.text = "${it.data.conclusionText}"

            mAdapter.setNewInstance(it.data.recList)

        }
    }

    override fun setLayout() = binding.root
}