/*
 * DWN - Desktop Window Manager
 * retoor <retoor@molodetz.nl>
 * News ticker for bottom panel
 */

#ifndef DWN_NEWS_H
#define DWN_NEWS_H

#include "dwn.h"
#include <stdbool.h>

#define MAX_NEWS_ARTICLES 50
#define NEWS_API_URL "https://news.app.molodetz.nl/api"

typedef enum {
    SENTIMENT_NEUTRAL = 0,
    SENTIMENT_POSITIVE,
    SENTIMENT_NEGATIVE
} NewsSentiment;

typedef struct {
    char title[256];
    char content[1024];
    char link[512];
    char author[128];
    NewsSentiment sentiment;
    float sentiment_score;
} NewsArticle;

typedef struct {
    NewsArticle articles[MAX_NEWS_ARTICLES];
    int article_count;
    int current_article;
    double scroll_offset;
    bool fetching;
    bool has_error;
    long last_fetch;
    long last_scroll_update;
    bool interactive_mode;
    int display_widths[MAX_NEWS_ARTICLES];
    int total_width;
    int render_x;
    int render_width;
    bool widths_dirty;
} NewsState;

extern NewsState news_state;

void news_init(void);
void news_cleanup(void);

void news_fetch_async(void);
void news_update(void);

void news_next_article(void);
void news_prev_article(void);
void news_open_current(void);

void news_render(Panel *panel, int x, int max_width, int *used_width);
void news_handle_click(int x, int y);

void news_lock(void);
void news_unlock(void);

#endif
