#pragma once

#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <shellapi.h>
#include <string>

namespace poe2::ui {

constexpr UINT WM_TRAYICON = WM_USER + 101;

constexpr UINT ID_TRAY_TITLE      = 2001;
constexpr UINT ID_TRAY_STATUS     = 2002;
constexpr UINT ID_TRAY_SETTINGS   = 2003;
constexpr UINT ID_TRAY_PANIC      = 2004;
constexpr UINT ID_TRAY_STREAMER   = 2005;
constexpr UINT ID_TRAY_RESET_ZOOM = 2006;
constexpr UINT ID_TRAY_EXIT       = 2007;

class SystemTray {
public:
    SystemTray() = default;
    ~SystemTray();

    SystemTray(const SystemTray&) = delete;
    SystemTray& operator=(const SystemTray&) = delete;
    SystemTray(SystemTray&& other) noexcept;
    SystemTray& operator=(SystemTray&& other) noexcept;

    /// @brief Khởi tạo icon khay hệ thống (System Tray)
    bool Create(HWND hWnd, HINSTANCE hInstance, UINT callbackMsg = WM_TRAYICON);

    /// @brief Hủy icon khỏi khay hệ thống
    void Destroy();

    /// @brief Cập nhật trạng thái hiển thị trên Tooltip khay hệ thống
    void UpdateStatus(bool attached, uint32_t pid, float currentZoom, float maxZoom);

    /// @brief Hiển thị Context Menu khi người dùng nhấp chuột phải vào Tray Icon
    void ShowContextMenu(HWND hWnd, bool streamerMode, bool attached);

    bool IsCreated() const noexcept { return created_; }

private:
    HICON CreateProgrammaticIcon(HINSTANCE hInstance);

    HWND hWnd_ = nullptr;
    HICON hIcon_ = nullptr;
    bool created_ = false;
    NOTIFYICONDATAW nid_{};
    std::wstring lastTip_;
};

} // namespace poe2::ui
