package com.lukouguoji.gjc.dialog

import android.content.Context
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.DialogIntExpLoadResetBinding
import com.lukouguoji.module_base.base.BaseDialogModel
import com.lukouguoji.module_base.ktx.verifyNullOrEmpty
import dev.utils.app.info.KeyValue

/**
 * 国际出港装载 - 状态重置对话框
 */
class IntExpLoadResetDialogModel(
    private val callback: (IntExpLoadResetDialogModel) -> Unit
) : BaseDialogModel<DialogIntExpLoadResetBinding>(DIALOG_TYPE_CENTER) {

    val resetStatusList = MutableLiveData<List<KeyValue>>()
    val selectedResetStatus = MutableLiveData("")
    var resetStatusCode: String? = null

    override fun layoutId(): Int = R.layout.dialog_int_exp_load_reset

    override fun onDialogCreated(context: Context) {
        binding.model = this
        initResetStatusList()
        selectedResetStatus.observeForever { value ->
            resetStatusCode = when (value) {
                "01" -> "01"
                "02" -> null
                else -> null
            }
        }
    }

    private fun initResetStatusList() {
        resetStatusList.value = listOf(
            KeyValue("正常", "01"),
            KeyValue("未申报", "02")
        )
    }

    fun onSaveClick() {
        if (selectedResetStatus.value.verifyNullOrEmpty("请选择重置状态")) return
        dismiss()
        callback(this)
    }
}
