package com.sixin.module_p.ui.gnj.xieji.details

import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.lifecycle.MutableLiveData
import com.lukouguoji.module_base.base.BaseDialogModel
import com.lukouguoji.module_base.ktx.noNull
import com.lukouguoji.module_base.ktx.verifyNullOrEmpty
import com.lukouguoji.module_base.util.DictUtils
import com.sixin.module_p.R
import com.sixin.module_p.databinding.DialogPdaGncCunFangAddBinding
import com.sixin.module_p.databinding.DialogPdaGnjXiejiDetatisAllocationBinding
import dev.utils.app.info.KeyValue

class PdaGnjXieJiDetailsAllocationDialogModel(
    val carList: String,
    val transDestNow: String,
    val callBack: (PdaGnjXieJiDetailsAllocationDialogModel) -> Unit
) :
    BaseDialogModel<DialogPdaGnjXiejiDetatisAllocationBinding>(DIALOG_TYPE_FULL) {

    val transDest = MutableLiveData("")

    val transDestList = MutableLiveData<List<KeyValue>>().apply {
        DictUtils.getTransDestList {
            var filter = it.filter { b -> !b.value.equals("3") }
            println("filter:"+filter)
            value = filter
        }
    }

    ///////////////////////////////////////////////////////////////////////////
    // 方法区
    ///////////////////////////////////////////////////////////////////////////

    override fun layoutId() = R.layout.dialog_pda_gnj_xieji_detatis_allocation

    override fun onDialogCreated(context: Context) {
        binding.model = this
        setBackArrow("转运目的地分配")
    }

    private fun setBackArrow(title: String) {
        val toolbar: Toolbar = binding.root.findViewById(com.lukouguoji.module_base.R.id.toolbar)
        val titleName: TextView = binding.root.findViewById(com.lukouguoji.module_base.R.id.title_name)
        titleName.text = title
        val toolBack: View = binding.root.findViewById(com.lukouguoji.module_base.R.id.tool_back)
        toolBack.setOnClickListener {
            dismiss()
        }
    }
    fun onAreaSelected(position: Int) {
        println("transDestNow:"+transDestNow)
        transDest.value = transDestList.value?.getOrNull(position)?.value.noNull()
    }

    fun onConfirmClick() {
        if (transDest.value.verifyNullOrEmpty("请选择目的站")) {
            return
        }
        callBack.invoke(this)
        dismiss()
    }

}