/* GUI_AbstractLibrary.h */

/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
 *
 * This file is part of sayonara player
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GUI_ABSTRACTLIBRARY_H
#define GUI_ABSTRACTLIBRARY_H

#include "Gui/Utils/Delegates/ComboBoxDelegate.h"
#include "Gui/Utils/Widgets/Widget.h"

#include "Utils/Library/Filter.h"
#include "Utils/Library/Sorting.h"
#include "Utils/Library/LibraryNamespaces.h"
#include "Utils/Pimpl.h"

#include <QList>

class QPushButton;
class QComboBox;
class AbstractLibrary;
class QAbstractItemView;

namespace Library
{
	class TableView;
	class SearchBar;
	class GUI_AbstractLibrary :
		public Gui::Widget
	{
		Q_OBJECT
		PIMPL(GUI_AbstractLibrary)

		public:
			explicit GUI_AbstractLibrary(AbstractLibrary* library, QWidget* parent = nullptr);
			virtual ~GUI_AbstractLibrary() override;

		protected slots:
			virtual void liveSearchChanged();
			virtual void clearSelections();
			virtual void searchTriggered();
			virtual void searchEdited(const QString& searchString);
			virtual void keyPressed(int key);
			virtual void queryLibrary();
			virtual void itemDeleteClicked();
			virtual void showDeleteAnswer(const QString& text);

			void tracksDeleteClicked();

		protected: // NOLINT(*-redundant-access-specifiers)
			virtual void initShortcuts();
			[[nodiscard]] virtual bool hasSelections() const;

			virtual TrackDeletionMode showDeleteDialog(int trackCount) = 0;

			[[nodiscard]] virtual TableView* lvArtist() const = 0;
			[[nodiscard]] virtual TableView* lvAlbum() const = 0;
			[[nodiscard]] virtual TableView* lvTracks() const = 0;
			[[nodiscard]] virtual SearchBar* leSearch() const = 0;
			[[nodiscard]] virtual QList<QAbstractItemView*> allViews() const = 0;
			[[nodiscard]] virtual QList<Filter::Mode> searchOptions() const = 0;

			template<typename UI, typename T>
			std::shared_ptr<UI> setupParent(T* subclass)
			{
				auto result = std::make_shared<UI>();

				result->setupUi(subclass);
				init();

				return result;
			}

			void showEvent(QShowEvent* e) override;

		private:
			void init();
			void boldFontChanged();
	};
}

#endif // GUI_ABSTRACTLIBRARY_H
