using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NetTunnelApp
{
    public partial class LoginForm : Form
    {
        public event EventHandler<HashValuesEventArgs> onLoginServer;

        public LoginForm()
        {
            InitializeComponent();
        }

        private void linkPrivate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://oavpn.komect.com/portal/#!/privacy_CN");
        }

        private void chkAgree_CheckedChanged(object sender, EventArgs e)
        {
            butLogin.Enabled = chkAgree.Checked && txtPassword.Text.Length > 0 && txtUserName.Text.Length > 0;
        }

        private void butLogin_Click(object sender, EventArgs e)
        {
            HashValuesEventArgs eventArgs = new HashValuesEventArgs();
            eventArgs.HashArgs.Add("UserName", this.txtUserName.Text);
            eventArgs.HashArgs.Add("Password", this.txtPassword.Text);
            onLoginServer(sender, eventArgs);
            this.DialogResult = DialogResult.OK;
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtUserName_TextChanged(object sender, EventArgs e)
        {
            butLogin.Enabled = chkAgree.Checked && txtPassword.Text.Length > 0 && txtUserName.Text.Length > 0;
        }

        private void txtPassword_TextChanged(object sender, EventArgs e)
        {
            butLogin.Enabled = chkAgree.Checked && txtPassword.Text.Length > 0 && txtUserName.Text.Length > 0;
        }
    }
}