package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.gson.Gson
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityIntArrTelegramDetailsBinding
import com.lukouguoji.gjj.viewModel.IntArrTelegramDetailsViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.bean.MsgReceivePool
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 国际进港电报详情
 */
@Route(path = ARouterConstants.ACTIVITY_URL_INT_ARR_TELEGRAM_DETAILS)
class IntArrTelegramDetailsActivity : BaseBindingActivity<ActivityIntArrTelegramDetailsBinding, IntArrTelegramDetailsViewModel>() {

    override fun layoutId() = R.layout.activity_int_arr_telegram_details
    override fun viewModelClass() = IntArrTelegramDetailsViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际进港电报详情")
        binding.viewModel = viewModel

        val originalKeyListener = binding.etContent.keyListener
        viewModel.isEditable.observe(this) { editable ->
            binding.etContent.apply {
                isFocusable = editable
                isFocusableInTouchMode = editable
                isCursorVisible = editable
                keyListener = if (editable) originalKeyListener else null
            }
        }

        viewModel.initOnCreated(intent)
    }

    companion object {
        /**
         * 启动电报详情页面
         * @param context 上下文
         * @param bean 电报Bean
         * @param fid 航班ID
         */
        @JvmStatic
        fun start(context: Context, bean: MsgReceivePool, fid: String) {
            val starter = Intent(context, IntArrTelegramDetailsActivity::class.java)
                .putExtra(Constant.Key.DATA, Gson().toJson(bean))
                .putExtra("fid", fid)
            context.startActivity(starter)
        }
    }
}
