package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.InputType
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityIntImpAccidentVisaEditBinding
import com.lukouguoji.gjj.viewModel.IntImpAccidentVisaEditViewModel
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.addOnItemClickListener
import com.lukouguoji.module_base.ktx.setUpperCaseAlphanumericFilter

/**
 * 国际进港-事故签证新增/编辑
 */
class IntImpAccidentVisaEditActivity :
    BaseBindingActivity<ActivityIntImpAccidentVisaEditBinding, IntImpAccidentVisaEditViewModel>() {

    override fun layoutId() = R.layout.activity_int_imp_accident_visa_edit
    override fun viewModelClass() = IntImpAccidentVisaEditViewModel::class.java

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

        // 航班号：大写字母+数字
        binding.fnoInput.et.setUpperCaseAlphanumericFilter()
        // 运单号：纯数字11位
        binding.wbNoInput.et.inputType = InputType.TYPE_CLASS_NUMBER

        viewModel.rv = binding.rv
        binding.rv.addOnItemClickListener(viewModel)
        viewModel.initOnCreate(intent)

        viewModel.pageType.observe(this) {
            val title = when (it) {
                DetailsPageType.Add -> "国际事故签证新增"
                DetailsPageType.Details -> "国际事故签证详情"
                else -> "国际事故签证修改"
            }
            setBackArrow(title)
        }
    }

    companion object {
        private const val KEY_IS_DETAIL = "is_detail"

        @JvmStatic
        fun start(context: Context, id: Long = 0, isDetail: Boolean = false) {
            context.startActivity(
                Intent(context, IntImpAccidentVisaEditActivity::class.java)
                    .putExtra(Constant.Key.ID, id)
                    .putExtra(KEY_IS_DETAIL, isDetail)
            )
        }
    }
}
