package com.ama.core.common.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.ama.core.common.databinding.LayoutPopItemViewBinding


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

    private lateinit var mDataItem: PopMenuView.MenuItem

    private var mBinding: LayoutPopItemViewBinding
    init {
        mBinding = LayoutPopItemViewBinding.inflate(LayoutInflater.from(context), this, true)
    }

    fun setData(dataItem: PopMenuView.MenuItem) {
        mDataItem = dataItem
        with(mBinding) {
            ivBg.setImageResource(mDataItem.iconResId)
            if (mDataItem.tvDrawable > 0) {
                tvName.setCompoundDrawablesWithIntrinsicBounds(resources.getDrawable(mDataItem.tvDrawable), null, null, null)
            }

            if (mDataItem.tvTextRes > 0) {
                tvName.text = resources.getString(mDataItem.tvTextRes)
            }
        }
    }

    fun setText(textContent: String) {
        mBinding.tvName.text = textContent
    }


}