package com.gamedog.vididin.main.fragments.task.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.ama.core.architecture.util.ResUtil
import com.ama.core.architecture.util.setOnClickBatch
import com.gamedog.vididin.databinding.DailyTaskItemViewBinding


class DailyTaskItemView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
    private lateinit var mAction: () -> Unit
    private lateinit var mBinding: DailyTaskItemViewBinding


    init {
        mBinding = DailyTaskItemViewBinding.inflate(LayoutInflater.from(context), this, true)
        mBinding.run {
            setOnClickBatch(tvAction) {
                when (this) {
                    tvAction-> {
                        mAction.invoke()
                    }
                }
            }
        }
    }



    fun initUI(titleIconRes: Int, titleRes: Int, videosNum: Int, actionRes: Int) {
        mBinding.ivItemIcon.setImageResource(titleIconRes)
        mBinding.tvItemTitle.text = String.format(ResUtil.getString(titleRes), videosNum)
        mBinding.tvAction.setText(actionRes)
    }

    fun setProgressText(progress: Int, progressText: String) {
        mBinding.tvItemProgress.text = progressText
        mBinding.itemProgress.setProgress(progress)
    }

    fun setRewardInfo(rewardIconRes: Int, rewardNum: Int) {
        mBinding.tvRewardNum.text = "" + rewardNum
        mBinding.ivRewardIcon.setImageResource(rewardIconRes)
    }

    fun setActionFun(action: ()->Unit) {
        mAction = action
    }




}