package com.hongyegroup.cpt_auths.mvvm.vm

import android.app.Activity
import android.view.View
import androidx.hilt.lifecycle.ViewModelInject
import androidx.lifecycle.MutableLiveData
import com.guadou.lib_baselib.base.vm.BaseViewModel
import com.guadou.lib_baselib.ext.dp2px
import com.hongyegroup.cpt_auths.widget.CountyCodePopup
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.enums.PopupPosition

class PensonalLoginViewModel @ViewModelInject constructor(

) : BaseViewModel() {

    private val countyCodes = listOf("+1", "+44", "+60", "+61", "+63", "+65", "+66", "+84", "+86", "+852")

    var mMobileCodeLiveData: MutableLiveData<String> = MutableLiveData()

    init {
        mMobileCodeLiveData.value = "+65"
    }

    /**
     * 下拉选选择国家区号
     */
    fun showCountryCodePopup(view: View, activity: Activity) {

        XPopup.Builder(activity)
            .hasShadowBg(false)
            .isCenterHorizontal(true) //是否与目标水平居中对齐
            .offsetY(-5)
            .popupPosition(PopupPosition.Bottom) //手动指定弹窗的位置
            .atView(view) // 依附于所点击的View，内部会自动判断在上方或者下方显示
            .asCustom(CountyCodePopup(activity, view, dp2px(300f), countyCodes) { _, text ->
                mMobileCodeLiveData.value = text
            })
            .show()

    }


}