#ifndef GUI_H
#define GUI_H

#include "irc_client.h"
#include "config.h"

#if defined(__has_include)
#  if __has_include(<ncurses.h>)
#    include <ncurses.h>
#  elif __has_include(<curses.h>)
#    include <curses.h>
#  else
#    error "Neither ncurses.h nor curses.h is available"
#  endif
#else
#  include <curses.h>
#endif

#include <time.h>

#define MAX_CHAT_LINES 1000
#define MAX_MESSAGE_LENGTH 512
#define INPUT_BUFFER_SIZE 512

typedef struct {
    char nick[64];
    char message[MAX_MESSAGE_LENGTH];
    time_t timestamp;
    int is_status;
} chat_line_t;

typedef struct {
    WINDOW *main_win;
    WINDOW *chat_win;
    WINDOW *input_win;
    WINDOW *status_win;
    WINDOW *users_win;
    WINDOW *channels_win;

    int max_x, max_y;
    int chat_scroll_pos;
    int input_pos;
} gui_state_t;

extern gui_state_t g_gui;
extern chat_line_t g_chat_buffer[MAX_CHAT_LINES];
extern int g_chat_line_count;

int gui_init(void);
void gui_cleanup(void);
void gui_refresh_all(irc_client_t *client);
void gui_main_loop(irc_client_t *client, volatile int *should_exit);
void gui_show_connection_dialog(irc_client_t *client);
void gui_add_message(const char *nick, const char *message);
void gui_add_status(const char *status);
void gui_add_notice(const char *format, ...);
void gui_clear_chat(void);
void gui_scroll_up(int lines);
void gui_scroll_down(int lines);
int gui_get_input(char *buffer, int max_len);
void gui_signal_handler(int sig);

#endif
