package cn.yyxx.eyuangame.core.impl.floating

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cn.yyxx.eyuangame.core.entity.FloatFeature
import cn.yyxx.support.ResUtils

/**
 * @author #Suyghur.
 * Created on 2021/06/28
 */
class FloatCenterItem constructor(context: Context, url: String, feature: FloatFeature) : LinearLayout(context) {

    private lateinit var root: View
    private lateinit var icon: ImageView
    private lateinit var desc: TextView

    init {
        initView(context, url, feature)
    }

    private fun initView(context: Context, url: String, feature: FloatFeature) {
        root = LayoutInflater.from(context).inflate(ResUtils.getResId(context, "yyxx_float_item", "layout"), null)
        icon = root.findViewById(ResUtils.getResId(context, "yyxx_iv_float_icon", "id"))
        desc = root.findViewById(ResUtils.getResId(context, "yyxx_tv_float_desc", "id"))


        when (feature) {
            FloatFeature.FEATURE_MEMBER -> {
                if (TextUtils.isEmpty(url)) {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_member_img", "drawable"))
                } else {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_member_img", "drawable"))
                }
                desc.text = ResUtils.getResString(context, "yyxx_tv_float_member_desc")
            }

            FloatFeature.FEATURE_GIF -> {
                if (TextUtils.isEmpty(url)) {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_gif_img", "drawable"))
                } else {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_gif_img", "drawable"))
                }
                desc.text = ResUtils.getResString(context, "yyxx_tv_float_gif_desc")
            }

            FloatFeature.FEATURE_GM -> {
                if (TextUtils.isEmpty(url)) {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_gm_img", "drawable"))
                } else {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_gm_img", "drawable"))
                }
                desc.text = ResUtils.getResString(context, "yyxx_tv_float_gm_desc")
            }

            FloatFeature.FEATURE_CHARGE -> {
                if (TextUtils.isEmpty(url)) {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_charge_img", "drawable"))
                } else {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_charge_img", "drawable"))
                }
                desc.text = ResUtils.getResString(context, "yyxx_tv_float_charge_desc")
            }

            FloatFeature.FEATURE_INVITE -> {
                if (TextUtils.isEmpty(url)) {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_invite_img", "drawable"))
                } else {
                    icon.setBackgroundResource(ResUtils.getResId(context, "yyxx_float_invite_img", "drawable"))
                }
                desc.text = ResUtils.getResString(context, "yyxx_tv_float_invite_desc")
            }
        }

        addView(root)
//        icon = view
    }
}