package de.frajul.endlessroll.views;

import android.graphics.Typeface;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import de.frajul.endlessroll.R;
import de.frajul.endlessroll.entities.shapes.EmptyTask;
import de.frajul.endlessroll.entities.shapes.Task;
import de.frajul.endlessroll.main.GameActivity;

/**
 * Created by Julian on 30.10.2017.
 */

public class ShapeInspectorCheckbox {

    private GameActivity gameActivity;
    private View layout;
    private ImageView image;
    private TextView textView;

    public ShapeInspectorCheckbox(GameActivity gameActivity, Typeface typeface, View layout) {
        this.gameActivity = gameActivity;
        this.layout = layout;
        image = (ImageView) layout.findViewById(R.id.shape_inspector_check_box_image);
        textView = (TextView) layout.findViewById(R.id.shape_inspector_check_box_text);
        textView.setTypeface(typeface);
    }

    public void updateForTask(Task task) {
        boolean taskNotEmpty = !(task instanceof EmptyTask);
        setVisible(taskNotEmpty);
        if (taskNotEmpty) {
            textView.setText(task.toString(gameActivity, gameActivity.getLevelManager()));
            setChecked(task.isConditionFulfilled());
        }
    }

    private void setChecked(boolean checked) {
        int drawableId = checked ? R.drawable.guis_checkbox_checked : R.drawable.guis_checkbox_unchecked;
        image.setBackgroundDrawable(gameActivity.getResources().getDrawable(drawableId));
    }

    private void setVisible(boolean visible) {
        layout.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
    }

}
