using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Khd.Core.Wpf.CSS
{
    /// <summary>
    /// PageControl.xaml 的交互逻辑
    /// </summary>
    public partial class PageControl : UserControl
    {
        public event RoutedEventHandler? PreviousPageClicked;
        public event RoutedEventHandler? NextPageClicked;
        public event SelectionChangedEventHandler? PageSizeComboBoxSelectionChanged;
        public readonly PageInfo PageInfo = new();

        public PageControl()
        {
            InitializeComponent();
            this.PageControlGrid.DataContext = PageInfo;
        }

        private void PreviousPageButton_Click(object sender, RoutedEventArgs e)
        {
            PreviousPageClicked?.Invoke(this, e);
        }

        private void NextPageButton_Click(object sender, RoutedEventArgs e)
        {
            NextPageClicked?.Invoke(this, e);
        }
    }


    #region PageInfo
    public class PageInfo : INotifyPropertyChanged
    {
        private int _pageSize = 10;
        private int _currentPage = 1;
        private int _totalPage = 0;

        public int PageSize
        {
            get => _pageSize;
            set
            {
                if (_pageSize != value)
                {
                    _pageSize = value;
                    OnPropertyChanged(nameof(PageSize));
                }
            }
        }

        public int CurrentPage
        {
            get => _currentPage;
            set
            {
                if (_currentPage != value)
                {
                    _currentPage = value;
                    OnPropertyChanged(nameof(CurrentPage));
                }
            }
        }

        public int TotalPage
        {
            get => _totalPage;
            set
            {
                if (_totalPage != value)
                {
                    _totalPage = value;
                    OnPropertyChanged(nameof(TotalPage));
                }
            }
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    #endregion
}
