package com.abbidot.tracker.adapter

import android.graphics.Typeface
import android.util.TypedValue
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.MenuTxtBean
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.constant.MultipleEntity
import com.abbidot.tracker.widget.TypefaceTextView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder


/**
 *Created  by .yzq on 2024/8/12/012.
 * @link
 * @description:
 */
class HelpTextImageTypeAdapter(list: MutableList<MenuTxtBean>?) :
    BaseMultiItemQuickAdapter<MenuTxtBean, BaseViewHolder>(list) {

    init {
        //加粗的标题文字
        addItemType(MultipleEntity.TEXT, R.layout.layout_help_title1)
        //只是图片的
        addItemType(MultipleEntity.IMG, R.layout.layout_help_image)
        //显示不同颜色的文字
        addItemType(MultipleEntity.IMG_TEXT, R.layout.layout_help_title1)
        //显示16sp大小的文字内容
        addItemType(MultipleEntity.IMG_IMG, R.layout.layout_help_title1)
        //显示14sp大小的文字内容
        addItemType(MultipleEntity.IMG_TEXT_IMG, R.layout.layout_help_title2)
        //显示多大字体，是否粗体,字体颜色
        addItemType(MultipleEntity.TEXT_TEXT_IMG, R.layout.layout_help_title2)
    }

    override fun convert(holder: BaseViewHolder, item: MenuTxtBean) {
//        val position = getItemPosition(item)
        when (item.itemType) {
            MultipleEntity.TEXT -> {
                // 创建一个Typeface对象，指定加粗字体
                val typefaceBold = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
                holder.getView<TypefaceTextView>(R.id.tv_help_title_one).apply {
                    text = item.menuName
                    typeface = typefaceBold
                }
                holder.itemView.setPadding(0, AppUtils.dpToPx(8), 0, 0)
            }

            MultipleEntity.IMG_TEXT -> holder.getView<TypefaceTextView>(R.id.tv_help_title_one)
                .apply {
                    text = item.menuName
                    setTextColor(ContextCompat.getColor(context, item.colorRedId))
                }

            MultipleEntity.IMG -> {
                holder.getView<AppCompatImageView>(R.id.iv_help_image_type)
                    .setImageResource(item.imageId)
            }

            MultipleEntity.IMG_IMG -> {
                holder.getView<TypefaceTextView>(R.id.tv_help_title_one).text = item.menuName
                holder.itemView.setPadding(0, AppUtils.dpToPx(20), 0, 0)
            }

            MultipleEntity.IMG_TEXT_IMG -> {
                holder.getView<TypefaceTextView>(R.id.tv_help_title_two).text = item.menuName
                holder.itemView.setPadding(0, AppUtils.dpToPx(14), 0, 0)
            }

            MultipleEntity.TEXT_TEXT_IMG -> {
                holder.getView<TypefaceTextView>(R.id.tv_help_title_two).apply {
                    //是否粗体
                    val typefaceBold =
                        if (item.isSwitch) Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
                        else Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)
                    typeface = typefaceBold
                    text = item.menuName
                    setTextSize(TypedValue.COMPLEX_UNIT_SP, item.state.toFloat())

                    val tColor = if (item.colorRedId == ConstantInt.Type0) R.color.data_black_color
                    else item.colorRedId
                    setTextColor(ContextCompat.getColor(context, tColor))
                }
//                holder.itemView.setPadding(0, AppUtils.dpToPx(14), 0, 0)
            }
        }
    }

}