using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
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 SlnMesnac.WPF.Templates
{
    /// <summary>
    /// Pagination.xaml 的交互逻辑
    /// </summary>
    public partial class Pagination : UserControl
    {
        public Pagination()
        {
            InitializeComponent();
        }


        #region 分页数据属性

        /// <summary>
        /// 总条数
        /// </summary>
        public long Total
        {
            get { return (long)GetValue(TotalProperty); }
            set { SetValue(TotalProperty, value); }
        }
        public static readonly DependencyProperty TotalProperty =
            DependencyProperty.Register("Total", typeof(long), typeof(Pagination), new PropertyMetadata(0l, (s, e) =>
            {
                ((Pagination)s).Total = (long)e.NewValue;
            }));


        /// <summary>
        /// 总页数
        /// </summary>
        public int Page
        {
            get { return (int)GetValue(PageProperty); }
            set { SetValue(PageProperty, value); }
        }

        public static readonly DependencyProperty PageProperty =
            DependencyProperty.Register("Page", typeof(int), typeof(Pagination),
                new PropertyMetadata(0, (o, args) =>
                {
                    ((Pagination)o).Page = (int)args.NewValue;
                }));

        /// <summary>
        /// 当前页
        /// </summary>
        public int Current
        {
            get { return (int)GetValue(CurrentProperty); }
            set { SetValue(CurrentProperty, value); }
        }
        public static readonly DependencyProperty CurrentProperty =
            DependencyProperty.Register("Current", typeof(int), typeof(Pagination), new PropertyMetadata(1, (o, args) =>
            {
                ((Pagination)o).Page = (int)args.NewValue;
            }));

        /// <summary>
        /// 分页大小列表
        /// </summary>
        public List<int> PageSizes
        {
            get { return (List<int>)GetValue(PageSizesProperty); }
            set { SetValue(PageSizesProperty, value); }
        }
        public static readonly DependencyProperty PageSizesProperty =
            DependencyProperty.Register("PageSizes", typeof(List<int>), typeof(Pagination), new PropertyMetadata(null, (o, args) =>
            {
                ((Pagination)o).PageSizes = (List<int>)args.NewValue;
            }));

        /// <summary>
        /// 分页大小
        /// </summary>
        public int PageSize
        {
            get { return (int)GetValue(PageSizeProperty); }
            set { SetValue(PageSizeProperty, value); }
        }
        public static readonly DependencyProperty PageSizeProperty =
            DependencyProperty.Register("PageSize", typeof(int), typeof(Pagination), new PropertyMetadata(10, (o, args) =>
            {
                ((Pagination)o).PageSize = (int)args.NewValue;
            }));

        #endregion

        #region 分页事件

        /// <summary>
        /// 上一页
        /// </summary>
        public static readonly DependencyProperty FindPreCommandProperty =
            DependencyProperty.Register("PreCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
                (o, args) =>
                {
                    ((Pagination)o).PreCommand = (RelayCommand)args.NewValue;
                }));
        public RelayCommand PreCommand
        {
            get { return (RelayCommand)GetValue(FindPreCommandProperty); }
            set { SetValue(FindPreCommandProperty, value); }
        }
        public static readonly DependencyProperty NextCommandProperty =
            DependencyProperty.Register("NextCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
                (o, args) =>
                {
                    ((Pagination)o).NextCommand = (RelayCommand)args.NewValue;
                }));
        public RelayCommand NextCommand
        {
            get { return (RelayCommand)GetValue(NextCommandProperty); }
            set { SetValue(NextCommandProperty, value); }
        }
        public static readonly DependencyProperty GoCommandProperty =
            DependencyProperty.Register("GoCommand", typeof(RelayCommand), typeof(Pagination), new PropertyMetadata(null,
                (o, args) =>
                {
                    ((Pagination)o).GoCommand = (RelayCommand)args.NewValue;
                }));
        public RelayCommand GoCommand
        {
            get { return (RelayCommand)GetValue(GoCommandProperty); }
            set { SetValue(GoCommandProperty, value); }
        }
        #endregion
    }
}
