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.R
import com.gamedog.vididin.VidiConst
import com.gamedog.vididin.databinding.BeginnerTaskItemViewBinding
import com.gamedog.vididin.main.fragments.task.Task
import com.gamedog.vididin.manager.TaskManager


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 setRewardInfo(taskReward: Task) {
        val isRewardGold = VidiConst.GOLD_IN_CONFIG == taskReward.reward_type;
        mBinding.ivRewardIcon.setImageResource(if (isRewardGold) R.mipmap.icon_glod_small else R.mipmap.icon_cash_s)
        mBinding.tvRewardNum.text = taskReward.reward_value.toString()
    }


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

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


}