using System;
using System.Drawing;
using System.Windows.Forms;

namespace Katteker.AppStub
{
    public sealed partial class InstallerUx : Form
    {
        private int _autoCloseCountdown = 10;

        public InstallerUx(string appName)
        {
            Font = SystemFonts.MessageBoxFont;
            InitializeComponent();
            SetLocationAndShow();
            this.appName.Text = appName;
        }

        private void SetLocationAndShow()
        {
            var taskBar = new Taskbar();
            switch (taskBar.Position)
            {
                case TaskbarPosition.Unknown:
                    break;
                case TaskbarPosition.Left:
                    Location = new Point(taskBar.Bounds.Left + taskBar.Bounds.Width, taskBar.Bounds.Bottom - Size.Height);
                    break;
                case TaskbarPosition.Top:
                    Location = new Point(taskBar.Bounds.Right - Size.Width, taskBar.Bounds.Bottom);
                    break;
                case TaskbarPosition.Right:
                    Location = new Point(taskBar.Bounds.Left - Size.Width, taskBar.Bounds.Bottom - Size.Height);
                    break;
                case TaskbarPosition.Bottom:
                    Location = new Point(taskBar.Bounds.Right - Size.Width, taskBar.Bounds.Top - Size.Height);
                    break;
                default:
                    break;
            }
            Show();
        }

        private void closeBtn_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void installBtn_Click(object sender, EventArgs e)
        {
            _autoCloseCountdown = 0;
            MessageBox.Show("Hallo Welt");
        }

        private void autoCloseTimer_Tick(object sender, EventArgs e)
        {
            switch (_autoCloseCountdown)
            {
                case 1:
                    Close();
                    break;
                case 0:
                    countDownLbl.Text = string.Empty;
                    autoCloseTimer.Enabled = false;
                    break;
                default:
                    countDownLbl.Tag = --_autoCloseCountdown;
                    countDownLbl.Text = _autoCloseCountdown.ToString();
                    break;
            }
        }
    }
}