package com.hikapro.backpack.view.recycler;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hikapro.backpack.R;
import com.hikapro.backpack.presenter.adapters.helper.sets.ItemTouchHelperViewHolder;

/**
 * Created by tariel on 20/04/16.
 */
public class SetViewHolder extends RecyclerView.ViewHolder implements ItemTouchHelperViewHolder{

    public CardView cardView;
    public TextView textView;
    public TextView setInfo;

    private ViewGroup cardContent;
    private Drawable drawable;

    public SetViewHolder(View v) {
        super(v);
        setupViews(v);
    }

    private void setupViews(View view) {
        cardView    = (CardView) view.findViewById(R.id.card_view_set);
        textView    = (TextView) view.findViewById(R.id.set_text);
        setInfo     = (TextView) view.findViewById(R.id.set_info);
        cardContent = (ViewGroup) view.findViewById(R.id.card_content);
    }

    //GLM_add_resources_SetList
    @Override
    public void onItemClear() {
        cardContent.setBackgroundColor(cardView.getResources().getColor(R.color.colorListBackground));
        if (drawable != null) {
            cardContent.setBackground(drawable);
        }
        drawable = null;
    }

    //GLM_add_resources_SetList
    @Override
    public void onItemSelected() {
        this.drawable = cardContent.getBackground();
        cardContent.setBackgroundColor(Color.GRAY);
    }

    public void applyBackground(Context context, int setId) {

        Drawable drawable = null;

        switch (setId) {
            case 1:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_1);
                break;
            case 2:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_2);
                break;
            case 3:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_3);
                break;
            case 4:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_4);
                break;
            case 5:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_5);
                break;
            case 6:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_6);
                break;
            case 7:
                // nothing
                break;
            case 8:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_8);
                break;
            case 9:
                // nothing
                break;
            case 10:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_10);
                break;
            case 11:
                // nothing
                break;
            case 12:
                // nothing
                break;
            case 13:
                // nothing
                break;
            case 14:
                drawable = ContextCompat.getDrawable(context, R.drawable.ic_card_14);
                break;
            default:
                drawable = new ColorDrawable(ContextCompat.getColor(context, R.color.colorListBackground));

        }
        if (drawable != null)
            cardContent.setBackground(drawable);
        else
            cardContent.setBackgroundColor(cardView.getResources().getColor(R.color.colorFullTransparent));

    }
}
