#pragma once
#include <Windows.h>
#include <vector>
#include "raylib.h"

// 窗口拖拽状态
struct WindowDragState
{
    bool dragging = false;
    bool wasDown = false;
    POINT mouseStart{};
    POINT windowStart{};
};

class Initialization
{
public:
    static Initialization* Get();

    bool Init_Windows();
    void Renderer();
    void UpdateWindowDrag();    // 每帧调用，更新窗口拖拽
    void Clear();

    void Set_Flags(int New_Flags);
    void Set_WinSize(RLVector2 New_WinSize);
    bool Set_Tittle(const char* New_Tittle);
    void Clear_Flags(int New_Flags);

    RLVector2 Get_WinSize() const { return Win_size; }
    const char* Get_WinTittle() const { return Win_Tittle; }

    void SetDragEnabled(bool enabled) { m_dragEnabled = enabled; }
    bool IsDragEnabled() const { return m_dragEnabled; }

    void RequestClose() { m_requestClose = true; }
    bool ShouldClose() const { return m_requestClose; }

    // 注册拖拽屏蔽区域（窗口局部坐标），鼠标在此区域内按下不会触发拖拽
    // 每帧需先 ClearDragBlockRegions() 再重新注册
    void AddDragBlockRegion(RLRectangle Rect);
    void ClearDragBlockRegions();

    // 将窗口限制在当前显示器工作区内
    static int Clamp(int v, int min, int max) { return (v < min) ? min : (v > max ? max : v); }

	void SetFailedToFindPattern(bool failed) { m_failed_to_find_pattern = failed; }
	bool GetFailedToFindPattern() const { return m_failed_to_find_pattern; }

private:
    bool IsMouseInBlockRegion() const;

    Initialization() :Win_size({600,420}) {};
    ~Initialization() = default;

    RLVector2 Win_size = { 0,0 };
    int Win_Flags = 0;
    const char* Win_Tittle = "skeet_loader";

    bool m_dragEnabled = true;
    bool m_requestClose = false;
    WindowDragState m_drag;
    std::vector<RLRectangle> m_dragBlockRegions;

    bool m_failed_to_find_pattern = false;
};
