using PCUT.ViewModels;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace PCUT.Pages
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class LogInformationPage : Page
    {
        public LogViewModel ViewModels { get; set; }
        public LogInformationPage()
        {
            this.InitializeComponent();
            ViewModels = DataContext as LogViewModel;
        }

        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ViewModels.Types.Bind(Types);
            ViewModels.Users.Bind(Users);
            await ViewModels.LoadUsersAsync();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            ViewModels.Pagination.Page = 1;
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            ViewModels.Pagination.Dispose();
        }

        private void btnFirst_Click(object sender, RoutedEventArgs e)
        {
            ViewModels.Pagination.Page = 1;
        }

        private void btnLast_Click(object sender, RoutedEventArgs e)
        {
            ViewModels.Pagination.Page = ViewModels.Pagination.TotalPage;
        }

        private void btnPrevious_Click(object sender, RoutedEventArgs e)
        {
            ViewModels.Pagination.Page--;
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            ViewModels.Pagination.Page++;
        }
    }
}
