using System.Windows;
using System.Windows.Controls;

namespace Elwig.Controls {
    public partial class UnitTextBox : UserControl {

        public event TextChangedEventHandler? TextChanged;

        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UnitTextBox));
        public string Text {
            get => (string)GetValue(TextProperty);
            set => SetValue(TextProperty, value ?? "");
        }

        public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(UnitTextBox));
        public string Unit {
            get => (string)GetValue(UnitProperty);
            set => SetValue(UnitProperty, value ?? "");
        }

        public UnitTextBox() {
            Text = "";
            Unit = "";
            InitializeComponent();
            DataContext = this;
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs evt) {
            Text = TextBox.Text;
            TextChanged?.Invoke(sender, evt);
        }

        public new void Focus() {
            TextBox.Focus();
        }
    }
}