package com.sixin.module_p.ui.enter.home

import android.content.Context
import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.alibaba.fastjson.JSONArray
import com.lukouguoji.module_base.base.BaseDialogModel
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.formatDate
import com.lukouguoji.module_base.ktx.launchCollect
import com.lukouguoji.module_base.ktx.toInt
import com.lukouguoji.module_base.ktx.toJson
import com.lukouguoji.module_base.ktx.toRequestBody
import com.lukouguoji.module_base.util.Common
import com.lukouguoji.module_base.util.DictUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.enums.PopupPosition
import com.sixin.module_p.R
import com.sixin.module_p.databinding.DialogPdaCunfangFilterBinding
import com.sixin.module_p.databinding.DialogPdaDaishouyunFilterBinding
import com.sixin.module_p.databinding.FragmentPdaHomeConfigBinding
import dev.DevUtils
import dev.utils.app.info.KeyValue
import dev.utils.common.DateUtils
import java.util.Calendar

class HomeConfigDialogModel(
    private val callBack: () -> Unit
) : BaseDialogModel<FragmentPdaHomeConfigBinding>(DIALOG_TYPE_DRAWER) {


    val filterContent = MutableLiveData("")

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

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

    override fun onDialogCreated(context: Context) {
        binding.model = this
        launchCollect({
            NetApply.api.getFltFilter()
        }) {
            onSuccess = {
                filterContent.value = it.data?.filterContent
            }
        }
    }


    override fun onBuild(builder: XPopup.Builder) {
        builder.popupPosition(PopupPosition.Right)
    }


    fun onResetClick() {
        filterContent.value = ""
        /*callBack.invoke()
        dismiss()*/
    }

    fun onConfirmClick() {
        launchCollect({
            NetApply.api.addOrModifyFltFilter(
                mapOf(
                "filterContent" to filterContent.value,
            ).toRequestBody()
            )
        }) {
            onSuccess = {
                callBack.invoke()
                dismiss()
            }
        }
    }
}