using System;
using System.Net;
using System.Windows;
using System.Diagnostics;
using System.Windows.Controls;

using Fiesta_Client.API;

namespace Fiesta_Client.Panels
{
    public partial class Buy : UserControl
    {
        private MainWindow MainHandle;

        public Buy(MainWindow MW)
        {
            InitializeComponent();

            MainHandle = MW;
        }

        private void Next_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                WebClient BuyClient = new WebClient();

                MessageBox.Show(String.Format("{0}={1}", Web.Settings()["Account-Exist-URL"], Username.Text));

                if (BuyClient.DownloadString(String.Format("{0}={1}", Web.Settings()["Account-Exist-URL"], Username.Text)) == "1")
                {
                    Process.Start(String.Format(Web.Settings()["Buy-URL"], Username.Text));

                    MainHandle.ShowMain(false);
                }
                else
                {
                    MessageBox.Show("That username cannot be found :(");

                    Process.Start(String.Format("{0}\\Nyx Launcher.exe", AppDomain.CurrentDomain.BaseDirectory));

                    Environment.Exit(0);
                }
            }
            catch { }
        }
    }
}
