#pragma once

#include "lumacs/ui_interface.hpp"
#include <functional>

namespace lumacs {

// Forward declarations
class EditorCore;

/// @brief Handles the common mode activation logic for editor events.
///
/// This class centralizes the minibuffer activation code that was previously
/// duplicated between TUI and GTK frontends. It provides default callbacks
/// for each mode while allowing frontends to customize quit behavior.
class ModeActivator {
public:
    /// @brief Callback invoked when the user confirms quitting.
    using QuitCallback = std::function<void()>;

    explicit ModeActivator(EditorCore& core);

    /// @brief Handle a mode-related editor event.
    /// @param event The editor event to handle.
    /// @param quit_callback Callback to invoke for quit commands (nullptr to ignore quit).
    /// @return true if the event was handled, false otherwise.
    bool handle_mode_event(EditorEvent event, QuitCallback quit_callback = nullptr);

private:
    EditorCore& core_;

    void activate_command_mode(QuitCallback quit_callback);
    void activate_buffer_switch_mode();
    void activate_kill_buffer_mode();
    void activate_find_file_mode();
    void activate_theme_selection_mode();
    void activate_isearch_mode(bool forward);
};

} // namespace lumacs
