using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawControl : MonoBehaviour
{
    public Toggle arrowToggle_;
    public Toggle textToggle_;
    public Toggle brushToggle_;
    public Toggle targetToggle_;

    public static DrawScript drawScript_;
    public void Clear()
    {
        drawScript_.Clear();

        arrowToggle_.isOn = false;
        textToggle_.isOn = false;
        brushToggle_.isOn = false;
        targetToggle_.isOn = false;
    }

    // Use this for initialization
    public void Init()
    {
        arrowToggle_.onValueChanged.AddListener(OnArrowToggleValueChanged);
        textToggle_.onValueChanged.AddListener(OnTextToggleValueChanged);
        brushToggle_.onValueChanged.AddListener(OnBrushToggleValueChanged);
        targetToggle_.onValueChanged.AddListener(OnTargetToggleValueChanged);
    }

    private void OnArrowToggleValueChanged(bool isOn)
    {
        ColorBlock cb = arrowToggle_.colors;
        if (isOn)
        {
            cb.normalColor = Color.gray;
            cb.highlightedColor = Color.gray;

            textToggle_.isOn = false;
            brushToggle_.isOn = false;
            targetToggle_.isOn = false;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.ARROW;
        }
        else
        {
            cb.normalColor = Color.white;
            cb.highlightedColor = Color.white;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
        }
        arrowToggle_.colors = cb;
    }

    private void OnTextToggleValueChanged(bool isOn)
    {
        ColorBlock cb = textToggle_.colors;
        if (isOn)
        {
            cb.normalColor = Color.gray;
            cb.highlightedColor = Color.gray;

            arrowToggle_.isOn = false;
            brushToggle_.isOn = false;
            targetToggle_.isOn = false;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.TEXT;
        }
        else
        {
            cb.normalColor = Color.white;
            cb.highlightedColor = Color.white;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
        }
        textToggle_.colors = cb;
    }

    private void OnBrushToggleValueChanged(bool isOn)
    {
        ColorBlock cb = brushToggle_.colors;
        if (isOn)
        {
            cb.normalColor = Color.gray;
            cb.highlightedColor = Color.gray;

            arrowToggle_.isOn = false;
            textToggle_.isOn = false;
            targetToggle_.isOn = false;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.PAINTBRUSH;
        }
        else
        {
            cb.normalColor = Color.white;
            cb.highlightedColor = Color.white;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
        }
        brushToggle_.colors = cb;
    }

    private void OnTargetToggleValueChanged(bool isOn)
    {
        ColorBlock cb = targetToggle_.colors;
        if (isOn)
        {
            cb.normalColor = Color.gray;
            cb.highlightedColor = Color.gray;

            arrowToggle_.isOn = false;
            textToggle_.isOn = false;
            brushToggle_.isOn = false;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.TARGET;
        }
        else
        {
            cb.normalColor = Color.white;
            cb.highlightedColor = Color.white;

            drawScript_.DrawMode = DrawScript.DRAW_MODE.NO_DRAW;
        }
        targetToggle_.colors = cb;
    }    
}
