using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MyAuth
{
    public partial class ResetPasswordPanel : UserControl
    {
        string _email;

        // ** ctor
        public ResetPasswordPanel(string email)
        {
            InitializeComponent();

            _btnOK.Click += _btnOK_Click;
            _btnCancel.Click += _btnCancel_Click;

            _email = email;
            _tb.Text = _tb.Text.Replace("$EMAIL$", _email);
        }
        public ResetPasswordPanel() : this(null) { }

        // ** event handlers
        void _btnOK_Click(object sender, RoutedEventArgs e)
        {
            ModalDialog.StartOperation(this);
            try
            {
                var model = DataContext as AuthenticationModel;
                model.ResetPassword(_email, completedReset);
            }
            catch (Exception x)
            {
                completedReset(x);
            }
        }
        void completedReset(Exception x)
        {
            ModalDialog.EndOperation(this, x);
        }
        void _btnCancel_Click(object sender, RoutedEventArgs e)
        {
            ModalDialog.Close(this);
        }
    }
}
