#pragma once

#include <gtkmm/dialog.h>
#include <gtkmm/box.h>
#include <gtkmm/listbox.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <gtkmm/entry.h>
#include <gtkmm/popover.h>

#include "DatabaseManager.hpp"

class TagManagerDialog : public Gtk::Dialog {
public:
  TagManagerDialog(Gtk::Window& parent, DatabaseManager& db);

  // Signal emitted when tags are modified (so caller can refresh book list)
  sigc::signal<void()>& signalTagsModified() { return m_signalTagsModified; }

private:
  void refresh_tag_list();
  Gtk::Widget* create_tag_row(const DatabaseManager::TagInfo& tag);
  void on_rename_tag(const std::string& old_name);
  void on_delete_tag(const std::string& tag_name);
  void on_cleanup_clicked();

  DatabaseManager& m_db;

  Gtk::Box m_contentBox {Gtk::Orientation::VERTICAL};
  Gtk::ScrolledWindow m_scrolled;
  Gtk::ListBox m_tagList;
  Gtk::Box m_buttonBox {Gtk::Orientation::HORIZONTAL};
  Gtk::Button m_cleanupButton;
  Gtk::Label m_emptyLabel;

  // Rename popover
  Gtk::Popover m_renamePopover;
  Gtk::Box m_renameBox {Gtk::Orientation::VERTICAL};
  Gtk::Entry m_renameEntry;
  Gtk::Button m_renameApplyButton;
  std::string m_renameOldName;

  sigc::signal<void()> m_signalTagsModified;
};
