#pragma once
#include "song.h"

namespace logiAmp {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for addSong
	/// </summary>
	public ref class addSong : public System::Windows::Forms::Form
	{
	public:
		addSong(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~addSong()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::TextBox^  songNameBox;
	private: System::Windows::Forms::TextBox^  songArtistBox;
	private: System::Windows::Forms::TextBox^  filePathBox;
	private: System::Windows::Forms::Button^  openFileDialogButton;
	private: System::Windows::Forms::Button^  addNewSongButton;
	private: System::Windows::Forms::OpenFileDialog^  openFileDialog1;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->songNameBox = (gcnew System::Windows::Forms::TextBox());
			this->songArtistBox = (gcnew System::Windows::Forms::TextBox());
			this->filePathBox = (gcnew System::Windows::Forms::TextBox());
			this->openFileDialogButton = (gcnew System::Windows::Forms::Button());
			this->addNewSongButton = (gcnew System::Windows::Forms::Button());
			this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(12, 16);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(66, 13);
			this->label1->TabIndex = 0;
			this->label1->Text = L"Song Name:";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(12, 44);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(61, 13);
			this->label2->TabIndex = 0;
			this->label2->Text = L"Song Artist:";
			// 
			// songNameBox
			// 
			this->songNameBox->Location = System::Drawing::Point(86, 13);
			this->songNameBox->Name = L"songNameBox";
			this->songNameBox->Size = System::Drawing::Size(249, 20);
			this->songNameBox->TabIndex = 0;
			// 
			// songArtistBox
			// 
			this->songArtistBox->Location = System::Drawing::Point(86, 41);
			this->songArtistBox->Name = L"songArtistBox";
			this->songArtistBox->Size = System::Drawing::Size(249, 20);
			this->songArtistBox->TabIndex = 2;
			// 
			// filePathBox
			// 
			this->filePathBox->Location = System::Drawing::Point(15, 84);
			this->filePathBox->Name = L"filePathBox";
			this->filePathBox->ReadOnly = true;
			this->filePathBox->Size = System::Drawing::Size(239, 20);
			this->filePathBox->TabIndex = 100;
			// 
			// openFileDialogButton
			// 
			this->openFileDialogButton->Location = System::Drawing::Point(260, 81);
			this->openFileDialogButton->Name = L"openFileDialogButton";
			this->openFileDialogButton->Size = System::Drawing::Size(75, 23);
			this->openFileDialogButton->TabIndex = 3;
			this->openFileDialogButton->Text = L"Browse..";
			this->openFileDialogButton->UseVisualStyleBackColor = true;
			this->openFileDialogButton->Click += gcnew System::EventHandler(this, &addSong::openFileDialogButton_Click);
			// 
			// addNewSongButton
			// 
			this->addNewSongButton->Location = System::Drawing::Point(143, 110);
			this->addNewSongButton->Name = L"addNewSongButton";
			this->addNewSongButton->Size = System::Drawing::Size(75, 23);
			this->addNewSongButton->TabIndex = 4;
			this->addNewSongButton->Text = L"Add";
			this->addNewSongButton->UseVisualStyleBackColor = true;
			this->addNewSongButton->Click += gcnew System::EventHandler(this, &addSong::addNewSongButton_Click);
			// 
			// openFileDialog1
			// 
			this->openFileDialog1->FileName = L"openFileDialog1";
			// 
			// addSong
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(353, 141);
			this->Controls->Add(this->addNewSongButton);
			this->Controls->Add(this->openFileDialogButton);
			this->Controls->Add(this->filePathBox);
			this->Controls->Add(this->songArtistBox);
			this->Controls->Add(this->songNameBox);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Name = L"addSong";
			this->Text = L"Add Song to Library";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void openFileDialogButton_Click(System::Object^  sender, System::EventArgs^  e) 
		 {
				 //Filter available files.
				 openFileDialog1->Filter = " Audio Files (*.mp3, *.ogg, *.wav, *.flac)|*.mp3;*.ogg;*.wav;*.flac";
				 // Open the prompt.
				 openFileDialog1->ShowDialog();
				 // Set the path in the read-only box.
				 filePathBox->Text = openFileDialog1->FileName;
		 }
	private: System::Void addNewSongButton_Click(System::Object^  sender, System::EventArgs^  e) 
		{
			// Check to see all boxes have values
			if( songNameBox->Text == "" ) {
				MessageBox::Show("Please enter a song name.");
			} else if( songArtistBox->Text == "" ) {
				MessageBox::Show("Please enter an artist name.");
			} else if( filePathBox->Text == "" ) {
				MessageBox::Show("Please select a file.");
			} else {
				// If song exists, do not let it get created.
				if( song::songExists( songNameBox->Text, songArtistBox->Text) ) {
					MessageBox::Show("Song already exists in database.");
				} else {
					// If the elements pass the checks, call the static function to add a song
					song::addSong( songNameBox->Text, songArtistBox->Text, filePathBox->Text );

					// Close the add dialog
					this->Close();
				}
			}
		}
};
}
