package com.zj365.mime.act

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.BaseListAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.network.model.EnterpriseInfoHomeBean
import com.zj365.mime.R
import com.zj365.mime.adapter.EnterpriseInformationAdapter
import com.zj365.mime.databinding.ActEnterpriseInformationBinding
import com.zj365.mime.vm.EnterpriseInformationVm

/**
 * 企业资料
 */
@Route(path = ARouterUrl.ENTERPRISE_INFO)
class EnterpriseInformationAct : BaseListAct<EnterpriseInformationVm>() {
    val binding by lazy { ActEnterpriseInformationBinding.inflate(layoutInflater) }

    val mAdapter by lazy { EnterpriseInformationAdapter() }
    override fun initAdapter() {
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter = mAdapter
        setRecycleRefresh(binding.recyclerView,binding.mRefresh,true)
        binding.recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
                super.getItemOffsets(outRect, itemPosition, parent)
                outRect.bottom = 12
            }
        })

        mAdapter.addChildClickViewIds(R.id.tv_more)
        mAdapter.setOnItemChildClickListener { adapter, view, position ->
            var bean = adapter.data[position] as EnterpriseInfoHomeBean
            when(view.id){
                R.id.tv_more ->{
                    bundle.clear()
                    bundle.putInt("type",bean.type)
                    RouteManager.goAct(ARouterUrl.ENTERPRISE_TYPE_INFO,bundle)
                }
            }
        }
    }

    override fun loadData() {
        mViewModel.getEnterpriseInformationHomeList()
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "企业资料"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }
    }

    override fun liveObserver() {

        mViewModel.enterpriseInfoHomeLiveData.observe(this){
            mAdapter.setNewInstance(it.data)
        }

    }

    override fun setLayout() = binding.root
}