package com.lukouguoji.gnj.page.yiku.list

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gnj.R
import com.lukouguoji.gnj.databinding.ActivityGnjYikuListBinding
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.getLifecycleOwner
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国内进港移库列表页
 */
@Route(path = ARouterConstants.ACTIVITY_URL_GNJ_YIKU_LIST)
class GnjYiKuListActivity :
    BaseBindingActivity<ActivityGnjYikuListBinding, GnjYiKuListViewModel>() {

    override fun layoutId() = R.layout.activity_gnj_yiku_list

    override fun viewModelClass() = GnjYiKuListViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国内进港移库")

        binding.viewModel = viewModel

        // 绑定分页逻辑
        viewModel.pageModel
            .bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, getLifecycleOwner())

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

        // 初始加载
        viewModel.refresh()
    }

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