/* The model picker's lines (modelpanel.c), in the settings panel's frame (panel.h): a box over the
* transcript, the rows above the footer, or one line. A view with no storage, as panel.c is: the caller
* loads the models (pic models --json), filters and orders them, and says what Enter does; this lays
* them out in aligned columns under a heading per provider, and maps a click back to a row. */
#ifndef PIC_TUI_MODELPANEL_H
#define PIC_TUI_MODELPANEL_H
#include <stddef.h>
#include "width.h"
/* One row: a model, or one of the picker's own actions (model starts with \x01). */
typedef struct {
const char *model; /* provider/id */
const char *name; /* its display name ("" or the id: none shown) */
const char *price; /* "$3/$15" per million tokens in/out, "" when unknown */
const char *status; /* "default", "no key", "key refused", "from proxy", ... joined, or "" */
const char *key; /* which key the model uses (#73); NULL in every row: no column */
const char *about; /* an action row's description */
const char *group; /* the heading it goes under; NULL: its provider's (then the id is shown without it) */
long window; /* its context window in tokens, 0 when unknown */
int avail; /* its provider has a key */
int warn; /* the status is a problem with the key (refused, no credit, rate-limited) */
} tui_mrow;
/* What is shown: ORDER[0..N) index ROWS, SEL is the selected one of them. */
typedef struct {
const tui_mrow *rows;
const size_t *order;
size_t n, sel;
int grouped; /* a heading where the provider changes, and ids without it */
const char *filter; /* what is typed */
const char *current; /* the model in use: ticked */
const char *enter; /* the description's last line: what Enter does now */
const char *hints; /* the keys; wrapped, never cut */
const char *more; /* a dim line at the end of the list ("" or NULL: none) */
} tui_mlist;
typedef struct {
size_t top; /* the first list line shown */
size_t page; /* list lines last drawn */
int form; /* TUI_PANEL_* last drawn */
} tui_mview;
/* List lines for M: its rows, a heading per provider when grouped, the "more" line. */
size_t tui_mpanel_list_len(const tui_mlist *m);
/* The box's lines other than the list at WIDTH: borders, filter, separator, description, wrapped keys. */
size_t tui_mpanel_chrome(const tui_mlist *m, size_t width);
/* The lines, appended to OUT, as tui_panel_lines gives the settings panel's: BOX (WIDTH at least 24) is
* LIST + tui_mpanel_chrome lines; DOCK a title, the filter, LIST lines, the description and the keys;
* LINE the selected model and the keys. The cursor in the filter at *crow, *ccol (-1: hidden). 0 or -1. */
int tui_mpanel_lines(tui_mview *v, const tui_mlist *m, int form, size_t width, size_t list, tui_lines *out, int *crow,
int *ccol);
/* Line LINE of the lines last drawn: the index into ORDER of the row there, or -1 (a heading, a border,
* the filter, a "more" line). */
long tui_mpanel_click(const tui_mview *v, const tui_mlist *m, size_t line);
/* Which models the picker suggests with nothing typed (docs/manual/models.md, "Which models the picker
* suggests"): MODELS[0..N) as listed (provider/id; AVAIL its provider has a key, WARN that key failed),
* RECENT the models used lately, the latest first. Into OUT (room for N): the current model, the default,
* the recent ones, then for each provider whose key works (in list order) the newest model of each family,
* a few per provider; for a provider of other labs' models (ids with a lab before a slash, as
* OpenRouter's) only a few well-known flagships. Models whose key failed only when current. Dated
* snapshots, "latest" aliases and variants (":batch") collapse into their family. How many; *LEAD of
* them, first, are the current, default and recent ones. */
size_t tui_models_suggest(const char *const *models, const int *avail, const int *warn, size_t n, const char *current,
const char *def, const char *const *recent, size_t nrecent, size_t *out, size_t *lead);
/* MODEL's family (lower case, versions and dates taken out: "claude-opus" for claude-opus-4-6) into KEY,
* its version numbers into VER (up to 6), its snapshot date into *DATE (0: none). -1 for a variant
* (an id with a ':'), which is never suggested. */
int tui_model_family(const char *model, char *key, size_t cap, long ver[6], long *date);
#endif