package de.tudarmstadt.informatik.hostage.ui2.popup;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;

import de.tudarmstadt.informatik.hostage.R;

/**
 * Created by Julien on 13.02.14.
 */
public class SimplePopupItem extends AbstractPopupItem {

    public boolean selected;
	private Context context;
	private View container;

	public SimplePopupItem(Context context) {
        super(context);

	    this.context = context;
    }

    public int getLayoutId(){
        return R.layout.simple_popup_item;
    }

    public void configureItemView(View view){
        TextView titleView = (TextView) view.findViewById(R.id.title_text_view);
        RadioButton cbox = (RadioButton) view.findViewById(R.id.isSelectedButton);
        titleView.setText(this.getTitle());

        if (this.isSelected()){
            cbox.setVisibility(View.VISIBLE);
        } else {
            cbox.setVisibility(View.INVISIBLE);
        }
    }

    public void setSelected(boolean selected){
        this.selected = selected;
        if (this.getItemView() != null) this.configureItemView(this.getItemView());
    }

	private View getContainer(){
		if(container == null){
			container = this.getItemView().findViewById(R.id.popup_item_container);
		}

		return container;
	}

    public boolean isSelected(){
        return this.selected;
    }

	public void onItemDown(MotionEvent event){
		getContainer().setBackgroundColor(
				context.getResources().getColor(android.R.color.holo_blue_light));
	}

	public void onItemUp(MotionEvent event){
		getContainer().setBackgroundColor(context.getResources().getColor(android.R.color.transparent));
	}
}
