/*
 * Copyright (C) 2014-2026 CZ.NIC
 *
 * 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/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#pragma once

#include <QString>
#include <QWidget>

#include "src/delegates/tags_delegate.h"
#include "src/models/sort_filter_proxy_model.h"
#include "src/models/tag_assignment_model.h"

class AcntId; /* Forward declaration. */
class MsgId; /* Forward declaration. */
class QAction; /* Forward declaration. */
class QLineEdit; /* Forward declaration. */
class QListView; /* Forward declaration. */
class QPushButton; /* Forward declaration. */
class TagContainer; /* Forward declaration. */

/*!
 * @brief Tags control popup.
 */
class TagsPopupControlWidget : public QWidget {
	Q_OBJECT

public:
	/*!
	 * @brief Constructor.
	 *
	 * @param[in] tagCont Tag container.
	 * @param[in] actionEditAvailableTags Edit available tags action.
	 * @param[in] parent Parent widget.
	 */
	explicit TagsPopupControlWidget(TagContainer *tagCont,
	    QAction *actionEditAvailableTags, QWidget *parent = Q_NULLPTR);

	/*!
	 * @brief Return size hint.
	 *
	 * @return Size hint.
	 */
	virtual
	QSize sizeHint(void) const Q_DECL_OVERRIDE;

	/*!
	 * @brief Set watched message identifiers.
	 *
	 * @param[in] acntId Account identifier.
	 * @param[in] msgIds Set of message IDs, empty set if no assignment
	 *                   should be edited.
	 */
	void setMsgIds(const AcntId &acntId, const QSet<MsgId> &msgIds);

Q_SIGNALS:
	/*!
	 * @brief Widged closed.
	 */
	void controlClosed(void);

private Q_SLOTS:
	/*!
	 * @brief Filter listed tags.
	 */
	void filterTags(const QString &text);

	/*!
	 * @brief Edit all tags.
	 *
	 * @note Triggers m_actionEditAvailableTags. Emits controlClosed.
	 *     Closes the widget.
	 */
	void manageTagsClicked(void);

private:
	QString m_dfltFilerLineStyleSheet; /*!< Used to remember default line edit style. */
	TagsDelegate m_tagsDelegate; /*!< Responsible for painting. */
	TagAssignmentModel m_tagAssignmentModel; /* Tag assignment model. */
	SortFilterProxyModel m_tagListProxyModel; /*!<
	                                           * Used for tag filtering.
	                                           */
	QLineEdit *m_filterLine; /*!< Tag filter line. */
	QListView *m_tagListView; /*!< Tag assignment list. */

	QPushButton *m_manageTagsButton; /*!< Disconnect all sessions button. */
	QAction *m_actionEditAvailableTags; /*!< Edit available tags action. */
};
