package com.zxbw.modulemain.fragment

import android.view.View
import android.widget.Adapter
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.zx.ad.AdManager
import com.zx.ad.callback.RewardVideoAdListener
import com.zxbw.modulemain.R
import com.zxbw.modulemain.adapter.CashEnterListAdapter
import com.zxbw.modulemain.adapter.CashTaskListAdapter
import com.zxbw.modulemain.uitls.TimeUtils
import com.zxhl.cms.common.base.BaseFragment
import com.zxhl.cms.utils.JumpUtils
import com.zxhl.cms.utils.OnRecycleItemClickListener
import kotlinx.android.synthetic.main.fragment_layout_cash_check.*
import me.jessyan.autosize.utils.ScreenUtils

/**
 * @author (wangXuewei)
 * @datetime 2022-06-22 14:00 GMT+8
 * @detail :现金签到
 */
class CashCheckFragment : BaseFragment(), OnRecycleItemClickListener<Any> {
    private var mCashTaskAdapter: CashTaskListAdapter? = null
    private var mCashEnterAdapter: CashEnterListAdapter? = null


    override fun layoutID(): Int = R.layout.fragment_layout_cash_check

    override fun init(view: View?) {
        var statusBarHeight = ScreenUtils.getStatusBarHeight()
        if (statusBarHeight <= 0) {
            statusBarHeight = 40
        }
        id_sys_bar_view.layoutParams.height = statusBarHeight

        mCashTaskAdapter = CashTaskListAdapter(activity, this)
        mCashEnterAdapter = CashEnterListAdapter(
            activity
        ) { view, position, data ->
            if (position < 2) {
                showToast("本次机会已失效")
            } else if (position > 2) {
                showToast("本轮尚未开始")
            } else {
                showToast("今天抽取机会已用完，明天继续获取")
            }
        }

        id_rcl_cash_enter_list.layoutManager = GridLayoutManager(activity, 5)
        id_rcl_cash_enter_list.adapter = mCashEnterAdapter
        id_rcl_cash_task_list.layoutManager = LinearLayoutManager(activity)
        id_rcl_cash_task_list.adapter = mCashTaskAdapter

        id_img_open_red_envelope.setOnClickListener {
            JumpUtils.GrabRedEnvelope()
        }
    }

    override fun onItemClick(view: View?, position: Int, data: Any?) {
        if (position == 0) {
            playRewardVideo()
        } else {
            JumpUtils.GrabRedEnvelope()
        }
    }

    private fun playRewardVideo() {
        AdManager.loadRewardAd(activity!!, object : RewardVideoAdListener {
            override fun onRewardVideoAdClose() {

            }

            override fun onRewardVideoAdReward() {

            }

            override fun onRewardVideoAdShow() {

            }

            override fun onRewardVideoAdError(errorMsg: String?) {

            }
        })

    }

}