/* ItemChangeHistory.c generated by valac 0.56.19, the Vala compiler
 * generated from ItemChangeHistory.vala, do not modify */

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include <adwaita.h>
#include <glib-object.h>
#include "planify.h"
#include <gtk/gtk.h>
#include <glib.h>
#include <gee.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <pango/pango.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DIALOGS_TYPE_ITEM_CHANGE_HISTORY (dialogs_item_change_history_get_type ())
#define DIALOGS_ITEM_CHANGE_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistory))
#define DIALOGS_ITEM_CHANGE_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistoryClass))
#define DIALOGS_IS_ITEM_CHANGE_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIALOGS_TYPE_ITEM_CHANGE_HISTORY))
#define DIALOGS_IS_ITEM_CHANGE_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DIALOGS_TYPE_ITEM_CHANGE_HISTORY))
#define DIALOGS_ITEM_CHANGE_HISTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistoryClass))

typedef struct _DialogsItemChangeHistory DialogsItemChangeHistory;
typedef struct _DialogsItemChangeHistoryClass DialogsItemChangeHistoryClass;
typedef struct _DialogsItemChangeHistoryPrivate DialogsItemChangeHistoryPrivate;
enum  {
	DIALOGS_ITEM_CHANGE_HISTORY_0_PROPERTY,
	DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY,
	DIALOGS_ITEM_CHANGE_HISTORY_NUM_PROPERTIES
};
static GParamSpec* dialogs_item_change_history_properties[DIALOGS_ITEM_CHANGE_HISTORY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW (widgets_item_change_history_row_get_type ())
#define WIDGETS_ITEM_CHANGE_HISTORY_ROW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW, WidgetsItemChangeHistoryRow))
#define WIDGETS_ITEM_CHANGE_HISTORY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW, WidgetsItemChangeHistoryRowClass))
#define WIDGETS_IS_ITEM_CHANGE_HISTORY_ROW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW))
#define WIDGETS_IS_ITEM_CHANGE_HISTORY_ROW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW))
#define WIDGETS_ITEM_CHANGE_HISTORY_ROW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW, WidgetsItemChangeHistoryRowClass))

typedef struct _WidgetsItemChangeHistoryRow WidgetsItemChangeHistoryRow;
typedef struct _WidgetsItemChangeHistoryRowClass WidgetsItemChangeHistoryRowClass;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _DialogsItemChangeHistory {
	AdwDialog parent_instance;
	DialogsItemChangeHistoryPrivate * priv;
};

struct _DialogsItemChangeHistoryClass {
	AdwDialogClass parent_class;
};

struct _DialogsItemChangeHistoryPrivate {
	ObjectsItem* _item;
	GtkListBox* listbox;
	GtkScrolledWindow* listbox_scrolled;
	gint start_week;
	gint end_week;
	gboolean _loading;
	GeeHashMap* signal_map;
};

static gint DialogsItemChangeHistory_private_offset;
static gpointer dialogs_item_change_history_parent_class = NULL;

VALA_EXTERN GType dialogs_item_change_history_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DialogsItemChangeHistory, g_object_unref)
VALA_EXTERN DialogsItemChangeHistory* dialogs_item_change_history_new (ObjectsItem* item);
VALA_EXTERN DialogsItemChangeHistory* dialogs_item_change_history_construct (GType object_type,
                                                                 ObjectsItem* item);
static void dialogs_item_change_history_fetch_data (DialogsItemChangeHistory* self);
VALA_EXTERN ObjectsItem* dialogs_item_change_history_get_item (DialogsItemChangeHistory* self);
VALA_EXTERN WidgetsItemChangeHistoryRow* widgets_item_change_history_row_new (ObjectsObjectEvent* object_event);
VALA_EXTERN WidgetsItemChangeHistoryRow* widgets_item_change_history_row_construct (GType object_type,
                                                                        ObjectsObjectEvent* object_event);
VALA_EXTERN GType widgets_item_change_history_row_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WidgetsItemChangeHistoryRow, g_object_unref)
static void dialogs_item_change_history_header_completed_function (DialogsItemChangeHistory* self,
                                                            GtkListBoxRow* lbrow,
                                                            GtkListBoxRow* lbbefore);
