#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>
#ifdef WEBKIT_INCLUDE
    #include <webkit2/webkit2.h>
#endif 
#include "ubl-strings.h"

#define _(String) gettext(String)

#define glade_path "/com/ublinux/ui/ubl-settings-fstecadvised.glade"
#define glade_path_test_element "/com/ublinux/ui/ubl-settings-fstecadvised-test-element.glade"
#define CssPath "/com/ublinux/css/ubl-settings-fstecadvised.css"
#define config_path yon_char_unite(yon_ubl_user_get_home_directory(),"/.config/",LocaleName,"/",LocaleName,".conf",NULL)
#define icon_path "com.ublinux.ubl-settings-fstecadvised"

#define LocaleName "ubl-settings-fstecadvised"
#define fstec_list_command "fstec-hardening-advised --list --csv --nocolor"
#define fstec_test_command "fstec-hardening-advised --test --csv --nocolor"
#define fstec_test_apply_command "fstec-hardening-advised --test --apply --csv --nocolor"

#define config_get_command(target) yon_char_unite("ubconfig --source ",target," get security FSTEC_HARDENING_ADVISED",NULL)
#define config_get_default_command ""

#define config_get_global_only_parameters ""
#define config_get_local_only_parameters ""

#define FSTEC_parameter "FSTEC_HARDENING_ADVISED"
#define FSTEC_parameter_command "ubconfig --source global get security FSTEC_HARDENING_ADVISED"

typedef char* string;

__attribute__((unused)) static \
string version_application;

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

extern config main_config;

typedef struct {
    template_window_fields;
    GtkWidget *TestStartButton;
    GtkWidget *TestListbox;
    GtkWidget *ConfigureSystemSwitch;
    GtkWidget *WarningLabel;
    GtkWidget *LoadingOverlay;
    GtkWidget *LoadingSpinner;
} main_window;

typedef struct {
    GtkWidget *TestRow;
    GtkWidget *TestNameLabel;
    GtkWidget *TestStatusLabel;
    GtkWidget *TestSeparator;
} test_row_element;

struct test_struct {
    char *group;
    char *test_name;
    char *test_status;
};

struct idle_struct {
    main_window *widgets;
    config_str test_result;
    int size;
};

void on_save_done(main_window *, config_str output, int size);
void on_config_global_local_save(GtkWidget *, main_window *);
void on_config_local_save(GtkWidget *, main_window *);
void on_config_global_save(GtkWidget *, main_window *);
void on_config_custom_save(GtkWidget *, main_window *);
void on_config_local_load(GtkWidget *,main_window *);
void on_config_global_load(GtkWidget *,main_window *);
void on_config_custom_load(GtkWidget *,main_window *);

void yon_load_proceed(YON_CONFIG_TYPE type);

gboolean yon_interface_update(main_window *);

void config_init();

main_window *yon_main_window_complete(main_window *widgets);

void on_test_start(GtkWidget *, main_window *widgets);

gboolean on_configure_fstec_toggled(GtkWidget *, int, main_window *widgets);
test_row_element *yon_test_row_element_new();
void yon_row_element_append(main_window *widgets, char *test_name, char *status);
void yon_test_clear(main_window *widgets);
void yon_test_tab_resize(main_window *widgets);
test_row_element *yon_test_row_element_title_new();
void yon_row_element_append_title(main_window *widgets, char *test_name);
struct test_struct *yon_test_get_struct(char *testline);
void yon_test_parse(struct idle_struct *temp_struct);
void yon_startup_tests_list(main_window *widgets);