using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media;


namespace VisualPathFinder
{
    public class Tile: System.Windows.Controls.Grid
    {
        CellType state;

        #region Public Constants
        public enum CellType
        {
            HIGHLIGHT,
            EMPTY,
            WALL,
            ENDPOINT,
            NON_ENDPOINT,
            FINISH,
            START
        }
        #endregion

        public Tile():base()
        {
            this.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Tile_MouseLeftButtonDown);
            this.MouseRightButtonDown += new System.Windows.Input.MouseButtonEventHandler(Tile_MouseRightButtonDown);
            this.Margin = new System.Windows.Thickness(2);
            this.MinHeight = 12;
            this.MinWidth = 12;
        }

        void Tile_MouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (state == CellType.START)
            {
                State = CellType.FINISH;
            }
            else if (state == CellType.FINISH)
            {
                State = CellType.EMPTY;
            }
            else
            {
                State = CellType.START;
            }
        }

        void Tile_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (state == Tile.CellType.EMPTY)
            {
                State = Tile.CellType.WALL;
            }
            else
            {
                State = Tile.CellType.EMPTY;
            }
        }

        public CellType State
        {
            get
            {
                return state;
            }
            set
            {
                state = value;
                switch (state)
                {
                    case Tile.CellType.HIGHLIGHT:
                        this.Background = new SolidColorBrush(Colors.Turquoise);
                        break;
                    case Tile.CellType.EMPTY:
                        this.Background = new SolidColorBrush(Colors.White);
                        break;
                    case Tile.CellType.WALL:
                        this.Background = new SolidColorBrush(Colors.Black);
                        break;
                    case Tile.CellType.NON_ENDPOINT:
                        this.Background = new SolidColorBrush(Colors.DarkBlue);
                        break;
                    case Tile.CellType.START:
                        this.Background = new SolidColorBrush(Colors.Green);
                        break;
                    case Tile.CellType.FINISH:
                        this.Background = new SolidColorBrush(Colors.Red);
                        break;
                    default:
                        this.Background = new SolidColorBrush(Colors.Violet);
                        break;
                }
            }
        }
    }
}
