
#ifndef BEATRAT_KEYBINDS_MENU_H
#define BEATRAT_KEYBINDS_MENU_H

#include <X11/Xlib.h>
#include "keybinds.h"

/* Settings > "Keybinds..." opens this overlay -- a scrollable list of
 * every action this build knows about, each showing its current
 * binding(s), with a key-capture flow (highlight a row, press Enter,
 * then press the new key) so rebinding never requires opening
 * keybinds.conf by hand. Same bevel-box look as settings_draw(), and
 * deliberately its own small module rather than folded into settings.c
 * -- it edits keybinds.conf, not settings.conf, and main.c's dialog
 * dispatch already treats "which modal is active" as one flag per
 * dialog, so this is just one more of those, not a sub-mode of
 * Settings itself. */

#define KEYBINDS_MENU_BOX_W          520
#define KEYBINDS_MENU_BOX_H          360
#define KEYBINDS_MENU_LIST_Y         40
#define KEYBINDS_MENU_ROW_H          18
#define KEYBINDS_MENU_VISIBLE_ROWS   15
#define KEYBINDS_MENU_BINDING_COL_X  188

/* Every action except ACTION_NONE (index 0, never user-facing) is one
 * row, in the enum's declaration order. */
#define KEYBINDS_MENU_NUM_ROWS (ACTION_COUNT - 1)

/* Row i's action -- ACTION_NONE is always skipped, so row 0 is
 * ACTION_QUIT (the next value after it). A function rather than a
 * macro so main.c's click/scroll math doesn't need to know that
 * ACTION_NONE is 0 either. */
static inline AppAction keybinds_menu_row_action(int row) {
    return (AppAction)(row + 1);
}

/* scroll_top: index of the first visible row (caller clamps/owns
 * scrolling). selected_idx: the row with the nav highlight -- also
 * what Enter/Delete act on. awaiting_key: true while waiting for the
 * next keypress to become the new binding for the selected row, drawn
 * as a capture prompt in place of that row's current binding text.
 * status_msg (may be "") renders at the bottom -- e.g. a rebind
 * conflict note from keybinds_rebind(). */
void keybinds_menu_draw(const KeyBindMap *kb, Display *dpy, Window win, GC gc,
                         int win_w, int win_h, int scroll_top, int selected_idx,
                         int awaiting_key, const char *status_msg);

#endif