VALA_EXTERN ObjectsObjectEvent* widgets_item_change_history_row_get_object_event (WidgetsItemChangeHistoryRow* self);
static GtkWidget* dialogs_item_change_history_get_header_box (DialogsItemChangeHistory* self,
                                                       const gchar* title);
static GtkWidget* dialogs_item_change_history_build_card (DialogsItemChangeHistory* self,
                                                   const gchar* icon_name,
                                                   const gchar* header,
                                                   const gchar* value);
VALA_EXTERN void dialogs_item_change_history_clean_up (DialogsItemChangeHistory* self);
static void dialogs_item_change_history_set_item (DialogsItemChangeHistory* self,
                                           ObjectsItem* value);
static GObject * dialogs_item_change_history_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _dialogs_item_change_history_header_completed_function_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                             GtkListBoxRow* before,
                                                                                             gpointer self);
static void _dialogs_item_change_history___lambda215_ (DialogsItemChangeHistory* self);
static void __dialogs_item_change_history___lambda215__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                              gpointer self);
static void _dialogs_item_change_history___lambda216_ (DialogsItemChangeHistory* self);
static void __dialogs_item_change_history___lambda216__adw_dialog_closed (AdwDialog* _sender,
                                                                   gpointer self);
static void dialogs_item_change_history_finalize (GObject * obj);
static GType dialogs_item_change_history_get_type_once (void);
static void _vala_dialogs_item_change_history_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_dialogs_item_change_history_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
dialogs_item_change_history_get_instance_private (DialogsItemChangeHistory* self)
{
	return G_STRUCT_MEMBER_P (self, DialogsItemChangeHistory_private_offset);
}

DialogsItemChangeHistory*
dialogs_item_change_history_construct (GType object_type,
                                       ObjectsItem* item)
{
	DialogsItemChangeHistory * self = NULL;
	g_return_val_if_fail (item != NULL, NULL);
	self = (DialogsItemChangeHistory*) g_object_new (object_type, "item", item, "title", _ ("Change History"), "content-width", 450, "content-height", 500, NULL);
	return self;
}

DialogsItemChangeHistory*
dialogs_item_change_history_new (ObjectsItem* item)
{
	return dialogs_item_change_history_construct (DIALOGS_TYPE_ITEM_CHANGE_HISTORY, item);
}

static void
dialogs_item_change_history_fetch_data (DialogsItemChangeHistory* self)
{
	GeeArrayList* events = NULL;
	ServicesDatabase* _tmp0_;
	ServicesDatabase* _tmp1_;
	ObjectsItem* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	GeeArrayList* _tmp5_;
	GeeArrayList* _tmp6_;
	GtkListBox* _tmp19_;
	g_return_if_fail (self != NULL);
	_tmp0_ = services_database_get_default ();
	_tmp1_ = _tmp0_;
	_tmp2_ = self->priv->_item;
	_tmp3_ = objects_base_object_get_id ((ObjectsBaseObject*) _tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = services_database_get_events_by_item (_tmp1_, _tmp4_, self->priv->start_week, self->priv->end_week);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp1_);
	events = _tmp6_;
	{
		GeeArrayList* _object_event_list = NULL;
		GeeArrayList* _tmp7_;
		gint _object_event_size = 0;
		GeeArrayList* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		gint _object_event_index = 0;
		_tmp7_ = events;
		_object_event_list = _tmp7_;
		_tmp8_ = _object_event_list;
		_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
		_tmp10_ = _tmp9_;
		_object_event_size = _tmp10_;
		_object_event_index = -1;
		while (TRUE) {
			gint _tmp11_;
			gint _tmp12_;
			ObjectsObjectEvent* object_event = NULL;
			GeeArrayList* _tmp13_;
			gpointer _tmp14_;
			GtkListBox* _tmp15_;
			ObjectsObjectEvent* _tmp16_;
			WidgetsItemChangeHistoryRow* _tmp17_;
			WidgetsItemChangeHistoryRow* _tmp18_;
			_object_event_index = _object_event_index + 1;
			_tmp11_ = _object_event_index;
			_tmp12_ = _object_event_size;
			if (!(_tmp11_ < _tmp12_)) {
				break;
			}
			_tmp13_ = _object_event_list;
			_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _tmp13_, _object_event_index);
			object_event = (ObjectsObjectEvent*) _tmp14_;
			_tmp15_ = self->priv->listbox;
			_tmp16_ = object_event;
			_tmp17_ = widgets_item_change_history_row_new (_tmp16_);
			g_object_ref_sink (_tmp17_);
			_tmp18_ = _tmp17_;
			gtk_list_box_append (_tmp15_, (GtkWidget*) _tmp18_);
			_g_object_unref0 (_tmp18_);
			_g_object_unref0 (object_event);
		}
	}
	_tmp19_ = self->priv->listbox;
	gtk_list_box_invalidate_headers (_tmp19_);
	_g_object_unref0 (events);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
