package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityGjjManifestDetailsBinding
import com.lukouguoji.gjj.holder.GjjManifestPicViewHolder
import com.lukouguoji.gjj.viewModel.GjjManifestDetailsViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.ktx.noNull

class GjjManifestDetailsActivity :
    BaseBindingActivity<ActivityGjjManifestDetailsBinding, GjjManifestDetailsViewModel>() {

    override fun layoutId() = R.layout.activity_gjj_manifest_details

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际进港舱单详情")
        viewModel.id = intent.getStringExtra(Constant.Key.ID).noNull()
        viewModel.pic = intent.getStringExtra(Constant.Key.PIC).noNull()
        viewModel.originalPic = intent.getStringExtra(Constant.Key.ORIGINAL_PIC).noNull()

        binding.viewModel = viewModel

        val picAdapter = CommonAdapter(
            this,
            R.layout.item_gjj_manifest_pic,
            GjjManifestPicViewHolder::class.java
        )
        binding.rvPic.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
        binding.rvPic.adapter = picAdapter

        viewModel.picList.observe(this) { list ->
            picAdapter.refresh(list)
        }

        viewModel.getData()
    }

    companion object {
        @JvmStatic
        fun start(context: Context, id: String, pic: String = "", originalPic: String = "") {
            val starter = Intent(context, GjjManifestDetailsActivity::class.java)
                .putExtra(Constant.Key.ID, id)
                .putExtra(Constant.Key.PIC, pic)
                .putExtra(Constant.Key.ORIGINAL_PIC, originalPic)
            context.startActivity(starter)
        }
    }
}