#ifndef PHILOS_UTILS_H
#define PHILOS_UTILS_H
#include "ubl-utils.h"
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <pthread.h>
#include <string.h>
#include <dirent.h>
#include <locale.h>
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#ifdef VTE_TERMINAL
    #include <vte/vte.h>
#endif

#include <pwd.h>
#include <stdbool.h>

#define catch(x) ExitJmp:if(__HadError)
#define throw(x) {__HadError=true;goto ExitJmp;}
#define file_source_login_min_max "/etc/login.defs"
static char** array_size_pow;
typedef struct {
    char** disk_read;
    char** disk_write;
    int* i_o_limit_read;
    int* i_o_limit_write;
    int* i_o_limit_read_size;
    int* i_o_limit_write_size;
    int size;
    int size_disk;
} temp_config;

typedef struct {
    GtkWidget* Window;
    GtkWidget* btnSaveTempSave;
    GtkWidget* btnTempCancel;
    GtkWidget* lblSetUGP;
    GtkWidget* lblHeadQuotasEditWindow;
    
    GtkWidget* btnOpenUserGroup;

    GtkWidget* btnReviewProject;
    GtkWidget* btnGenerateProject;
    GtkWidget* entryCatalogProject;
    GtkWidget* chbAuto;
    GtkWidget* entryProjectName;
    GtkWidget* boxProjectAddEdit;
    GtkWidget* boxProject;
    GtkWidget* lblCatalogProjectEdit;
    GtkWidget* lblProjectIdValueEdit;
    GtkWidget* entryProjectId;
    GtkWidget*  boxTempDevice;
    
    GtkWidget* wndChooseFileWallpaper;
    GtkWidget* btnFilemangerOk;
    GtkWidget* btnFilemangerExit;
    GtkWidget* quotegroupSizeSoftLimitCheck;
    GtkWidget* quotegroupSizeSoftLimitSpin;
    GtkWidget* quotegroupSizeSoftLimitCombo; 
    GtkWidget* quotegroupSizeHardLimitCheck; 
    GtkWidget* quotegroupSizeHardLimitSpin;
    GtkWidget* quotegroupSizeHardLimitCombo;
    GtkWidget* quotegroupFilesSoftLimitCheck;
    GtkWidget* quotegroupFilesSoftLimitSpin; 
    GtkWidget* quotegroupFilesHardLimitCheck;
    GtkWidget* quotegroupFilesHardLimitSpin; 
    GtkWidget* lblSetNameDevice;
    GtkWidget* boxProjectAddEditboxProjectId;
    GtkWidget* entryUser;
    GtkWidget* UserDeviceCombo;
    GtkWidget* lblSetQuotasStatus;
    GtkWidget* lblWarningText;
    GtkWidget* WarrningWindow;
    GtkWidget* CancelWarrningButton;
    GtkWidget* boxBlockGuiAddEdit;
} temp_set_window;

typedef struct {
    char* name;
    int note_selected;
    GtkListStore *liststore;
    GtkWidget* tree_view;
    GtkWidget* btnAdd;
    GtkWidget* btnEdit;
    GtkWidget* btnDel;
    GtkWidget* btnFilter;
    GtkWidget* Update;
    GtkWidget* lblSetNameDevice;
} hotebook;
typedef struct {
    int weeks;
    int days;
    int hours;
    int minutes;
    char* str_time; 
} me_time;

void philos_array_string_remove_char(char*** array, char* str_remove,  int size);
void philos_set_pow_size_memory(char* str_find, int* array_size, char** array_size_pow);
void philos_set_size_memory_integer_char(char* str_find, char*** array_data, int index);
void philos_free_string_array(char ***array, int size);
void philos_free_string_array_n3(char ****array, int size);
void philos_free_int_array(int **array, int size);
void philos_free_int_array_n2(int ***array, int size);
unsigned short philos_read_uid_min_max(char* filename, char* search);
config_str philos_list_user(int* size, int flag_lim);
config_str philos_list_group(int* size, int flag_lim);
char* philos_str_size_pow_byte(GtkWidget *combo_box_text);
char* philos_str_remove(char *str, const char *sub);
void philos_split_size_memory(char* str_value, int* size, char* pow_memory);
char* philos_format_cfg_str_size_memory(char* str_key, int value, int pow_size_memory);
char** philos_str_split(char *parameters, int *size, char *divider);
void philos_array_str_copy(char*** source, char*** copy);
void philos_array_int_copy(int** source, int** copy);
char** philos_pars_terminal_systemd_cgls(char* CMD_GET_SLICE_SERVICE, char* str_find, int* size_array_data);
char* philos_pard_array_add_cmd(char* cmd, temp_config* _config, char* key, int* array_io, int* array_io_pow_size, char** disk, int size);
int philos_check_activ_disk(temp_set_window *widgets, temp_config* _config);
void philos_temp_generate_cmd(temp_set_window *widgets, temp_config* _config);
void philos_temp_del_disk(temp_set_window *widgets, temp_config* _config, int flag_check_array);
void philos_temp_config_init(temp_config* _config);
void philos_update_device_to_entry(temp_set_window *widgets, temp_config* _config, int flag_check_array);
void philos_temp_add_disk(temp_set_window *widgets, temp_config* _config, int flag_check_array);
int* philos_int_append(int* array, int* size, int value);
int* remove_element_int_array(int* array, int* size, int item_to_delete);
int** remove_element_int_array_n3(int** array, int* size, int item_to_delete);
char* philos_get_size_bite(GtkWidget* chk_button, GtkWidget* spin, GtkWidget* combo_box_text);
void philos_fill_combo_box_text(GtkWidget *cbt, config_str list_data, int size);
void philos_set_spin_adjustment(GtkWidget *check, GtkWidget *spin, GtkWidget *combo, size_t value);
void philos_set_active_widgets(GtkWidget *check, GtkWidget *spin, GtkWidget *combo);
size_t get_resurs_total(char* cmd);
float get_size_pow_memory(size_t size_memory, int size);
void philos_set_active_widgets_device_io(GtkWidget* combo_to_l2,GtkWidget *check, GtkWidget *spin, GtkWidget *combo);
char *yon_char_get_augumented(char *source, char *append);
dictionary *yon_dictionary_create_with_data_connected(dictionary *dict, char *key, void *data);
char **yon_char_parsed_shrink(char **char_string, int *size, int item_to_delete);
char*** yon_char_parsed_shrink_n3(char ***char_string, int *size, int item_to_delete);
dictionary *yon_dictionary_create_empty();
void yon_terminal_integrated_launch(GtkWidget *terminal, char* command, void *endwork_function, void* endwork_function_argument);
dictionary *yon_dictionary_create_conneced(dictionary *targetdict);
void yon_int_array_append(int **source, int append);
#ifdef VTE_TERMINAL
static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data);
#endif
int philos_config_save(char *command);
void philos_array_int_pars_to(int** array, int to);
void philos_array_char_pars_to(char*** array, char* to);
int find_null_array(temp_config* _config);
void init_device_disk(temp_config* _config);
char** philos_char_parsed_append(char** parsed, int *size, char *string);
void philos_set_size_memory_integer(char* str_find, size_t* array_data);
me_time time_convert(size_t seconds);
char* fill_tree_view_id(int id);
char *philos_char_from_size_t(size_t int_to_convert);
size_t philos_convert_memory(char* num_memory_pow);

#endif