dialogs_item_change_history_header_completed_function (DialogsItemChangeHistory* self,
                                                       GtkListBoxRow* lbrow,
                                                       GtkListBoxRow* lbbefore)
{
	WidgetsItemChangeHistoryRow* row = NULL;
	WidgetsItemChangeHistoryRow* _tmp0_;
	WidgetsItemChangeHistoryRow* _tmp1_;
	ObjectsObjectEvent* _tmp2_;
	ObjectsObjectEvent* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	WidgetsItemChangeHistoryRow* _tmp17_;
	WidgetsItemChangeHistoryRow* _tmp18_;
	ObjectsObjectEvent* _tmp19_;
	ObjectsObjectEvent* _tmp20_;
	GDateTime* _tmp21_;
	GDateTime* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	GtkWidget* _tmp25_;
	GtkWidget* _tmp26_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (lbrow != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (lbrow, WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW, WidgetsItemChangeHistoryRow));
	row = _tmp0_;
	_tmp1_ = row;
	_tmp2_ = widgets_item_change_history_row_get_object_event (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = objects_object_event_get_event_date (_tmp3_);
	_tmp5_ = _tmp4_;
	if (g_strcmp0 (_tmp5_, "") == 0) {
		_g_object_unref0 (row);
		return;
	}
	if (lbbefore != NULL) {
		WidgetsItemChangeHistoryRow* before = NULL;
		WidgetsItemChangeHistoryRow* _tmp6_;
		WidgetsItemChangeHistoryRow* _tmp7_;
		ObjectsObjectEvent* _tmp8_;
		ObjectsObjectEvent* _tmp9_;
		GDateTime* _tmp10_;
		GDateTime* _tmp11_;
		WidgetsItemChangeHistoryRow* _tmp12_;
		ObjectsObjectEvent* _tmp13_;
		ObjectsObjectEvent* _tmp14_;
		GDateTime* _tmp15_;
		GDateTime* _tmp16_;
		_tmp6_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (lbbefore, WIDGETS_TYPE_ITEM_CHANGE_HISTORY_ROW, WidgetsItemChangeHistoryRow));
		before = _tmp6_;
		_tmp7_ = before;
		_tmp8_ = widgets_item_change_history_row_get_object_event (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = objects_object_event_get_date (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = row;
		_tmp13_ = widgets_item_change_history_row_get_object_event (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp15_ = objects_object_event_get_date (_tmp14_);
		_tmp16_ = _tmp15_;
		if (g_date_time_compare (_tmp11_, _tmp16_) == 0) {
			_g_object_unref0 (before);
			_g_object_unref0 (row);
			return;
		}
		_g_object_unref0 (before);
	}
	_tmp17_ = row;
	_tmp18_ = row;
	_tmp19_ = widgets_item_change_history_row_get_object_event (_tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = objects_object_event_get_date (_tmp20_);
	_tmp22_ = _tmp21_;
	_tmp23_ = utils_datetime_get_relative_date_from_date (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = dialogs_item_change_history_get_header_box (self, _tmp24_);
	_tmp26_ = _tmp25_;
	gtk_list_box_row_set_header ((GtkListBoxRow*) _tmp17_, _tmp26_);
	_g_object_unref0 (_tmp26_);
	_g_free0 (_tmp24_);
	_g_object_unref0 (row);
}

static GtkWidget*
dialogs_item_change_history_get_header_box (DialogsItemChangeHistory* self,
                                            const gchar* title)
{
	GtkLabel* header_label = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	GtkLabel* _tmp2_ = NULL;
	GtkBox* header_box = NULL;
	GtkBox* _tmp3_ = NULL;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (title != NULL, NULL);
	_tmp0_ = g_strdup ("heading");
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = (GtkLabel*) gtk_label_new (title);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp2_, _tmp1_);
	_tmp1_ = (_vala_array_free (_tmp1_, 1, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_halign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp2_);
	header_label = _tmp2_;
	_tmp3_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp3_, 12);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp3_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp3_, 6);
	g_object_ref_sink (_tmp3_);
	header_box = _tmp3_;
	gtk_box_append (header_box, (GtkWidget*) header_label);
	result = (GtkWidget*) header_box;
	_g_object_unref0 (header_label);
	return result;
}

static GtkWidget*
dialogs_item_change_history_build_card (DialogsItemChangeHistory* self,
                                        const gchar* icon_name,
                                        const gchar* header,
                                        const gchar* value)
{
	GtkImage* image = NULL;
	GtkImage* _tmp0_;
	GtkLabel* header_label = NULL;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar** _tmp4_;
	GtkLabel* _tmp5_ = NULL;
	GtkLabel* value_label = NULL;
	gchar* _tmp6_;
	gchar** _tmp7_;
	GtkLabel* _tmp8_ = NULL;
	GtkGrid* card_content = NULL;
	GtkGrid* _tmp9_ = NULL;
	AdwBin* card = NULL;
	GtkWidget* _tmp10_;
	gchar* _tmp11_;
	gchar** _tmp12_;
	AdwBin* _tmp13_ = NULL;
	GtkWidget* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (icon_name != NULL, NULL);
	g_return_val_if_fail (header != NULL, NULL);
	g_return_val_if_fail (value != NULL, NULL);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name (icon_name);
	g_object_ref_sink (_tmp0_);
	image = _tmp0_;
	_tmp1_ = g_strdup ("title-4");
	_tmp2_ = g_strdup ("caption");
	_tmp3_ = g_strdup ("font-bold");
	_tmp4_ = g_new0 (gchar*, 3 + 1);
	_tmp4_[0] = _tmp1_;
	_tmp4_[1] = _tmp2_;
	_tmp4_[2] = _tmp3_;
	_tmp5_ = (GtkLabel*) gtk_label_new (header);
	gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_START);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp5_, _tmp4_);
	_tmp4_ = (_vala_array_free (_tmp4_, 3, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp5_);
	header_label = _tmp5_;
	_tmp6_ = g_strdup ("caption");
	_tmp7_ = g_new0 (gchar*, 1 + 1);
	_tmp7_[0] = _tmp6_;
	_tmp8_ = (GtkLabel*) gtk_label_new (value);
	gtk_label_set_xalign (_tmp8_, (gfloat) 0);
	gtk_label_set_use_markup (_tmp8_, TRUE);
	gtk_widget_set_halign ((GtkWidget*) _tmp8_, GTK_ALIGN_START);
	gtk_label_set_ellipsize (_tmp8_, PANGO_ELLIPSIZE_END);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp8_, _tmp7_);
	_tmp7_ = (_vala_array_free (_tmp7_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp8_);
	value_label = _tmp8_;
	_tmp9_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp9_, 12);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp9_, TRUE);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp9_, TRUE);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp9_, 12);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp9_, 6);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp9_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp9_, 6);
	g_object_ref_sink (_tmp9_);
	card_content = _tmp9_;
	gtk_grid_attach (card_content, (GtkWidget*) image, 0, 0, 1, 2);
	gtk_grid_attach (card_content, (GtkWidget*) header_label, 1, 0, 1, 1);
	gtk_grid_attach (card_content, (GtkWidget*) value_label, 1, 1, 1, 1);
	_tmp10_ = _g_object_ref0 ((GtkWidget*) card_content);
	_tmp11_ = g_strdup ("card");
	_tmp12_ = g_new0 (gchar*, 1 + 1);
	_tmp12_[0] = _tmp11_;
	_tmp13_ = (AdwBin*) adw_bin_new ();
	adw_bin_set_child (_tmp13_, _tmp10_);
	_g_object_unref0 (_tmp10_);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp13_, _tmp12_);
	_tmp12_ = (_vala_array_free (_tmp12_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp13_);
	card = _tmp13_;
	result = (GtkWidget*) card;
	_g_object_unref0 (card_content);
	_g_object_unref0 (value_label);
	_g_object_unref0 (header_label);
	_g_object_unref0 (image);
	return result;
}

