#ifndef RENDERER_H
#define RENDERER_H

#include <X11/Xlib.h>
#include "desktop_parser.h"
#include <X11/Xft/Xft.h>

/* ── layout constants ────────────────────────────────────────────────────── */
#define COLS            4       /* fixed: number of columns in grid          */
#define ROWS            3       /* fixed: number of visible rows             */
/* TILE_W, TILE_H, TILE_GAP are runtime values stored in RenderState,
   computed in renderer_init() from the actual screen dimensions.           */

/* Footer height computed at runtime as a fraction of screen height */
#define FOOTER_H_FRAC   0.18f
/* Thickness of the blue border line drawn along the footer curve */
#define FOOTER_BORDER_W 6

/* Tooltip bubble */
#define TOOLTIP_H       36
#define TOOLTIP_PAD_X   20
#define TOOLTIP_PAD_Y   10

/* ── colour palette ──────────────────────────────────────────────────────── */
typedef struct {
    unsigned long bg;
    unsigned long bg2;
    unsigned long tile_face;
    unsigned long tile_shadow_dark;
    unsigned long tile_shadow_mid;
    unsigned long tile_border_focus;
    unsigned long tile_border_norm;
    unsigned long tile_inner_hi;
    unsigned long footer_bg;
    unsigned long footer_border;    /* thick cyan line along footer curve    */
    unsigned long text_dark;
    unsigned long text_med;
    unsigned long text_light;
    unsigned long clock_text;
    unsigned long white;
    unsigned long tooltip_bg;
    unsigned long tooltip_border;
    unsigned long nav_arrow_bg;
    unsigned long nav_arrow_fg;
} WiiColors;

/* ── render state ────────────────────────────────────────────────────────── */
typedef struct {
    Display      *dpy;
    Window        win;
    GC            gc;
    int           screen;
    int           sw, sh;
    Pixmap        backbuf;

    WiiColors     col;
    XFontStruct  *font_title;
    XFontStruct  *font_sub;
    XftFont      *xft_clock;
    XftDraw      *xft_draw;
    XFontStruct  *font_clock;
    XFontStruct  *font_clock_ampm;  /* your large AM/PM font                */
    XFontStruct  *font_date;
    char         *ttf_clock_path;

    AppList      *apps;
    int           scroll_col;
    int           focus_idx;

    /* Animation */
    int           glow_phase;
    int           scroll_anim;
    int           scroll_target;

    /* Grid origin */
    int           grid_x;
    int           grid_y;

    /* Runtime tile dimensions — computed from screen size in renderer_init */
    int           tile_w;
    int           tile_h;
    int           tile_gap;
    int           tile_r;       /* corner radius                             */

    /* Runtime footer height (18% of sh, set in renderer_init) */
    int           footer_h;
} RenderState;

/* ── API ─────────────────────────────────────────────────────────────────── */
void renderer_init(RenderState *rs, Display *dpy, Window win,
                   int screen, int sw, int sh, AppList *apps);
void renderer_free(RenderState *rs);
void renderer_draw(RenderState *rs);
int  renderer_move_focus(RenderState *rs, int dcol, int drow);
void renderer_tick(RenderState *rs);
DesktopEntry *renderer_focused_entry(RenderState *rs);

#endif /* RENDERER_H */