package com.duben.microtribe.ui.widgets.luckymonkeypanel;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.duben.microtribe.R;

/**
 * Created by jeanboy on 2017/4/20.
 */

public class PanelItemView extends FrameLayout implements ItemView {

    private View overlay;
    private TextView tv_panel_item_text;
    private ImageView iv_panel_item_pic;
    private Drawable drawable;
    private Drawable drawable2;
    private Context context;


    public PanelItemView(Context context) {
        this(context, null);
    }

    public PanelItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PanelItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context=context;

        inflate(context, R.layout.view_panel_item, this);
        overlay = findViewById(R.id.overlay);
        iv_panel_item_pic = findViewById(R.id.iv_panel_item_pic);
        tv_panel_item_text = findViewById(R.id.tv_panel_item_text);
        drawable = ContextCompat.getDrawable(getContext(), R.drawable.bg_lucky_monkey_item_overlay);
        drawable2 = ContextCompat.getDrawable(getContext(), R.drawable.bg_lucky_monkey_item_overlay2);
    }

    public void setStyle(String type, String text) {
        switch (type) {
            case "o":
                // 一年
                iv_panel_item_pic.setImageResource(R.mipmap.ic_nine_year);
                tv_panel_item_text.setTextColor(ContextCompat.getColor(
                        context,
                        R.color.color_A24240
                ));
                tv_panel_item_text.setTypeface(null, Typeface.NORMAL);
                break;
            case "f":
                // 终身
                iv_panel_item_pic.setImageResource(R.mipmap.ic_nine_all);
                tv_panel_item_text.setTextColor(ContextCompat.getColor(
                        context,
                        R.color.color_A24240
                ));

                tv_panel_item_text.setTypeface(null, Typeface.NORMAL);
                break;
            case "m":
                // 手机
                iv_panel_item_pic.setImageResource(R.mipmap.ic_nine_mobile);
                tv_panel_item_text.setTextColor(ContextCompat.getColor(
                        context,
                        R.color.apk_uninstalled
                ));
                tv_panel_item_text.setTypeface(null, Typeface.BOLD);
                break;
            default:
                // 支付
                iv_panel_item_pic.setImageResource(R.mipmap.ic_nine_vip);
                tv_panel_item_text.setTextColor(ContextCompat.getColor(
                        context,
                        R.color.color_A24240
                ));
                tv_panel_item_text.setTypeface(null, Typeface.NORMAL);
                break;
        }
        tv_panel_item_text.setText(text);
    }

    @Override
    public void setFocus(boolean isFocused) {
        if (overlay != null) {
//            overlay.setVisibility(isFocused ? INVISIBLE : VISIBLE);

            overlay.setBackground(isFocused ? drawable : drawable2);
        }
    }

}
