#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <locale.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <libintl.h>
#include <getopt.h>
#include <libublsettings.h>
#include <libublsettings-gtk3.h>
#include <libublsettingsui-gtk3.h>
//#include <vte/vte.h>
#include <webkit2/webkit2.h>
#include "ubl-strings.h"

#define _(String) gettext(String)

#define glade_path "/com/ublinux/ui/ubhello.glade"
#define glade_path_app "/com/ublinux/ui/ubhello-app.glade"
#define glade_path_quick_start "/com/ublinux/ui/ubhello-quick-start.glade"
#define glade_path_resource "/com/ublinux/ui/ubhello-resource.glade"
#define CssPath "/com/ublinux/css/ubhello.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define icon_path "com.ublinux.ubhello"
#define apps_path "resource:///com/ublinux/csv/apps.csv"
#define docs_path "resource:///com/ublinux/csv/docs.csv"
#define links_path "resource:///com/ublinux/csv/links.csv"
#define base_uri "/usr/share/ubhello/wiki/"

#define markdown_path "/usr/share/ubhello/wiki/"

#define languages_search_path "/usr/share/ubhello/wiki"

#define LocaleName "ubhello"

#define config_get_command(target) yon_char_unite("ubconfig --source ",target," get [system] FIRSTSTART -- get [locale] LANG LOCALE",NULL)

#define FIRSTSTART_parameter "FIRSTSTART"
#define FIRSTSTART_parameter_on_command "ubconfig --target system set [system] FIRSTSTART"
#define FIRSTSTART_parameter_off_command "ubconfig --target system remove [system] FIRSTSTART"

#define LANG_parameter "LANG"
#define LANG_parameter_command "ubconfig --source global get [locale] LANG"

#define LOCALE_parameter "LOCALE"
#define LOCALE_parameter_on_command "ubconfig --source global get [locale] LOCALE"
typedef char* string;

__attribute__((unused)) static \
string version_application;

typedef struct {
    template_config_fields
    int save_config;
    config_str launch_arguments;
    int launch_size;
    int firststart;
} config;

extern config main_config;

typedef struct {
    template_window_fields
    GtkWidget *QuickStartList;
    GtkWidget *ManagementFlow;
    GtkWidget *WebkitSwitch;
    GtkWidget *ResourcesFlow;
    GtkWidget *LanguageCombo;
    GtkWidget *StartupSwitch;
    GtkWidget *MainOverlay;
    GtkWidget *BackButton;
} main_window;

typedef struct {
    GtkWidget *MainRow;
    GtkWidget *AppIcon;
    GtkWidget *AppLabel;
    apps *app;
} app_struct;

typedef struct {
    GtkWidget *MainRow;
    GtkWidget *AppIcon;
    GtkWidget *AppLabel;

    char *link;
} resource_struct;

typedef struct {
    GtkWidget *MainRow;
    GtkWidget *AppIcon;
    GtkWidget *AppLabel;
    
    char *file_path;
} quick_start_struct;


void yon_load_proceed();

gboolean yon_interface_update(main_window *);

void config_init();

main_window *yon_main_window_complete(main_window *widgets);
resource_struct *yon_resource_struct_new();
app_struct *yon_app_struct_new();
quick_start_struct *yon_quick_start_struct_new();
void on_resource_activate(GtkWidget *, GtkWidget *row, main_window *);
void on_app_activate(GtkWidget *, GtkWidget *row, main_window *);
void on_quick_start_activate(GtkWidget *, GtkWidget *row, main_window *widgets);
gboolean on_ubhello_reopen(GtkWidget *, guint state, main_window *);
void on_translation_changed(GtkWidget *, main_window *);
void yon_title_info_translate(GtkWidget *title_label);
void on_app_translate(GtkWidget *row);
void on_back_clicked(GtkWidget *, GtkWidget *socket);
void on_plug_connected(GtkSocket *self, main_window *widgets);
void on_plug_disconnected(GtkSocket *self, main_window *widgets);
void on_quick_start_close(GtkWidget *, main_window *widgets);
void yon_language_update(GtkWidget *target);
gboolean yon_interface_update(main_window *widgets);
void yon_window_translate(GtkWidget *target);