package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityIntImpMsgParseBinding
import com.lukouguoji.gjj.viewModel.IntImpMsgParseViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.impl.observe
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国际进港-电报解析（电报生成）页面
 */
@Route(path = ARouterConstants.ACTIVITY_URL_INT_IMP_MSG_PARSE)
class IntImpMsgParseActivity :
    BaseBindingActivity<ActivityIntImpMsgParseBinding, IntImpMsgParseViewModel>() {

    override fun layoutId() = R.layout.activity_int_imp_msg_parse
    override fun viewModelClass() = IntImpMsgParseViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("电报生成")
        binding.viewModel = viewModel

        // 绑定分页
        viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)

        // 设置item点击监听
        binding.rv.addOnItemClickListener(viewModel)

        // 监听刷新事件
        FlowBus.with<String>(ConstantEvent.EVENT_CHECK_CHANGED).observe(this) { viewModel.onItemCheckChanged() }

        FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).observe(this) {
            viewModel.refresh()
        }
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, IntImpMsgParseActivity::class.java)
            context.startActivity(starter)
        }
    }
}
