#ifndef HUSH_RENDER_H
#define HUSH_RENDER_H

#include "editor.h"
#include "layout_cache.h"
#include "app_mode.h"
#include "fonts.h"
#include "clay.h"
#include "image_cache.h"
#include <SDL.h>

/* Declared (not defined) here because vendor/clay_renderer_SDL2.c has no header of its own;
   it is compiled once, into src/clay_impl.c. */
void Clay_SDL2_Render(SDL_Renderer *renderer, Clay_RenderCommandArray renderCommands, SDL2_Font *fonts);

/* Registered with Clay_SetMeasureTextFunction (userData = the SDL2_Font[FONT_COUNT] array).
   UTF-8 aware (TTF_SizeUTF8), so accented characters (e.g. Swedish å ä ö) measure correctly. */
Clay_Dimensions hush_measure_text(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData);

/* Builds the Clay tree for the current editor state, populates `cache` fresh (consumed by
   hit-testing on the *next* frame's input), issues the Clay render commands, and draws the
   blinking caret on top. Call between SDL_RenderClear/SDL_RenderPresent, after
   Clay_SetPointerState/Clay_SetLayoutDimensions/Clay_UpdateScrollContainers.
   `renderer` is used both for Clay_SDL2_Render and for the raw post-Clay overlay draws (caret,
   selection highlight, strikethrough). `mouseLeftPressed` is this frame's left-click edge (Clay
   itself has no input polling under SDL2, so render.c's internal click checks -- task
   checkboxes, modal buttons, click-outside-to-cancel -- need it passed in). `winW`/`winH` are
   the current window size in pixels (main.c already computes these for Clay_SetLayoutDimensions
   that same frame).
   When `mode` is not MODE_EDITING, also draws the corresponding modal on top and returns
   whichever action the user's click resolved to this frame (MODAL_ACTION_NONE otherwise).
   `*outToggledTaskBlock` is set to the block index of a task-list checkbox clicked this frame,
   or -1 if none (ignored if NULL) -- caller should follow up with editor_toggle_task.
   `openPrompt` is read (never NULL) for MODE_OPEN_PROMPT's typed-path text field; ignored
   otherwise. `confirmForOpen` disambiguates MODE_QUIT_CONFIRM's wording: true if it's guarding
   Ctrl+O (unsaved changes before opening another file) rather than Ctrl+X (quitting).
   `turnIntoMenu` is read (never NULL, ignored outside MODE_EDITING) for the left-margin "Turn
   Into" popup anchored to ed->cursorBlock. `quickInsertMenu` is read (never NULL, ignored outside
   MODE_EDITING) for the "@" quick-insert popup, also anchored to ed->cursorBlock -- caller is
   responsible for the two never being open at once. `outMenuClick` (never NULL) is reset every
   call and filled in with whichever block-type menu row/icon/outside-click the frame's click
   resolved to, if any -- caller applies the result after render_frame returns. `imageCache` is
   the process-lifetime image cache (see image_cache.h) used to render BLOCK_IMAGE blocks. */
ModalAction render_frame(EditorState *ed, LayoutCache *cache, SDL2_Font *fonts, SDL_Renderer *renderer,
                          bool mouseLeftPressed, float winW, float winH, float deltaTime, float caretBlinkT, AppMode mode,
                          int *outToggledTaskBlock, const OpenPromptState *openPrompt, bool confirmForOpen,
                          const TurnIntoMenuState *turnIntoMenu, const QuickInsertMenuState *quickInsertMenu,
                          BlockTypeMenuClickResult *outMenuClick, ImageCache *imageCache);

#endif
