namespace HistoryView.Controls.Basics;

public partial class TimerWatch : UserControl
{
    public TimerWatch()
    {
        InitializeComponent();
        _timer.Elapsed += new System.Timers.ElapsedEventHandler(OnTmrTrg);
        _timer.Interval = 1000;
        _timer.AutoReset = true;
        _timer.Enabled = true;
    }
    private readonly System.Timers.Timer _timer = new();

    private void OnTmrTrg(object? sender, System.Timers.ElapsedEventArgs e)
    {
        try
        {
            App.Current?.Dispatcher?.Invoke(() =>
            {
                this.Date.Text = DateTime.Now.ToString("yyyy/MM/dd");
                this.Time.Text = DateTime.Now.ToString("HH:mm:ss");
            });
        }
        catch
        {

        }
    }

    public Orientation Orientation
    {
        get { return (Orientation)GetValue(OrientationProperty); }
        set { SetValue(OrientationProperty, value); }
    }

    public static readonly DependencyProperty OrientationProperty =
        DependencyProperty.Register("Orientation", typeof(Orientation), typeof(TimerWatch), new PropertyMetadata(default));

    public SolidColorBrush TextBrush
    {
        get { return (SolidColorBrush)GetValue(TextBrushProperty); }
        set { SetValue(TextBrushProperty, value); }
    }

    // Using a DependencyProperty as the backing store for TextBrush.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty TextBrushProperty =
        DependencyProperty.Register("TextBrush", typeof(SolidColorBrush), typeof(TimerWatch), new PropertyMetadata(new SolidColorBrush()));

}
