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.setOnClickBatch
import com.gamedog.vididin.databinding.BeginnerTaskItemViewBinding


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


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


    fun initUI(titleIconRes: Int, titleRes: Int, desRes: Int, actionRes: Int) {
        mBinding.ivItemIcon.setImageResource(titleIconRes)
        mBinding.tvItemTitle.setText(titleRes)
        mBinding.tvAction.setText(actionRes)
        mBinding.tvItemDescrible.setText(desRes)
    }


    fun setRewardNum(rewardNum: String) {
        mBinding.tvRewardNum.text = rewardNum
    }

    fun setRewardIcon(iconRes: Int) {
        mBinding.ivRewardIcon.setImageResource(iconRes)
    }


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

    fun setRewardTextStyle(textSize: Int, color: Int) {
        mBinding.tvRewardNum.textSize = textSize.toFloat()
        mBinding.tvRewardNum.setTextColor(color)
    }


}