package com.cooleshow.base.widgets;

import android.content.Context;
import android.media.Image;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cooleshow.base.R;

import androidx.annotation.Nullable;

/**
 * Author by pq, Date on 2022/7/25.
 */
public class BadgeIconListView extends LinearLayout {
    public static final String STYLE_TYPE = "STYLE";
    public static final String VIDEON_TYPE = "VIDEON";
    public static final String LIVE_TYPE = "LIVE";
    public static final String MUSIC_TYPE = "MUSIC";
    private ImageView mIvVipIcon;
    private ImageView mIvStyleIcon;
    private ImageView mIvMusicSheetIcon;
    private ImageView mIvVideoCourseIcon;
    private ImageView mIvLiveIcon;

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

    public BadgeIconListView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public BadgeIconListView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOrientation(HORIZONTAL);
        LayoutInflater.from(getContext()).inflate(R.layout.view_badge_list_layout, this);
        mIvVipIcon = findViewById(R.id.iv_vip_icon);
        mIvStyleIcon = findViewById(R.id.iv_style_icon);
        mIvMusicSheetIcon = findViewById(R.id.iv_music_sheet_icon);
        mIvVideoCourseIcon = findViewById(R.id.iv_video_course_icon);
        mIvLiveIcon = findViewById(R.id.iv_live_icon);
    }

    public void setVipIcon(boolean isVip) {
        if (mIvVipIcon != null) {
            mIvVipIcon.setImageResource(isVip ? R.drawable.icon_vip_able : R.drawable.icon_vip_enable);
        }
    }

    public void setStyleIcon(boolean isStylePass) {
        if (mIvStyleIcon != null) {
            mIvStyleIcon.setImageResource(isStylePass ? R.drawable.icon_style_badge_able : R.drawable.icon_style_badge_enable);
        }
    }

    public void setMusicSheetIcon(boolean isPass) {
        if (mIvMusicSheetIcon != null) {
            mIvMusicSheetIcon.setImageResource(isPass ? R.drawable.icon_music_sheet_badge_able : R.drawable.icon_music_sheet_badge_enable);
        }
    }

    public void setLiveIcon(boolean isPass) {
        if (mIvVideoCourseIcon != null) {
            mIvVideoCourseIcon.setImageResource(isPass ? R.drawable.icon_video_course_badge_able : R.drawable.icon_video_course_badge_enable);
        }
    }


    public void setVideoCourseIcon(boolean isPass) {
        if (mIvLiveIcon != null) {
            mIvLiveIcon.setImageResource(isPass ? R.drawable.icon_live_badge_able : R.drawable.icon_live_badge_enable);
        }
    }

    public void setData(String tag) {
        if (!TextUtils.isEmpty(tag)) {
            setStyleIcon(tag.contains(STYLE_TYPE));
            setVideoCourseIcon(tag.contains(VIDEON_TYPE));
            setLiveIcon(tag.contains(LIVE_TYPE));
            setMusicSheetIcon(tag.contains(MUSIC_TYPE));
        }
    }

}
