﻿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 Custom_Tag
{
	public partial class EditForm : Form
	{
		MainForm mForm;
		List<int> index = new List<int>();

		public EditForm(MainForm MF, List<int> id)
		{
			mForm = MF;
			InitializeComponent();
			index = id;
			lbTotalFile.Text = "Файлов редактируется: " + index.Count.ToString();
		}

		private void Apply() //Приминить редактирование
		{
			for (int i = 0, id; i < index.Count; i++) //Загрузка данных в класс
			{
				id = index[i];
				if (cbNameFile.Checked)
				{
					mForm.Apply(id, "NameFile", mForm.lMFile[id].Repl(tbNameFile.Text));
				}
				if (cbTitle.Checked)
				{
					mForm.Apply(id, "Title", mForm.lMFile[id].Repl(tbTitle.Text));
				}
				if (cbComment.Checked)
				{
					mForm.Apply(id, "Comment", mForm.lMFile[id].Repl(tbComment.Text));
				}
				if (cbPerformer.Checked)
				{
					mForm.Apply(id, "Performer", tbPerformer.Text);
				}
				if (cbAlbumArtist.Checked)
				{
					mForm.Apply(id, "AlbumArtist", tbAlbumArtist.Text);
				}
				if (cbAlbum.Checked)
				{
					mForm.Apply(id, "Album", tbAlbum.Text);
				}
				if (cbYear.Checked)
				{
					mForm.Apply(id, "Year", (uint)nudYear.Value);
				}
				if (cbTrack.Checked && !cbTrackStep.Checked)
				{
					mForm.Apply(id, "Track", (uint)nupTrack.Value);
				}
				else if (cbTrack.Checked)
				{
					mForm.Apply(id, "Track", (uint)(nupTrack.Value + nupTrackStep.Value * i));
				}
				if (cbGenre.Checked)
				{
					mForm.Apply(id, "Genre", tbGenre.Text);
				}
			}
		}

		private void btSeve_Click(object sender, EventArgs e)
		{
			Apply();
		}

		//====================== ЧекБоксы ======================
		private void cbNameFile_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbNameFile, cbNameFile.Checked);
		}
		private void cbTitle_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbTitle, cbTitle.Checked);
		}
		private void cbComment_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbComment, cbComment.Checked);
		}
		private void cbPerformer_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbPerformer, cbPerformer.Checked);
		}
		private void cbAlbumArtist_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbAlbumArtist, cbAlbumArtist.Checked);
		}
		private void cbAlbum_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbAlbum, cbAlbum.Checked);
		}
		private void cbGenre_CheckedChanged(object sender, EventArgs e)
		{
			lEnabled(tbGenre, cbGenre.Checked);
		}

		private void cbYear_CheckedChanged(object sender, EventArgs e)
		{
			nudYear.Enabled = cbYear.Checked;
		}
		private void cbTrack_CheckedChanged(object sender, EventArgs e)
		{
			nupTrack.Enabled = cbTrackStep.Enabled = cbTrack.Checked;
			nupTrackStep.Enabled = cbTrack.Checked & cbTrackStep.Checked;
		}
		private void cbTrackStep_CheckedChanged(object sender, EventArgs e)
		{
			nupTrackStep.Enabled = cbTrackStep.Checked;
		}
		private void lEnabled(TextBox TB, bool ON)
		{
			if (ON)
			{
				TB.Enabled = ON;
				TB.BackColor = Color.FromArgb(52, 52, 52);
			}
			else
			{
				TB.Enabled = ON;
				TB.BackColor = Color.FromArgb(42, 42, 42);
			}
		}


		private void EditForm_FormClosed(object sender, FormClosedEventArgs e) //Закрытие формы
		{
			mForm.btEditON();
		}

		private void EditForm_MouseDown(object sender, MouseEventArgs e) //Перетаскивание формы за ее тело
		{
			base.Capture = false;
			Message m = Message.Create(base.Handle, 0xa1, new IntPtr(2), IntPtr.Zero);
			this.WndProc(ref m);
		}

		private void btClose_Click(object sender, EventArgs e) //Кнопка закрыть
		{
			this.Close();
		}
	}
}
