package com.hongyegroup.cpt_parttime.mvvm

import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import com.guadou.cs_cptservices.adapter.BannerGlobalAdapter
import com.guadou.lib_baselib.base.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import javax.inject.Inject

@HiltViewModel
class PartTimeJobDetailViewModel @Inject constructor(
    private val savedStateHandle: SavedStateHandle
) : BaseViewModel() {

    var testText = MutableLiveData<String>()

    var mPartTimeJobDetail :String? = null
    private val imgUrls = mutableListOf<String>()
    val mBannerImgAdapter by lazy { BannerGlobalAdapter(imgUrls) }

    var mFragments = mutableListOf<Fragment>()

    /**
     * 请求工作详情数据
     */
    fun requestJobDetail(): LiveData<Boolean> {
        val liveData = MutableLiveData<Boolean>()

        launchOnUI {
            //开始Loading
            loadStartLoading()

            withContext(Dispatchers.IO) {
                delay(1000)
            }

            mPartTimeJobDetail = "xx"

            imgUrls.clear()
            imgUrls.add("https://img.zcool.cn/community/0160855ac4e9c6a801212573507ad7.png@1280w_1l_2o_100sh.png")
            imgUrls.add("http://img.zcool.cn/community/019241565fa3df6ac7255d2e15560a.jpg@1280w_1l_2o_100sh.jpg")
            imgUrls.add("http://img.zcool.cn/community/0158a658a2b836a801219c77059a95.png@1280w_1l_2o_100sh.png")

            liveData.postValue(true)

        }

        return liveData
    }

}