using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using VKontakte;

namespace Gsome
{
	public class SplashScreen : Form
	{
		private IContainer components;

		private TableLayoutPanel tlpMain;

		private ProgressBar pbAuthorization;

		private Label lblStatus;

		private PictureBox pctTitle;

		private Label lblVersion;

		private Label lblInfo;

		private PictureBox pctLogo;

		private static Pen penBorder = new Pen(ProfessionalColors.ButtonSelectedHighlightBorder, 2f);

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Gsome.SplashScreen));
			tlpMain = new System.Windows.Forms.TableLayoutPanel();
			pbAuthorization = new Gsome.ProgressBar();
			lblStatus = new System.Windows.Forms.Label();
			pctTitle = new System.Windows.Forms.PictureBox();
			lblVersion = new System.Windows.Forms.Label();
			lblInfo = new System.Windows.Forms.Label();
			pctLogo = new System.Windows.Forms.PictureBox();
			tlpMain.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)pctTitle).BeginInit();
			((System.ComponentModel.ISupportInitialize)pctLogo).BeginInit();
			SuspendLayout();
			tlpMain.BackColor = System.Drawing.Color.Transparent;
			tlpMain.ColumnCount = 2;
			tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100f));
			tlpMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 141f));
			tlpMain.Controls.Add(pbAuthorization, 0, 3);
			tlpMain.Controls.Add(lblStatus, 0, 2);
			tlpMain.Controls.Add(pctTitle, 0, 0);
			tlpMain.Controls.Add(lblVersion, 0, 1);
			tlpMain.Controls.Add(lblInfo, 1, 1);
			tlpMain.Controls.Add(pctLogo, 1, 0);
			tlpMain.Dock = System.Windows.Forms.DockStyle.Fill;
			tlpMain.Location = new System.Drawing.Point(0, 0);
			tlpMain.Name = "tlpMain";
			tlpMain.RowCount = 4;
			tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f));
			tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
			tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
			tlpMain.RowStyles.Add(new System.Windows.Forms.RowStyle());
			tlpMain.Size = new System.Drawing.Size(365, 185);
			tlpMain.TabIndex = 0;
			pbAuthorization.BackColor = System.Drawing.Color.White;
			tlpMain.SetColumnSpan(pbAuthorization, 2);
			pbAuthorization.Dock = System.Windows.Forms.DockStyle.Top;
			pbAuthorization.Location = new System.Drawing.Point(10, 157);
			pbAuthorization.Margin = new System.Windows.Forms.Padding(10, 3, 10, 10);
			pbAuthorization.Maximum = 100;
			pbAuthorization.Name = "pbAuthorization";
			pbAuthorization.Progress = 0;
			pbAuthorization.Size = new System.Drawing.Size(345, 18);
			pbAuthorization.TabIndex = 0;
			tlpMain.SetColumnSpan(lblStatus, 2);
			lblStatus.Dock = System.Windows.Forms.DockStyle.Fill;
			lblStatus.Font = new System.Drawing.Font("Tahoma", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 204);
			lblStatus.Location = new System.Drawing.Point(10, 140);
			lblStatus.Margin = new System.Windows.Forms.Padding(10, 0, 10, 0);
			lblStatus.Name = "lblStatus";
			lblStatus.Size = new System.Drawing.Size(345, 14);
			lblStatus.TabIndex = 1;
			pctTitle.BackgroundImage = (System.Drawing.Image)resources.GetObject("pctTitle.BackgroundImage");
			pctTitle.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
			pctTitle.Dock = System.Windows.Forms.DockStyle.Left;
			pctTitle.Location = new System.Drawing.Point(3, 3);
			pctTitle.Name = "pctTitle";
			pctTitle.Size = new System.Drawing.Size(216, 92);
			pctTitle.TabIndex = 2;
			pctTitle.TabStop = false;
			lblVersion.AutoSize = true;
			lblVersion.Font = new System.Drawing.Font("Tahoma", 9.75f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, 204);
			lblVersion.Location = new System.Drawing.Point(10, 101);
			lblVersion.Margin = new System.Windows.Forms.Padding(10, 3, 10, 0);
			lblVersion.Name = "lblVersion";
			lblVersion.Size = new System.Drawing.Size(0, 16);
			lblVersion.TabIndex = 3;
			lblInfo.AutoSize = true;
			lblInfo.Dock = System.Windows.Forms.DockStyle.Fill;
			lblInfo.Font = new System.Drawing.Font("Tahoma", 9f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 204);
			lblInfo.ForeColor = System.Drawing.Color.Blue;
			lblInfo.Location = new System.Drawing.Point(227, 98);
			lblInfo.Name = "lblInfo";
			lblInfo.Size = new System.Drawing.Size(135, 42);
			lblInfo.TabIndex = 4;
			lblInfo.Text = "onotolearmy.0pk.ru\r\notake.ru\r\n==by exe-dealer==";
			lblInfo.TextAlign = System.Drawing.ContentAlignment.BottomRight;
			pctLogo.BackgroundImage = (System.Drawing.Image)resources.GetObject("pctLogo.BackgroundImage");
			pctLogo.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
			pctLogo.Dock = System.Windows.Forms.DockStyle.Right;
			pctLogo.Location = new System.Drawing.Point(264, 10);
			pctLogo.Margin = new System.Windows.Forms.Padding(3, 10, 10, 3);
			pctLogo.Name = "pctLogo";
			pctLogo.Size = new System.Drawing.Size(91, 85);
			pctLogo.TabIndex = 5;
			pctLogo.TabStop = false;
			pctLogo.Resize += new System.EventHandler(pctLogo_Resize);
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			BackColor = System.Drawing.Color.White;
			BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
			base.ClientSize = new System.Drawing.Size(365, 185);
			base.Controls.Add(tlpMain);
			DoubleBuffered = true;
			base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "SplashScreen";
			base.ShowInTaskbar = false;
			base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			tlpMain.ResumeLayout(false);
			tlpMain.PerformLayout();
			((System.ComponentModel.ISupportInitialize)pctTitle).EndInit();
			((System.ComponentModel.ISupportInitialize)pctLogo).EndInit();
			ResumeLayout(false);
		}

		public SplashScreen()
		{
			InitializeComponent();
			lblVersion.Text = "Версия: " + Application.ProductVersion + "\r\nВоруй-Убивай edition";
		}

		protected override void OnPaintBackground(PaintEventArgs e)
		{
			Graphics graphics = e.Graphics;
			Rectangle rect = new Rectangle(1, 1, base.ClientRectangle.Width - 2, base.ClientRectangle.Height - 2);
			using (LinearGradientBrush brush = new LinearGradientBrush(rect, ProfessionalColors.ButtonSelectedGradientBegin, ProfessionalColors.ButtonSelectedGradientEnd, LinearGradientMode.Vertical))
			{
				graphics.FillRectangle(brush, rect);
			}
			graphics.DrawRectangle(penBorder, rect);
			OnPaint(e);
		}

		protected override void OnShown(EventArgs e)
		{
			base.OnShown(e);
			pbAuthorization.Maximum = Accounts.Items.Count;
			Application.DoEvents();
			List<VKAccount> list = new List<VKAccount>();
			for (int i = 0; i < Accounts.Items.Count; i++)
			{
				VKAccount vKAccount = Accounts.Items[i];
				lblStatus.Text = "Авторизация: " + vKAccount;
				Application.DoEvents();
				try
				{
					VKClient vKClient = VKClient.Create(vKAccount.EMail, vKAccount.Pass);
					Accounts.Items[i] = vKClient.Account;
					VKClients.Items.Add(vKClient);
					pbAuthorization.SetNormalStyle();
				}
				catch (AuthorizationFailedException)
				{
					pbAuthorization.SetErrorStyle();
					list.Add(vKAccount);
				}
				pbAuthorization.Progress++;
				Application.DoEvents();
			}
			pbAuthorization.SetNormalStyle();
			lblStatus.Text = "Авторизация завершена";
			foreach (VKAccount item in list)
			{
				Accounts.Items.Remove(item);
			}
			Accounts.Save();
			Close();
		}

		private void pctLogo_Resize(object sender, EventArgs e)
		{
		}
	}
}
