using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Machinations.FromFlash.graph;
using Machinations.UserComponents;

namespace Machinations.GUI
{
    /// <summary>
    /// ancestor of inoutinnerView and inOutOuterView+
    /// </summary>
    public abstract class InOutView : PointObjectView//, IObjectView<T> where T : InOutBase
    {
        protected readonly InOutBase m_input;

        protected InOutView(InOutBase input)
        {
            m_input = input;
            Border border = new Border
            {
                Width = Radius,
                Height = Radius,
                Background = Brushes.Transparent,
                BorderBrush = new SolidColorBrush(Colors.Black),
                BorderThickness = new Thickness(4)
            };
            m_uiElement = border;
            m_textBlock.Text = m_input.Name;
        }

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

        public override string Label
        {
            get { return m_input.Name; }
            set
            {
                if (m_input.Name != value)
                {
                    m_input.Name = value;
                    base.Label = value;
                }
            }
        }

        public override void AddConnection(IConnectionView connectionView, bool start, bool withModel = true)
        {
            if (withModel)
                connectionView.Model.ConnectToElement(m_input, start);
            base.AddConnection(connectionView, start);
        }


        public override void ColorView(Brush brush)
        {
            ((Border)m_uiElement).BorderBrush = brush;
        }

        public override GraphElement GetModelElement()
        {
            return m_input;
        }

        public override void Dispose()
        {
            m_input.Dispose();
            base.Dispose();
        }
    }
}
