using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using Machinations.FromFlash.machinations.model;

namespace Machinations.GUI
{
    /// <summary>
    /// view object for artifitial player node
    /// </summary>
    class ArtifitialPlayerView : NodeView<ArtificialPlayer>
    {
        private TextBlock m_artifitialPlayerTextBlock;


        public ArtifitialPlayerView(ArtificialPlayer node):base(node)
        {
        }

        public override int Radius => 25;

        private double Side { get { return Math.Sqrt(Radius * Radius / 2); } }

        protected override void SetMainUiElementPosition(Point value)
        {
            m_uiElement.SetValue(Canvas.LeftProperty, value.X - Side / 2);
            m_uiElement.SetValue(Canvas.TopProperty, value.Y - Side / 2);
            m_artifitialPlayerTextBlock.SetValue(Canvas.LeftProperty, value.X - Side / 5);
            m_artifitialPlayerTextBlock.SetValue(Canvas.TopProperty, value.Y - Side / 2.5);
        }

        public override void InitShape()
        {
            m_uiElement = new Rectangle { Stroke = new SolidColorBrush(m_model.Color), Fill = new SolidColorBrush(Colors.Transparent), Width = Side, Height = Side };
            m_artifitialPlayerTextBlock = new TextBlock {Text = "AP", FontSize = Radius/3, Foreground = new SolidColorBrush(m_model.Color)};
        }

        public override List<UIElement> GetAllUiElements()
        {
            var basic = base.GetAllUiElements();
            basic.Add(m_artifitialPlayerTextBlock);
            return basic;
        }

        public override void ColorView(Brush brush)
        {
            ((Rectangle) m_uiElement).Stroke = brush;
            m_artifitialPlayerTextBlock.Foreground = brush;
        }
    }
}