#pragma once
#include "ui/ui_core.h"
#include "ui/ui_widgets.h"
#include "platform/platform.h"
#include "renderer/renderer.h"

#define MAX_POPUP_WINDOWS 4

typedef struct PopupWindow {
    B32              alive;
    B32             *open_flag;        // e.g. &app->show_settings_window
    PlatformWindow  *platform_window;
    Renderer        *renderer;
    UI_Context      *ui_ctx;
    UI_WidgetState   wstate;
    UI_WindowContentFn content_fn;
    void            *content_user_data;
    S32              width, height;
    S32              last_w, last_h;
    const char      *title;
} PopupWindow;

PopupWindow *popup_open(PlatformWindow *parent_window, Renderer *parent_renderer,
                        const char *title, B32 *open_flag,
                        S32 width, S32 height,
                        UI_WindowContentFn content_fn, void *user_data,
                        PlatformWindowStyle style,
                        B32 independent);
void         popup_close(PopupWindow *popup);
PopupWindow *popup_find_by_flag(B32 *flag);
void         popup_do_frame(PopupWindow *popup, F32 dt);
void         popup_close_all(void);
void         popup_close_check(void);
