package com.gamedog.vididin.widget


import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.view.isVisible
import com.ama.core.architecture.util.ResUtil
import com.viddin.videos.free.R
import com.viddin.videos.free.databinding.DailySignItemBinding
import com.gamedog.vididin.main.fragments.task.RewardDetail
import com.gamedog.vididin.manager.taskbeans.DailySignDayInfoBean


class DailySignItemView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {

    private lateinit var mConfigData: RewardDetail
    private lateinit var mStateData: DailySignDayInfoBean
    private var mBinding: DailySignItemBinding
    private var mIsSelected = false


    init {
        mBinding = DailySignItemBinding.inflate(LayoutInflater.from(context), this, true)
    }



    fun setData(data: RewardDetail, stateData: DailySignDayInfoBean) {
        mConfigData = data
        mStateData = stateData
        mBinding.tvGoldNum.text = "" + mConfigData.value
        mBinding.tvDayNum.text = context.getString(R.string.day) + " "+ mConfigData.day

        updateUI()
    }

    fun setLargeWidthMode() {
        mBinding.ivGold.setImageResource(R.mipmap.icon_gold_x3)
        mBinding.ivBg.setImageResource(R.mipmap.bg_biginner_daily_large)
        /*val param: ConstraintLayout.LayoutParams = mBinding.ivBg.layoutParams as ConstraintLayout.LayoutParams
        param.dimensionRatio = "H, 438:240"*/
    }

    fun setSelectState(isSelect: Boolean) {
        mIsSelected = isSelect
        updateUI()
    }

    fun getStateBean(): DailySignDayInfoBean {
        return mStateData
    }

    fun updateUI() {
        mBinding.ivDone.isVisible = mStateData.hasSigned
        mBinding.tvDayNum.isVisible = !mStateData.hasSigned
        mBinding.tvGoldNum.isVisible = true

        if (mIsSelected) {
            mBinding.rlRoot.foreground = ResUtil.getDrawable(R.drawable.bg_daily_sign_day_item)
        } else {
            mBinding.rlRoot.foreground = null
        }

        mBinding.rlRoot.alpha = if (mStateData.hasSigned) 0.5F else 1F
    }


}



