package com.lukouguoji.gjc.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityGjcQueryDetailsBinding
import com.lukouguoji.gjc.viewModel.GjcQueryDetailsViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CustomVP2Adapter
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国际出港查询详情页面
 */
@Route(path = ARouterConstants.ACTIVITY_URL_GJC_QUERY_DETAILS)
class GjcQueryDetailsActivity :
    BaseBindingActivity<ActivityGjcQueryDetailsBinding, GjcQueryDetailsViewModel>() {

    override fun layoutId() = R.layout.activity_gjc_query_details
    override fun viewModelClass() = GjcQueryDetailsViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际出港查询详情")
        binding.viewModel = viewModel

        // 初始化ViewModel(传入maWbId)
        viewModel.initOnCreated(intent)

        // 配置ViewPager2
        binding.vp.adapter = CustomVP2Adapter(
            viewModel.fragmentList,
            supportFragmentManager,
            lifecycle
        )
        binding.vp.isUserInputEnabled = false  // 禁用滑动
        binding.vp.offscreenPageLimit = 3      // 预加载3个Fragment

        // 监听Tab索引变化,切换Fragment
        viewModel.currentTab.observe(this) {
            binding.vp.setCurrentItem(it, false)  // false:无动画
        }

        // 加载详情数据
        viewModel.loadDetails()
    }

    companion object {
        @JvmStatic
        fun start(context: Context, maWbId: Long?) {
            val starter = Intent(context, GjcQueryDetailsActivity::class.java)
                .putExtra(Constant.Key.ID, maWbId?.toString() ?: "")
            context.startActivity(starter)
        }
    }
}