void
dialogs_item_change_history_clean_up (DialogsItemChangeHistory* self)
{
	GeeHashMap* _tmp15_;
	GtkListBox* _tmp16_;
	g_return_if_fail (self != NULL);
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = self->priv->signal_map;
		_tmp1_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_entry_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			GeeMapEntry* _tmp9_;
			gconstpointer _tmp10_;
			gconstpointer _tmp11_;
			GeeMapEntry* _tmp12_;
			gconstpointer _tmp13_;
			gconstpointer _tmp14_;
			_tmp6_ = _entry_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _entry_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			entry = (GeeMapEntry*) _tmp8_;
			_tmp9_ = entry;
			_tmp10_ = gee_map_entry_get_value (_tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = entry;
			_tmp13_ = gee_map_entry_get_key (_tmp12_);
			_tmp14_ = _tmp13_;
			g_signal_handler_disconnect ((GObject*) _tmp11_, (gulong) ((guintptr) _tmp14_));
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	_tmp15_ = self->priv->signal_map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp15_);
	_tmp16_ = self->priv->listbox;
	gtk_list_box_set_header_func (_tmp16_, NULL, NULL, NULL);
}

ObjectsItem*
dialogs_item_change_history_get_item (DialogsItemChangeHistory* self)
{
	ObjectsItem* result;
	ObjectsItem* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_item;
	result = _tmp0_;
	return result;
}

