package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityGjjManifestAddBinding
import com.lukouguoji.gjj.viewModel.GjjManifestAddViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.DetailsPageType
import com.lukouguoji.module_base.ktx.noNull

class GjjManifestAddActivity :
    BaseBindingActivity<ActivityGjjManifestAddBinding, GjjManifestAddViewModel>() {

    override fun layoutId() = R.layout.activity_gjj_manifest_add

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        // 动态设置标题
        val title = when {
            viewModel.pageType.value == DetailsPageType.Modify -> "国际进港舱单编辑"
            else -> "国际进港舱单新增"
        }
        setBackArrow(title)

        binding.viewModel = viewModel
        viewModel.initOnCreated(intent)
    }

    companion object {
        /**
         * 新增舱单
         */
        @JvmStatic
        fun start(context: Context, fid: String = "", dep: String, dest: String) {
            val starter = Intent(context, GjjManifestAddActivity::class.java)
                .putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Add.name)
                .putExtra(Constant.Key.ID, fid)
                .putExtra(Constant.Key.DEPARTURE, dep)
                .putExtra(Constant.Key.DESTINATION, dest)
            context.startActivity(starter)
        }

        /**
         * 编辑舱单（通过Bean对象）
         */
        @JvmStatic
        fun startForEdit(context: Context, bean: com.lukouguoji.module_base.bean.GjjManifest) {
            val starter = Intent(context, GjjManifestAddActivity::class.java)
                .putExtra(Constant.Key.PAGE_TYPE, DetailsPageType.Modify.name)
                .putExtra(Constant.Key.BEAN, bean)
            context.startActivity(starter)
        }
    }
}