package com.zj365.health.act.psychological

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseListAct
import com.xty.base.act.BaseVmAct
import com.xty.base.vm.BaseVm
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.util.CommonUtils
import com.xty.network.model.PsychologicalListBean
import com.zj365.health.BuildConfig
import com.zj365.health.adapter.psychological.PsychologicalTestMainAdapter
import com.zj365.health.databinding.ActPsychologicalTestMainBinding
import com.zj365.health.vm.PsychologicalTestMainVm

@Route(path = ARouterUrl.PSYCHOLOGICAL_TEST_LIST_ACT)
class PsychologicalTestMainAct : BaseListAct<PsychologicalTestMainVm>() {
    val binding by lazy { ActPsychologicalTestMainBinding.inflate(layoutInflater) }

    val mAdapter by lazy { PsychologicalTestMainAdapter() }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "心理测试"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }


        setRecycleRefresh(binding.mRecycle,binding.mRefresh,true)
    }

    override fun initAdapter() {

        binding.mRecycle.layoutManager = LinearLayoutManager(this)
        binding.mRecycle.adapter = mAdapter
        mAdapter.setOnItemClickListener { adapter, view, position ->
            var bean = adapter.data[position] as PsychologicalListBean.PsychologicalBean
            bundle.clear()
            bundle.putString("web_site_url","${BuildConfig.url}shareApi/H5_question/${CommonUtils.getMyUserId()}/${bean.id}/android")
            bundle.putBoolean("isShowTitle",true)
            bundle.putString("title",bean.surveyName)
            RouteManager.goAct(ARouterUrl.H5_ACT,bundle)


        }

    }

    override fun loadData() {
        mViewModel.getPsychologicalList(page)
    }

    override fun liveObserver() {
        mViewModel.psychologicalListData.observe(this){
            if (page > 1){
                mAdapter.addData(it.data.records)

            }else{
                mAdapter.setNewInstance(it.data.records)

            }
        }
    }

    override fun setLayout() = binding.root


}