using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
using CtrEditor.ObjetosSim;
using CtrEditor.FuncionesBase;

namespace CtrEditor.ObjetosSim.HydraulicComponents
{
    /// <summary>
    /// Interaction logic for ucHydPipe.xaml
    /// </summary>
    public partial class ucHydPipe : UserControl, IDataContainer
    {
        public osBase? Datos { get; set; }
        public int zIndex_fromFrames { get; set; } = 0;
        
        private bool _isHighlighted = false;
        
        public ucHydPipe()
        {
            InitializeComponent();
            this.Loaded += OnLoaded;
            this.Unloaded += OnUnloaded;
            DataContextChanged += OnDataContextChanged;
        }
        
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            Datos?.ucLoaded();
        }
        
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            Datos?.ucUnLoaded();
        }
        
        private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (DataContext is osHydPipe pipe)
            {
                Datos = pipe;
            }
        }
        
        #region IDataContainer Implementation
        
        public void Highlight(bool state)
        {
            _isHighlighted = state;
            
            if (state)
            {
                rectPipe.Stroke = new SolidColorBrush(Colors.Yellow);
                rectPipe.StrokeThickness = 3;
            }
            else
            {
                rectPipe.Stroke = new SolidColorBrush(Colors.DarkSlateGray);
                rectPipe.StrokeThickness = 2;
            }
        }
        
        #endregion
        
        public ZIndexEnum ZIndex_Base()
        {
            return ZIndexEnum.Estaticos;
        }
    }
}
