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

namespace C1Extended_Demo
{
    public class Navigator : Control
    {
        public event RoutedEventHandler FirstItemButtonClick;

        public event RoutedEventHandler PreviousItemButtonClick;

        public event RoutedEventHandler NextItemButtonClick;

        public event RoutedEventHandler LastItemButtonClick;

        public event RoutedEventHandler NewItemButtonClick;

        public event RoutedEventHandler DeleteItemButtonClick;

        private Button _firstItemButton;

        private Button _previousItemButton;

        private Button _nextItemButton;

        private Button _lastItemButton;

        private Button _newItemButton;

        private Button _deleteItemButton;

        public Navigator()
        {
            DefaultStyleKey = typeof(Navigator);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _firstItemButton = GetTemplateChild("FirstItemButton") as Button;
            _previousItemButton = GetTemplateChild("PreviousItemButton") as Button;
            _nextItemButton = GetTemplateChild("NextItemButton") as Button;
            _lastItemButton = GetTemplateChild("LastItemButton") as Button;
            _newItemButton = GetTemplateChild("NewItemButton") as Button;
            _deleteItemButton = GetTemplateChild("DeleteItemButton") as Button;

            _firstItemButton.Click += OnFirstItemButtonClick;
            _previousItemButton.Click += OnPreviousItemButtonClick;
            _nextItemButton.Click += OnNextItemButtonClick;
            _lastItemButton.Click += OnLastItemButtonClick;
            _newItemButton.Click += OnNewItemButtonClick;
            _deleteItemButton.Click += OnDeleteItemButtonClick;
        }

        private void OnFirstItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (FirstItemButtonClick != null)
                FirstItemButtonClick(this, e);
        }

        private void OnPreviousItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (PreviousItemButtonClick != null)
                PreviousItemButtonClick(this, e);
        }

        private void OnNextItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (NextItemButtonClick != null)
                NextItemButtonClick(this, e);
        }

        private void OnLastItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (LastItemButtonClick != null)
                LastItemButtonClick(this, e);
        }

        private void OnNewItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (NewItemButtonClick != null)
                NewItemButtonClick(this, e);
        }

        private void OnDeleteItemButtonClick(object sender, RoutedEventArgs e)
        {
            if (DeleteItemButtonClick != null)
                DeleteItemButtonClick(this, e);
        }
    }
}