static void
dialogs_item_change_history_set_item (DialogsItemChangeHistory* self,
                                      ObjectsItem* value)
{
	ObjectsItem* old_value;
	g_return_if_fail (self != NULL);
	old_value = dialogs_item_change_history_get_item (self);
	if (old_value != value) {
		ObjectsItem* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_item);
		self->priv->_item = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, dialogs_item_change_history_properties[DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY]);
	}
}

static void
_dialogs_item_change_history_header_completed_function_gtk_list_box_update_header_func (GtkListBoxRow* row,
                                                                                        GtkListBoxRow* before,
                                                                                        gpointer self)
{
	dialogs_item_change_history_header_completed_function ((DialogsItemChangeHistory*) self, row, before);
}

static void
_dialogs_item_change_history___lambda215_ (DialogsItemChangeHistory* self)
{
	GtkAdjustment* adj = NULL;
	GtkScrolledWindow* _tmp0_;
	GtkAdjustment* _tmp1_;
	GtkAdjustment* _tmp2_;
	GtkAdjustment* _tmp3_;
	gboolean _tmp4_ = FALSE;
	_tmp0_ = self->priv->listbox_scrolled;
	_tmp1_ = gtk_scrolled_window_get_vadjustment (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	adj = _tmp3_;
	if (!self->priv->_loading) {
		GtkAdjustment* _tmp5_;
		gdouble _tmp6_;
		gdouble _tmp7_;
		GtkAdjustment* _tmp8_;
		gdouble _tmp9_;
		gdouble _tmp10_;
		GtkAdjustment* _tmp11_;
		gdouble _tmp12_;
		gdouble _tmp13_;
		_tmp5_ = adj;
		_tmp6_ = gtk_adjustment_get_value (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = adj;
		_tmp9_ = gtk_adjustment_get_upper (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = adj;
		_tmp12_ = gtk_adjustment_get_page_size (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp4_ = _tmp7_ >= ((_tmp10_ - _tmp13_) - 50);
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		self->priv->_loading = TRUE;
		self->priv->start_week = self->priv->end_week;
		self->priv->end_week = self->priv->end_week + 7;
		dialogs_item_change_history_fetch_data (self);
		self->priv->_loading = FALSE;
	}
	_g_object_unref0 (adj);
}

static void
__dialogs_item_change_history___lambda215__gtk_adjustment_value_changed (GtkAdjustment* _sender,
                                                                         gpointer self)
{
	_dialogs_item_change_history___lambda215_ ((DialogsItemChangeHistory*) self);
}

static void
_dialogs_item_change_history___lambda216_ (DialogsItemChangeHistory* self)
{
	dialogs_item_change_history_clean_up (self);
}

static void
__dialogs_item_change_history___lambda216__adw_dialog_closed (AdwDialog* _sender,
                                                              gpointer self)
{
	_dialogs_item_change_history___lambda216_ ((DialogsItemChangeHistory*) self);
}

static GObject *
dialogs_item_change_history_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	DialogsItemChangeHistory * self;
	AdwHeaderBar* headerbar = NULL;
	AdwHeaderBar* _tmp0_;
	AdwHeaderBar* _tmp1_;
	GtkBox* create_update_box = NULL;
	GtkBox* _tmp2_ = NULL;
	GtkBox* _tmp3_;
	ObjectsItem* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	GtkWidget* _tmp9_;
	GtkWidget* _tmp10_;
	gchar* updated_date = NULL;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	ObjectsItem* _tmp15_;
	const gchar* _tmp16_;
	const gchar* _tmp17_;
	GtkBox* _tmp22_;
	const gchar* _tmp23_;
	GtkWidget* _tmp24_;
	GtkWidget* _tmp25_;
	gchar* _tmp26_;
	gchar** _tmp27_;
	GtkListBox* _tmp28_ = NULL;
	GtkListBox* _tmp29_;
	GtkListBox* _tmp30_;
	gchar* _tmp31_;
	gchar** _tmp32_;
	GtkLabel* _tmp33_ = NULL;
	GtkLabel* _tmp34_;
	GtkBox* v_box = NULL;
	GtkBox* _tmp35_ = NULL;
	GtkBox* _tmp36_;
	GtkBox* _tmp37_;
	GtkBox* _tmp38_;
	GtkListBox* _tmp39_;
	GtkBox* v2_box = NULL;
	GtkBox* _tmp40_ = NULL;
	GtkBox* _tmp41_;
	GtkBox* _tmp42_;
	GtkBox* _tmp43_;
	GtkWidget* _tmp44_;
	GtkScrolledWindow* _tmp45_ = NULL;
	AdwToolbarView* toolbar_view = NULL;
	AdwToolbarView* _tmp46_;
	AdwToolbarView* _tmp47_;
	AdwHeaderBar* _tmp48_;
	AdwToolbarView* _tmp49_;
	GtkScrolledWindow* _tmp50_;
	AdwToolbarView* _tmp51_;
	GtkScrolledWindow* _tmp52_;
	GtkAdjustment* _tmp53_;
	GtkAdjustment* _tmp54_;
	parent_class = G_OBJECT_CLASS (dialogs_item_change_history_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistory);
	_tmp0_ = (AdwHeaderBar*) adw_header_bar_new ();
	g_object_ref_sink (_tmp0_);
	headerbar = _tmp0_;
	_tmp1_ = headerbar;
	gtk_widget_add_css_class ((GtkWidget*) _tmp1_, "flat");
	_tmp2_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp2_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp2_, 6);
	gtk_widget_set_valign ((GtkWidget*) _tmp2_, GTK_ALIGN_START);
	gtk_box_set_homogeneous (_tmp2_, TRUE);
	g_object_ref_sink (_tmp2_);
	create_update_box = _tmp2_;
	_tmp3_ = create_update_box;
	_tmp4_ = self->priv->_item;
	_tmp5_ = objects_item_get_added_datetime (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = utils_datetime_get_relative_date_from_date (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = dialogs_item_change_history_build_card (self, "plus-large-symbolic", _ ("Added at"), _tmp8_);
	_tmp10_ = _tmp9_;
	gtk_box_append (_tmp3_, _tmp10_);
	_g_object_unref0 (_tmp10_);
	_g_free0 (_tmp8_);
	_tmp11_ = g_strconcat ("(", _ ("Not available"), NULL);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strconcat (_tmp12_, ")", NULL);
	_tmp14_ = _tmp13_;
	_g_free0 (_tmp12_);
	updated_date = _tmp14_;
	_tmp15_ = self->priv->_item;
	_tmp16_ = objects_item_get_updated_at (_tmp15_);
	_tmp17_ = _tmp16_;
	if (g_strcmp0 (_tmp17_, "") != 0) {
		ObjectsItem* _tmp18_;
		GDateTime* _tmp19_;
		GDateTime* _tmp20_;
		gchar* _tmp21_;
		_tmp18_ = self->priv->_item;
		_tmp19_ = objects_item_get_updated_datetime (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = utils_datetime_get_relative_date_from_date (_tmp20_);
		_g_free0 (updated_date);
		updated_date = _tmp21_;
	}
	_tmp22_ = create_update_box;
	_tmp23_ = updated_date;
	_tmp24_ = dialogs_item_change_history_build_card (self, "update-symbolic", _ ("Updated at"), _tmp23_);
	_tmp25_ = _tmp24_;
	gtk_box_append (_tmp22_, _tmp25_);
	_g_object_unref0 (_tmp25_);
	_tmp26_ = g_strdup ("listbox-background");
	_tmp27_ = g_new0 (gchar*, 1 + 1);
	_tmp27_[0] = _tmp26_;
	_tmp28_ = (GtkListBox*) gtk_list_box_new ();
	gtk_widget_set_hexpand ((GtkWidget*) _tmp28_, TRUE);
	gtk_widget_set_valign ((GtkWidget*) _tmp28_, GTK_ALIGN_START);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp28_, _tmp27_);
	_tmp27_ = (_vala_array_free (_tmp27_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp28_);
	_g_object_unref0 (self->priv->listbox);
	self->priv->listbox = _tmp28_;
	_tmp29_ = self->priv->listbox;
	gtk_list_box_set_header_func (_tmp29_, _dialogs_item_change_history_header_completed_function_gtk_list_box_update_header_func, g_object_ref (self), g_object_unref);
	_tmp30_ = self->priv->listbox;
	_tmp31_ = g_strdup ("dimmed");
	_tmp32_ = g_new0 (gchar*, 1 + 1);
	_tmp32_[0] = _tmp31_;
	_tmp33_ = (GtkLabel*) gtk_label_new (_ ("Your change history will be displayed here once you start making chang" \
"es."));
	gtk_widget_set_css_classes ((GtkWidget*) _tmp33_, _tmp32_);
	_tmp32_ = (_vala_array_free (_tmp32_, 1, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp33_, 24);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp33_, 24);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp33_, 24);
	gtk_label_set_wrap (_tmp33_, TRUE);
	gtk_label_set_justify (_tmp33_, GTK_JUSTIFY_CENTER);
	g_object_ref_sink (_tmp33_);
	_tmp34_ = _tmp33_;
	gtk_list_box_set_placeholder (_tmp30_, (GtkWidget*) _tmp34_);
	_g_object_unref0 (_tmp34_);
	_tmp35_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp35_, TRUE);
	gtk_widget_set_valign ((GtkWidget*) _tmp35_, GTK_ALIGN_START);
	g_object_ref_sink (_tmp35_);
	v_box = _tmp35_;
	_tmp36_ = v_box;
	_tmp37_ = create_update_box;
	gtk_box_append (_tmp36_, (GtkWidget*) _tmp37_);
	_tmp38_ = v_box;
	_tmp39_ = self->priv->listbox;
	gtk_box_append (_tmp38_, (GtkWidget*) _tmp39_);
	_tmp40_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp40_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp40_, TRUE);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp40_, 12);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp40_, 12);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp40_, 12);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp40_, 12);
	g_object_ref_sink (_tmp40_);
	v2_box = _tmp40_;
	_tmp41_ = v2_box;
	_tmp42_ = v_box;
	gtk_box_append (_tmp41_, (GtkWidget*) _tmp42_);
	_tmp43_ = v2_box;
	_tmp44_ = _g_object_ref0 ((GtkWidget*) _tmp43_);
	_tmp45_ = (GtkScrolledWindow*) gtk_scrolled_window_new ();
	g_object_set (_tmp45_, "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp45_, TRUE);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp45_, TRUE);
	gtk_scrolled_window_set_child (_tmp45_, _tmp44_);
	_g_object_unref0 (_tmp44_);
	g_object_ref_sink (_tmp45_);
	_g_object_unref0 (self->priv->listbox_scrolled);
	self->priv->listbox_scrolled = _tmp45_;
	_tmp46_ = (AdwToolbarView*) adw_toolbar_view_new ();
	g_object_ref_sink (_tmp46_);
	toolbar_view = _tmp46_;
	_tmp47_ = toolbar_view;
	_tmp48_ = headerbar;
	adw_toolbar_view_add_top_bar (_tmp47_, (GtkWidget*) _tmp48_);
	_tmp49_ = toolbar_view;
	_tmp50_ = self->priv->listbox_scrolled;
	adw_toolbar_view_set_content (_tmp49_, (GtkWidget*) _tmp50_);
	_tmp51_ = toolbar_view;
	adw_dialog_set_child ((AdwDialog*) self, (GtkWidget*) _tmp51_);
	dialogs_item_change_history_fetch_data (self);
	_tmp52_ = self->priv->listbox_scrolled;
	_tmp53_ = gtk_scrolled_window_get_vadjustment (_tmp52_);
	_tmp54_ = _tmp53_;
	g_signal_connect_object (_tmp54_, "value-changed", (GCallback) __dialogs_item_change_history___lambda215__gtk_adjustment_value_changed, self, 0);
	g_signal_connect_object ((AdwDialog*) self, "closed", (GCallback) __dialogs_item_change_history___lambda216__adw_dialog_closed, self, 0);
	_g_object_unref0 (toolbar_view);
	_g_object_unref0 (v2_box);
	_g_object_unref0 (v_box);
	_g_free0 (updated_date);
	_g_object_unref0 (create_update_box);
	_g_object_unref0 (headerbar);
	return obj;
}

