#ifndef UI_H
#define UI_H

#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <time.h>

#include "channel.h"
#include "theme.h"

typedef struct UiFonts {
    TTF_Font *small;
    TTF_Font *medium;
    TTF_Font *large;
} UiFonts;

typedef struct UiTextTexture {
    SDL_Texture *texture;
    int width;
    int height;
} UiTextTexture;

typedef struct UiChannelCache {
    UiTextTexture name_medium;
    UiTextTexture number_medium;
    UiTextTexture file_small;
    UiTextTexture program_small_light;
    UiTextTexture program_medium_dark;
    UiTextTexture detail_small_dark;
} UiChannelCache;

typedef struct UiCache {
    SDL_Renderer *renderer;
    UiTextTexture no_media_title;
    UiTextTexture no_media_body;
    UiTextTexture no_media_hint;
    UiTextTexture footer_a;
    UiTextTexture footer_time;
    UiTextTexture footer_b;
    UiTextTexture footer_theme;
    UiTextTexture footer_c;
    UiTextTexture footer_title;
    UiTextTexture *timeline_labels;
    time_t timeline_label_slot;
    const GuideTheme *timeline_theme;
    UiChannelCache *channels;
    int channel_count;
    SDL_Texture *logo_texture;
} UiCache;

void ui_render_fullscreen(SDL_Renderer *renderer,
                          SDL_Texture *video_texture,
                          int texture_width,
                          int texture_height,
                          int window_width,
                          int window_height,
                          const GuideTheme *theme,
                          const UiFonts *fonts,
                          const ChannelList *channels,
                          int active_channel,
                          time_t app_start_time,
                          time_t now_wall,
                          int show_channel_banner,
                          const char *numeric_input_buffer,
                          int numeric_input_length,
                          int numeric_input_invalid);
void ui_render_guide(SDL_Renderer *renderer,
                     SDL_Texture *video_texture,
                     int texture_width,
                     int texture_height,
                     int window_width,
                     int window_height,
                     const GuideTheme *theme,
                     const UiFonts *fonts,
                     UiCache *cache,
                     const ChannelList *channels,
                     int active_channel,
                     int selected_channel,
                     time_t app_start_time,
                     time_t now_wall,
                     int guide_time_offset_minutes);
void ui_render_theme_picker(SDL_Renderer *renderer,
                            const UiFonts *fonts,
                            int window_width,
                            int window_height,
                            const GuideTheme *active_theme,
                            int current_theme_index,
                            int selected_theme_index);
void ui_render_about_modal(SDL_Renderer *renderer,
                           const UiFonts *fonts,
                           int window_width,
                           int window_height,
                           const GuideTheme *active_theme);
void ui_render_no_media(SDL_Renderer *renderer, const UiCache *cache, int window_width, int window_height);
int ui_load_fonts(UiFonts *fonts);
void ui_destroy_fonts(UiFonts *fonts);
int ui_cache_init(UiCache *cache, SDL_Renderer *renderer, const UiFonts *fonts, const ChannelList *channels);
void ui_cache_destroy(UiCache *cache);

#endif
