package com.zswc.creativity.vmodel

import android.app.Activity
import android.app.Application
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.ysnows.base.base.BRepository
import com.ysnows.base.base.BViewModel
import com.zswc.creativity.model.TibetaDetails
import com.zswc.creativity.utils.PopuBuyUtils
import com.zswc.creativity.utils.PopuDownWxUtils
import com.zswc.creativity.utils.PopuShareWxUtils
import com.zswc.creativity.utils.net.NetEngine
import kotlinx.coroutines.launch

class TibetanDetailsVModel(application: Application) : BViewModel<BRepository>(application)  {
    var ll: LinearLayout? = null

    var data= MutableLiveData<TibetaDetails>()
    //倒计时
    var isUp = true
    var time = MutableLiveData<String>()


    fun toClose(){

        (repository().context as Activity).finish()
    }

    fun getInfo(id:String){
        viewModelScope.launch {
            var it=repository().lreq { NetEngine.service.CollectionDetail(id) }
            if(it.ok()){

                data.value=it.data

            }

        }
    }

    fun  toBuy(view :View){//支付弹框
        PopuBuyUtils.show(repository().context!!, data.value?.cover,data.value?.name,data.value?.price, view)
    }

    fun getUrl() {


//        viewModelScope.launch {
//            var it = repository().lreq { NetEngine.service.getAppCode(k_id, "1") }
//            if (it.ok()) {
//
//                toShareCode(it.datas?.appcode)
//
//            }
//        }

        //测试
        toShareCode(data.value?.cover)
    }


    fun toShareCode(shareUrl: String?) {
        if (TextUtils.isEmpty(shareUrl)) {
            return
        }

        PopuDownWxUtils.show(repository().context!!, shareUrl!!,data.value?.name,data.value?.auth_name,data.value?.id, ll!!,repository().context!!.contentResolver)

       // PopuShareWxUtils.show(repository().context!!, shareUrl!!, ll!!,repository().context!!.contentResolver)
    }


}
