package com.lukouguoji.gnc.page.distribution.home.dialog

import android.content.Context
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.gnc.R
import com.lukouguoji.gnc.databinding.DialogGncDistributionBackBinding
import com.lukouguoji.gnc.databinding.DialogGncDistributionDriverBinding
import com.lukouguoji.module_base.base.BaseDialogModel
import com.lukouguoji.module_base.ktx.formatDate
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
import dev.utils.common.DateUtils

class GncDistributionBackDialogModel(
    val carList: String,
    private val callBack: (GncDistributionBackDialogModel) -> Unit
) : BaseDialogModel<DialogGncDistributionBackBinding>(DIALOG_TYPE_CENTER) {

    val date = MutableLiveData("")
    val fno = MutableLiveData("")
    val stash = MutableLiveData("")
    val stashList = MutableLiveData<List<KeyValue>>(
        listOf(
            KeyValue("", ""),
            KeyValue("进港库区", "1"),
            KeyValue("出港库区", "2"),
            KeyValue("出港机坪", "0"),
        )
    )
    val driver = MutableLiveData("")
    val driverList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getDriverList {
            value = it
        }
    }

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

    override fun onDialogCreated(context: Context) {
        binding.model = this
    }

    fun onConfirmClick() {
        if ((date.value.isNullOrEmpty() || fno.value.isNullOrEmpty()) && stash.value.isNullOrEmpty()) {
            showToast("航班信息或库位必须填写其中一项，否则无法退回！")
            return
        }
        if (stash.value == "1" && (date.value!!.isNotEmpty() || fno.value!!.isNotEmpty())) {
            showToast("若需退回进港库位，请清空航班日期和航班号！")
            return
        }
        if (stash.value == "2" && (date.value!!.isNotEmpty() || fno.value!!.isNotEmpty())) {
            showToast("若需退回出港库位，请清空航班日期和航班号！")
            return
        }

        dismiss()
        callBack(this)
    }

}