package com.lukouguoji.aerologic.page.gnj.manifest.add

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.InputType
import com.lukouguoji.aerologic.R
import com.lukouguoji.aerologic.databinding.ActivityGnjManifestAddBinding
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.DetailsPageType
import dev.utils.app.EditTextUtils

class GnjManifestAddActivity :
    BaseBindingActivity<ActivityGnjManifestAddBinding, GnjManifestAddViewModel>() {
    override fun layoutId() = R.layout.activity_gnj_manifest_add

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        viewModel.initOnCreate(intent)

        setBackArrow("国内进港舱单${viewModel.pageType.value?.title}")

        binding.viewModel = viewModel

        EditTextUtils.setInputType(binding.pdlWaybill.et, InputType.TYPE_CLASS_NUMBER)

        viewModel.dataBean.observe(this) {
            if (viewModel.pageType.value == DetailsPageType.Add) {
                it.fid = intent.getStringExtra(Constant.Key.FLIGHT) ?: ""
                it.fdep = intent.getStringExtra(Constant.Key.DEPARTURE) ?: ""
                it.fdest = intent.getStringExtra(Constant.Key.DESTINATION) ?: ""
            }
        }
    }

    companion object {
        @JvmStatic
        fun start(
            context: Context,
            id: String = "",
            modify: Boolean = false,
            fid: String = "",
            dep: String = "",
            dest: String = "",
        ) {
            val starter = Intent(context, GnjManifestAddActivity::class.java)
                .putExtra(Constant.Key.ID, id)
                .putExtra(Constant.Key.FLIGHT, fid)
                .putExtra(Constant.Key.DEPARTURE, dep)
                .putExtra(Constant.Key.DESTINATION, dest)
                .putExtra(Constant.Key.MODIFY, modify)
            context.startActivity(starter)
        }
    }

}