using PCUT.ViewModels;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

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

namespace PCUT.Pages
{
    public sealed partial class ChangePasswordDialog : ContentDialog
    {
        private ChangePasswordViewModel ViewModel { get; set; }
        public ChangePasswordDialog(string userId)
        {
            this.InitializeComponent();
            ViewModel = new ChangePasswordViewModel();
            ViewModel.UserId = userId;
            this.DataContext = ViewModel;
        }

        private async void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var confirmDialog = new MessageDialog("Are you sure you want to save the new password?");
            confirmDialog.Commands.Add(new UICommand("Yes") { Id = 1 });
            confirmDialog.Commands.Add(new UICommand("No") { Id = 0 });
            confirmDialog.DefaultCommandIndex = 0;
            confirmDialog.CancelCommandIndex = 1;

            var result = await confirmDialog.ShowAsync();

            if ((int)result.Id == 1)
            {
                await ViewModel.ChangePassword();
            }
            else
            {
             this.Hide(); 
            }
        }

        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            var confirmDialog = new MessageDialog("Are you sure you want to reset?");
            confirmDialog.Commands.Add(new UICommand("Yes") { Id = 1 });
            confirmDialog.Commands.Add(new UICommand("No") { Id = 0 });
            confirmDialog.DefaultCommandIndex = 0;
            confirmDialog.CancelCommandIndex = 1;

            var result = await confirmDialog.ShowAsync();

            if ((int)result.Id == 1)
            {
                await ViewModel.ChangeDefaultPassword();
            }
            else
            {
                this.Hide();
            }
        }
    }
}
