using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Http;

namespace JellyfinRPC
{
    public partial class ConfigForm : Form
    {
        public ConfigForm()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            ConfigManager.SetEntry("ServerURL", textBox1.Text);
            ConfigManager.SetEntry("APIKey", maskedTextBox1.Text);
            ConfigManager.SetEntry("UserID", textBox2.Text);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {
            textBox1.Text = ConfigManager.GetEntry("ServerURL");
            textBox2.Text = ConfigManager.GetEntry("UserID");
            maskedTextBox1.Text = ConfigManager.GetEntry("APIKey");
            textBox4.Text = ConfigManager.GetEntry("ServerURL");
            textBox5.Text = ConfigManager.GetEntry("ServerURL");
            JellyfinAPI.formClosed = false;
            
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click_1(object sender, EventArgs e)
        {

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
        private void button4_Click(object sender, EventArgs e)
        {
            ConfigManager.SetEntry("ServerURL", textBox4.Text);
            
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            ConfigManager.SetEntry("ServerURL", textBox5.Text);
            JellyfinAPI.GetTokenFromUsernameAndPassword(Username: textBox6.Text, Password: maskedTextBox2.Text);
        }

        private void textBox4_MouseHover(object sender, EventArgs e)
        {
            toolTip1.Show("Format like https://mydomain.local.", textBox4, textBox4.PointToClient(textBox4.Location).X + 30, textBox4.PointToClient(textBox4.Location).Y + 90, 2000);
        }

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

        private void textBox5_MouseHover(object sender, EventArgs e)
        {
            toolTip1.Show("Format like https://mydomain.local.", textBox5, textBox5.PointToClient(textBox5.Location).X + 30, textBox5.PointToClient(textBox5.Location).Y + 90, 2000);
        }

        private void textBox1_MouseHover(object sender, EventArgs e)
        {
            toolTip1.Show("Format like https://mydomain.local.", textBox1, textBox1.PointToClient(textBox1.Location).X + 30, textBox1.PointToClient(textBox1.Location).Y + 90, 2000);
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Hide();
            await JellyfinAPI.AuthWithQuickConnect();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ConfigManager.SetEntry("ServerURL", textBox4.Text);
            Close();
        }

        private void ConfigForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            JellyfinAPI.formClosed = true;
        }
    }
}
