using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Machinations.FromFlash.machinations.model;

namespace Machinations.GUI
{
    /// <summary>
    /// visualisation of delay
    /// </summary>
    public class DelayView : NodeView<Delay>
    {
        private TextBlock m_waitTextBlock;
        private const string Hourglass = "\u231B";

        public DelayView(Delay node) : base(node)
        {
            m_model.Changed += ModelOnChanged;
        }

        public override int Radius { get { return 25; } }

        public override void InitShape()
        {
            m_waitTextBlock = new TextBlock
            {
                Text = DecideText(),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                TextAlignment = TextAlignment.Center
            };
            Border border = new Border
            {
                CornerRadius = new CornerRadius(Radius),
                Width = Radius,
                Height = Radius,
                Background = Brushes.Transparent,
                BorderBrush = new SolidColorBrush(m_model.Color),
                BorderThickness = new Thickness(m_model.Thickness)
            };
            border.Child = m_waitTextBlock;
            m_uiElement = border;
        }


        private void ModelOnChanged(object sender, EventArgs eventArgs)
        {
            m_waitTextBlock.Text = DecideText();
        }

        private string DecideText()
        {
            if (Model.DelayType == Delay.TypeNormal) return Hourglass;
            return Hourglass + Hourglass;
        }
    }
}
