package com.lukouguoji.gnc.page.distribution.handover

import android.content.Context
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.databinding.DialogGncDistributionHandoverModifyBinding
import com.lukouguoji.module_base.base.BaseDialogModel
import com.lukouguoji.module_base.bean.FlightBean
import com.lukouguoji.module_base.ktx.showToast
import com.lukouguoji.module_base.ktx.verifyNullOrEmpty
import com.lukouguoji.module_base.util.DictUtils
import dev.utils.app.info.KeyValue

class GncDistributionHandoverModifyDialogModel(
    val driverList: List<KeyValue>,
    val bean: FlightBean? = null,
    private val callBack: (GncDistributionHandoverModifyDialogModel) -> Unit
) : BaseDialogModel<DialogGncDistributionHandoverModifyBinding>(DIALOG_TYPE_CENTER) {

    // 司机
    val driver = MutableLiveData("")

    // 业务袋
    val check1 = MutableLiveData(true)

    // 特货通知单
    val check2 = MutableLiveData(false)

    override fun layoutId(): Int {
        return R.layout.dialog_gnc_distribution_handover_modify
    }

    override fun onDialogCreated(context: Context) {
        binding.model = this
        bean?.let {
            when (bean.fileType) {
                "1" -> {
                    check1.value = true
                }

                "2" -> {
                    check2.value = true
                }

                "3" -> {
                    check1.value = true
                    check2.value = true
                }

                else -> {}
            }
            driver.value = bean.driver
        }
    }

    fun onConfirmClick() {
        if ( driver.value.isNullOrEmpty()){
            showToast("请选择司机")
            return
        }
        if ((getFileType().verifyNullOrEmpty("请选择单证类型"))
        ) {
            return
        }
        dismiss()
        callBack(this)
    }

    fun getFileType(): String {
        return when {
            check1.value == true && check2.value == true -> "3"
            check1.value == true -> "1"
            check2.value == true -> "2"
            else -> ""
        }
    }
}