static void
dialogs_item_change_history_class_init (DialogsItemChangeHistoryClass * klass,
                                        gpointer klass_data)
{
	dialogs_item_change_history_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DialogsItemChangeHistory_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dialogs_item_change_history_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_dialogs_item_change_history_set_property;
	G_OBJECT_CLASS (klass)->constructor = dialogs_item_change_history_constructor;
	G_OBJECT_CLASS (klass)->finalize = dialogs_item_change_history_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY, dialogs_item_change_history_properties[DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY] = g_param_spec_object ("item", "item", "item", OBJECTS_TYPE_ITEM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
dialogs_item_change_history_instance_init (DialogsItemChangeHistory * self,
                                           gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = dialogs_item_change_history_get_instance_private (self);
	self->priv->start_week = 0;
	self->priv->end_week = 7;
	self->priv->_loading = FALSE;
	_tmp0_ = gee_hash_map_new (G_TYPE_ULONG, NULL, NULL, G_TYPE_OBJECT, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->signal_map = _tmp0_;
}

static void
dialogs_item_change_history_finalize (GObject * obj)
{
	DialogsItemChangeHistory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistory);
	g_debug ("ItemChangeHistory.vala:43: Destroying - Dialogs.ItemChangeHistory\n");
	_g_object_unref0 (self->priv->_item);
	_g_object_unref0 (self->priv->listbox);
	_g_object_unref0 (self->priv->listbox_scrolled);
	_g_object_unref0 (self->priv->signal_map);
	G_OBJECT_CLASS (dialogs_item_change_history_parent_class)->finalize (obj);
}

static GType
dialogs_item_change_history_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DialogsItemChangeHistoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dialogs_item_change_history_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DialogsItemChangeHistory), 0, (GInstanceInitFunc) dialogs_item_change_history_instance_init, NULL };
	GType dialogs_item_change_history_type_id;
	dialogs_item_change_history_type_id = g_type_register_static (adw_dialog_get_type (), "DialogsItemChangeHistory", &g_define_type_info, 0);
	DialogsItemChangeHistory_private_offset = g_type_add_instance_private (dialogs_item_change_history_type_id, sizeof (DialogsItemChangeHistoryPrivate));
	return dialogs_item_change_history_type_id;
}

GType
dialogs_item_change_history_get_type (void)
{
	static volatile gsize dialogs_item_change_history_type_id__once = 0;
	if (g_once_init_enter (&dialogs_item_change_history_type_id__once)) {
		GType dialogs_item_change_history_type_id;
		dialogs_item_change_history_type_id = dialogs_item_change_history_get_type_once ();
		g_once_init_leave (&dialogs_item_change_history_type_id__once, dialogs_item_change_history_type_id);
	}
	return dialogs_item_change_history_type_id__once;
}

static void
_vala_dialogs_item_change_history_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	DialogsItemChangeHistory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistory);
	switch (property_id) {
		case DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY:
		g_value_set_object (value, dialogs_item_change_history_get_item (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_dialogs_item_change_history_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	DialogsItemChangeHistory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DIALOGS_TYPE_ITEM_CHANGE_HISTORY, DialogsItemChangeHistory);
	switch (property_id) {
		case DIALOGS_ITEM_CHANGE_HISTORY_ITEM_PROPERTY:
		dialogs_item_change_history_set_item (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

