package com.lukouguoji.gjj.activity

import android.app.Activity
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.ActivityIntImpPickUpDlvBinding
import com.lukouguoji.gjj.viewModel.IntImpPickUpDLVViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.Constant
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.router.ARouterConstants
import com.lukouguoji.module_base.util.DeviceUtil

/**
 * 国际进港-提取出库
 */
@Route(path = ARouterConstants.ACTIVITY_URL_INT_IMP_PICK_UP_DLV)
class IntImpPickUpDLVActivity :
    BaseBindingActivity<ActivityIntImpPickUpDlvBinding, IntImpPickUpDLVViewModel>() {

    override fun layoutId() = R.layout.activity_int_imp_pick_up_dlv
    override fun viewModelClass() = IntImpPickUpDLVViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow(if (DeviceUtil.isPhone()) "提取出库" else "国际进港出库")
        binding.viewModel = viewModel

        // 手机形态专属：待出库 Tab 默认态 + 角标计数 + 特码字典（平板不调用，行为零变化）
        if (DeviceUtil.isPhone()) viewModel.initPhoneExtras()

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

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

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

        // 初始化代理人列表
        viewModel.initAgentList()

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

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            viewModel.onActivityResult(requestCode, resultCode, data)
        }
    }
}
