package com.lukouguoji.gjc.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityGjcAssembleWeightEditBinding
import com.lukouguoji.gjc.holder.GjcAssembleWeightEditViewHolder
import com.lukouguoji.gjc.viewModel.GjcAssembleWeightEditViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.bean.GjcUldUseBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国际出港-修改组装重量页面
 */
@Route(path = ARouterConstants.ACTIVITY_URL_GJC_ASSEMBLE_WEIGHT_EDIT)
class GjcAssembleWeightEditActivity :
    BaseBindingActivity<ActivityGjcAssembleWeightEditBinding, GjcAssembleWeightEditViewModel>() {

    private lateinit var adapter: CommonAdapter

    override fun layoutId() = R.layout.activity_gjc_assemble_weight_edit

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际出港修改组装重量")

        binding.viewModel = viewModel

        // 初始化RecyclerView
        val layoutManager = LinearLayoutManager(this)
        binding.recyclerView.layoutManager = layoutManager

        // 添加分割线
        val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
        binding.recyclerView.addItemDecoration(divider)

        adapter = CommonAdapter(
            this,
            R.layout.item_gjc_assemble_weight_edit,
            GjcAssembleWeightEditViewHolder::class.java
        )
        binding.recyclerView.adapter = adapter

        // 监听数据变化更新RecyclerView
        viewModel.waybillList.observe(this) { records ->
            adapter.refresh(records)
        }

        // 初始化数据
        viewModel.initOnCreated(intent)
    }

    companion object {
        @JvmStatic
        fun start(context: Context, bean: GjcUldUseBean) {
            val starter = Intent(context, GjcAssembleWeightEditActivity::class.java)
                .putExtra(Constant.Key.BEAN, bean)
            context.startActivity(starter)
        }
    }
}
