/* stats-month-page.c generated by valac 0.56.19, the Vala compiler
 * generated from stats-month-page.vala, do not modify */

/*
 * Copyright (c) 2013-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "ft_ui.h"
#include <glib.h>
#include "ft_core.h"
#include <gtk/gtk.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <gdk/gdk.h>
#include <string.h>
#include <stdlib.h>
#include <gio/gio.h>
#include <gom/gom.h>
#include <glib/gi18n-lib.h>

#define FT_STATS_MONTH_PAGE_DAYS_PER_WEEK 7
#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

enum  {
	FT_STATS_MONTH_PAGE_0_PROPERTY,
	FT_STATS_MONTH_PAGE_DATE_PROPERTY,
	FT_STATS_MONTH_PAGE_NUM_PROPERTIES
};
static GParamSpec* ft_stats_month_page_properties[FT_STATS_MONTH_PAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _FtStatsMonthPageFetchAggregatedEntriesData FtStatsMonthPageFetchAggregatedEntriesData;
typedef struct _FtStatsMonthPagePopulateData FtStatsMonthPagePopulateData;
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _FtStatsMonthPagePrivate {
	GDate _date;
	FtBubbleChart* bubble_chart;
	FtStatsCard* pomodoro_card;
	FtStatsCard* breaks_card;
	FtStatsCard* interruptions_card;
	FtStatsCard* break_ratio_card;
	FtStatsManager* stats_manager;
	GDate display_start_date;
	GDate display_end_date;
};

struct _FtStatsMonthPageFetchAggregatedEntriesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsMonthPage* self;
	GomResourceGroup* result;
	GomRepository* repository;
	GomRepository* _tmp0_;
	GomRepository* _tmp1_;
	GValue start_date_value;
	GValue _tmp2_;
	GDate _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GValue end_date_value;
	GValue _tmp6_;
	GDate _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GomFilter* start_date_filter;
	GValue _tmp10_;
	GomFilter* _tmp11_;
	GomFilter* end_date_filter;
	GValue _tmp12_;
	GomFilter* _tmp13_;
	GomFilter* date_filter;
	GomFilter* _tmp14_;
	GomFilter* _tmp15_;
	GomFilter* _tmp16_;
	GomResourceGroup* aggregated_entries;
	GomRepository* _tmp17_;
	GomFilter* _tmp18_;
	GomResourceGroup* _tmp19_;
	GomResourceGroup* _tmp20_;
	GomResourceGroup* _tmp21_;
	guint _tmp22_;
	guint _tmp23_;
	GError* _error_;
	GError* _tmp24_;
	const gchar* _tmp25_;
	GError* _inner_error0_;
};

struct _FtStatsMonthPagePopulateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsMonthPage* self;
	GomResourceGroup* aggregated_entries;
	GomResourceGroup* _tmp0_;
	guint index;
	gboolean _tmp1_;
	guint _tmp2_;
	GomResourceGroup* _tmp3_;
	guint _tmp4_;
	guint _tmp5_;
	GomResourceGroup* _tmp6_;
	GomResource* _tmp7_;
};

static gint FtStatsMonthPage_private_offset;
static gpointer ft_stats_month_page_parent_class = NULL;
static FtStatsPageIface * ft_stats_month_page_ft_stats_page_parent_iface = NULL;

static gboolean ft_stats_month_page_transform_date (FtStatsMonthPage* self,
                                             GDate* date,
                                             guint* row,
                                             guint* column);
static void ft_stats_month_page_transform_position (FtStatsMonthPage* self,
                                             guint row,
                                             guint column,
                                             GDate* result);
static void ft_stats_month_page_reset (FtStatsMonthPage* self);
static void ft_stats_month_page_update_category_colors (FtStatsMonthPage* self);
VALA_EXTERN void ft_get_chart_primary_color (GdkRGBA* foreground_color,
                                 GdkRGBA* result);
VALA_EXTERN void ft_get_chart_secondary_color (GdkRGBA* foreground_color,
                                   GdkRGBA* result);
static void ft_stats_month_page_update_bubble_chart_labels (FtStatsMonthPage* self);
VALA_EXTERN gchar* ft_capitalize_words (const gchar* text);
static void ft_stats_month_page_fetch_aggregated_entries_data_free (gpointer _data);
static void ft_stats_month_page_fetch_aggregated_entries (FtStatsMonthPage* self,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
static GomResourceGroup* ft_stats_month_page_fetch_aggregated_entries_finish (FtStatsMonthPage* self,
                                                                       GAsyncResult* _res_);
static gboolean ft_stats_month_page_fetch_aggregated_entries_co (FtStatsMonthPageFetchAggregatedEntriesData* _data_);
static void ft_stats_month_page_fetch_aggregated_entries_ready (GObject* source_object,
                                                         GAsyncResult* _res_,
                                                         gpointer _user_data_);
static void ft_stats_month_page_process_aggregated_entry (FtStatsMonthPage* self,
                                                   FtAggregatedStatsEntry* entry);
static void ft_stats_month_page_process_entry (FtStatsMonthPage* self,
                                        FtStatsEntry* entry,
                                        gint sign);
static void ft_stats_month_page_populate_data_free (gpointer _data);
static void ft_stats_month_page_populate (FtStatsMonthPage* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
static void ft_stats_month_page_populate_finish (FtStatsMonthPage* self,
                                          GAsyncResult* _res_);
static gboolean ft_stats_month_page_populate_co (FtStatsMonthPagePopulateData* _data_);
static void ft_stats_month_page_populate_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);
static void ft_stats_month_page_on_entry_saved (FtStatsMonthPage* self,
                                         FtStatsEntry* entry);
static void ft_stats_month_page_on_entry_deleted (FtStatsMonthPage* self,
                                           FtStatsEntry* entry);
static void ft_stats_month_page_on_bubble_activated (FtStatsMonthPage* self,
                                              guint row,
                                              guint column);
static void _ft_stats_month_page_on_bubble_activated_ft_bubble_chart_bubble_activated (FtBubbleChart* _sender,
                                                                                guint row,
                                                                                guint column,
                                                                                gpointer self);
static void ft_stats_month_page_real_css_changed (GtkWidget* base,
                                           GtkCssStyleChange* change);
static void ft_stats_month_page_real_dispose (GObject* base);
static void _ft_stats_month_page_on_entry_saved_ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                       FtStatsEntry* entry,
                                                                       gpointer self);
static void _ft_stats_month_page_on_entry_deleted_ft_stats_manager_entry_deleted (FtStatsManager* _sender,
                                                                           FtStatsEntry* entry,
                                                                           gpointer self);
static gboolean _g_date_equal (const GDate * s1,
                        const GDate * s2);
static GObject * ft_stats_month_page_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void _ft_stats_month_page___lambda26_ (FtStatsMonthPage* self,
                                       GObject* obj,
                                       GAsyncResult* res);
static void __ft_stats_month_page___lambda26__gasync_ready_callback (GObject* source_object,
                                                              GAsyncResult* res,
                                                              gpointer self);
static void ft_stats_month_page_finalize (GObject * obj);
static GType ft_stats_month_page_get_type_once (void);
static void _vala_ft_stats_month_page_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_ft_stats_month_page_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_stats_month_page_get_instance_private (FtStatsMonthPage* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsMonthPage_private_offset);
}

FtStatsMonthPage*
ft_stats_month_page_construct (GType object_type,
                               GDate* date)
{
	FtStatsMonthPage * self = NULL;
	GDate _tmp0_;
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = *date;
	self = (FtStatsMonthPage*) g_object_new (object_type, "date", &_tmp0_, NULL);
	return self;
}

FtStatsMonthPage*
ft_stats_month_page_new (GDate* date)
{
	return ft_stats_month_page_construct (FT_TYPE_STATS_MONTH_PAGE, date);
}

static gboolean
ft_stats_month_page_transform_date (FtStatsMonthPage* self,
                                    GDate* date,
                                    guint* row,
                                    guint* column)
{
	guint _vala_row = 0U;
	guint _vala_column = 0U;
	gint position = 0;
	GDate _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (date != NULL, FALSE);
	_tmp0_ = *date;
	position = g_date_days_between (&self->priv->display_start_date, &_tmp0_);
	if (position >= 0) {
		_vala_column = (guint) (position % FT_STATS_MONTH_PAGE_DAYS_PER_WEEK);
		_vala_row = (guint) (position / FT_STATS_MONTH_PAGE_DAYS_PER_WEEK);
		result = TRUE;
		if (row) {
			*row = _vala_row;
		}
		if (column) {
			*column = _vala_column;
		}
		return result;
	} else {
		_vala_column = (guint) 0;
		_vala_row = (guint) 0;
		result = FALSE;
		if (row) {
			*row = _vala_row;
		}
		if (column) {
			*column = _vala_column;
		}
		return result;
	}
}

static void
ft_stats_month_page_transform_position (FtStatsMonthPage* self,
                                        guint row,
                                        guint column,
                                        GDate* result)
{
	GDate* date = NULL;
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_copy (&self->priv->display_start_date);
	date = _tmp0_;
	g_date_add_days (date, (FT_STATS_MONTH_PAGE_DAYS_PER_WEEK * row) + column);
	_tmp1_ = date;
	_tmp2_ = *_tmp1_;
	_g_free0 (_tmp1_);
	*result = _tmp2_;
	return;
}

static void
ft_stats_month_page_reset (FtStatsMonthPage* self)
{
	FtBubbleChart* _tmp0_;
	FtStatsCard* _tmp1_;
	FtStatsCard* _tmp2_;
	FtStatsCard* _tmp3_;
	FtStatsCard* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->bubble_chart;
	ft_bubble_chart_fill (_tmp0_, 0.0);
	_tmp1_ = self->priv->pomodoro_card;
	ft_stats_card_set_value (_tmp1_, 0.0);
	_tmp2_ = self->priv->breaks_card;
	ft_stats_card_set_value (_tmp2_, 0.0);
	_tmp3_ = self->priv->interruptions_card;
	ft_stats_card_set_value (_tmp3_, 0.0);
	_tmp4_ = self->priv->break_ratio_card;
	ft_stats_card_set_value (_tmp4_, ((double) NAN));
}

static void
ft_stats_month_page_update_category_colors (FtStatsMonthPage* self)
{
	GdkRGBA foreground_color = {0};
	FtBubbleChart* _tmp0_;
	GdkRGBA _tmp1_ = {0};
	GdkRGBA pomodoro_color = {0};
	GdkRGBA _tmp2_;
	GdkRGBA _tmp3_ = {0};
	GdkRGBA break_color = {0};
	GdkRGBA _tmp4_;
	GdkRGBA _tmp5_ = {0};
	FtBubbleChart* _tmp6_;
	GdkRGBA _tmp7_;
	FtBubbleChart* _tmp8_;
	GdkRGBA _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->bubble_chart;
	gtk_widget_get_color ((GtkWidget*) _tmp0_, &_tmp1_);
	foreground_color = _tmp1_;
	_tmp2_ = foreground_color;
	ft_get_chart_primary_color (&_tmp2_, &_tmp3_);
	pomodoro_color = _tmp3_;
	_tmp4_ = foreground_color;
	ft_get_chart_secondary_color (&_tmp4_, &_tmp5_);
	break_color = _tmp5_;
	_tmp6_ = self->priv->bubble_chart;
	_tmp7_ = pomodoro_color;
	ft_bubble_chart_set_category_color (_tmp6_, (guint) FT_STATS_CATEGORY_POMODORO, &_tmp7_);
	_tmp8_ = self->priv->bubble_chart;
	_tmp9_ = break_color;
	ft_bubble_chart_set_category_color (_tmp8_, (guint) FT_STATS_CATEGORY_BREAK, &_tmp9_);
}

static void
ft_stats_month_page_update_bubble_chart_labels (FtStatsMonthPage* self)
{
	GDate year_start_date = {0};
	GDate _tmp0_ = {0};
	GDate _tmp1_;
	GDate* date = NULL;
	GDate* _tmp2_;
	GDateWeekday first_day_of_week = 0;
	guint _tmp3_ = 0U;
	guint week_number_offset = 0U;
	gint row = 0;
	gint column = 0;
	g_return_if_fail (self != NULL);
	memset (&year_start_date, 0, sizeof (GDate));
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp0_);
	_tmp1_ = _tmp0_;
	g_date_set_dmy (&year_start_date, (GDateDay) 1, 1, g_date_get_year (&_tmp1_));
	_tmp2_ = g_date_copy (&self->priv->display_start_date);
	date = _tmp2_;
	first_day_of_week = ft_locale_get_first_day_of_week ();
	if (first_day_of_week == G_DATE_MONDAY) {
		_tmp3_ = g_date_get_monday_week_of_year (&year_start_date);
	} else {
		_tmp3_ = g_date_get_sunday_week_of_year (&year_start_date);
	}
	week_number_offset = 1U - _tmp3_;
	row = 0;
	column = 0;
	while (TRUE) {
		GDate* _tmp4_;
		GDate _tmp5_;
		gchar* tooltip_label = NULL;
		GDate* _tmp6_;
		GDate _tmp7_;
		gchar* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		gchar* _tmp11_;
		FtBubbleChart* _tmp12_;
		const gchar* _tmp13_;
		GDate* _tmp31_;
		GDate _tmp32_ = {0};
		GDate _tmp33_;
		GDate* _tmp35_;
		gint _tmp36_;
		_tmp4_ = date;
		_tmp5_ = self->priv->display_end_date;
		if (!(g_date_compare (_tmp4_, &_tmp5_) <= 0)) {
			break;
		}
		_tmp6_ = date;
		_tmp7_ = *_tmp6_;
		_tmp8_ = ft_date_utils_format_date (&_tmp7_, "%e %B");
		_tmp9_ = _tmp8_;
		_tmp10_ = ft_capitalize_words (_tmp9_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		tooltip_label = _tmp11_;
		_tmp12_ = self->priv->bubble_chart;
		_tmp13_ = tooltip_label;
		ft_bubble_chart_set_bubble_tooltip_label (_tmp12_, (guint) row, (guint) column, _tmp13_);
		if (row == 0) {
			gchar* weekday_name = NULL;
			GDate* _tmp14_;
			GDate _tmp15_;
			gchar* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			FtBubbleChart* _tmp20_;
			const gchar* _tmp21_;
			_tmp14_ = date;
			_tmp15_ = *_tmp14_;
			_tmp16_ = ft_date_utils_format_date (&_tmp15_, "%a");
			_tmp17_ = _tmp16_;
			_tmp18_ = ft_capitalize_words (_tmp17_);
			_tmp19_ = _tmp18_;
			_g_free0 (_tmp17_);
			weekday_name = _tmp19_;
			_tmp20_ = self->priv->bubble_chart;
			_tmp21_ = weekday_name;
			ft_bubble_chart_set_column_label (_tmp20_, (guint) column, _tmp21_);
			_g_free0 (weekday_name);
		}
		if (column == 0) {
			GDate* week_end_date = NULL;
			GDate* _tmp22_;
			GDate* _tmp23_;
			GDate* _tmp24_;
			guint _tmp25_ = 0U;
			guint week_number = 0U;
			FtBubbleChart* _tmp28_;
			gchar* _tmp29_;
			gchar* _tmp30_;
			_tmp22_ = date;
			_tmp23_ = g_date_copy (_tmp22_);
			week_end_date = _tmp23_;
			_tmp24_ = week_end_date;
			g_date_add_days (_tmp24_, 6U);
			if (first_day_of_week == G_DATE_MONDAY) {
				GDate* _tmp26_;
				_tmp26_ = week_end_date;
				_tmp25_ = g_date_get_monday_week_of_year (_tmp26_);
			} else {
				GDate* _tmp27_;
				_tmp27_ = week_end_date;
				_tmp25_ = g_date_get_sunday_week_of_year (_tmp27_);
			}
			week_number = _tmp25_ + week_number_offset;
			_tmp28_ = self->priv->bubble_chart;
			_tmp29_ = g_strdup_printf ("%u", week_number);
			_tmp30_ = _tmp29_;
			ft_bubble_chart_set_row_label (_tmp28_, (guint) row, _tmp30_);
			_g_free0 (_tmp30_);
			_g_free0 (week_end_date);
		}
		_tmp31_ = date;
		ft_stats_page_get_date ((FtStatsPage*) self, &_tmp32_);
		_tmp33_ = _tmp32_;
		if (g_date_get_month (_tmp31_) != g_date_get_month (&_tmp33_)) {
			FtBubbleChart* _tmp34_;
			_tmp34_ = self->priv->bubble_chart;
			ft_bubble_chart_set_bubble_inverted (_tmp34_, (guint) row, (guint) column, TRUE);
		}
		_tmp35_ = date;
		g_date_add_days (_tmp35_, 1U);
		_tmp36_ = column;
		column = _tmp36_ + 1;
		if (column >= FT_STATS_MONTH_PAGE_DAYS_PER_WEEK) {
			gint _tmp37_;
			column = 0;
			_tmp37_ = row;
			row = _tmp37_ + 1;
		}
		_g_free0 (tooltip_label);
	}
	_g_free0 (date);
}

static void
ft_stats_month_page_fetch_aggregated_entries_data_free (gpointer _data)
{
	FtStatsMonthPageFetchAggregatedEntriesData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (FtStatsMonthPageFetchAggregatedEntriesData, _data_);
}

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

static void
ft_stats_month_page_fetch_aggregated_entries (FtStatsMonthPage* self,
                                              GAsyncReadyCallback _callback_,
                                              gpointer _user_data_)
{
	FtStatsMonthPageFetchAggregatedEntriesData* _data_;
	FtStatsMonthPage* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtStatsMonthPageFetchAggregatedEntriesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_month_page_fetch_aggregated_entries_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_stats_month_page_fetch_aggregated_entries_co (_data_);
}

static GomResourceGroup*
ft_stats_month_page_fetch_aggregated_entries_finish (FtStatsMonthPage* self,
                                                     GAsyncResult* _res_)
{
	GomResourceGroup* result;
	FtStatsMonthPageFetchAggregatedEntriesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
ft_stats_month_page_fetch_aggregated_entries_ready (GObject* source_object,
                                                    GAsyncResult* _res_,
                                                    gpointer _user_data_)
{
	FtStatsMonthPageFetchAggregatedEntriesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_month_page_fetch_aggregated_entries_co (_data_);
}

static gboolean
ft_stats_month_page_fetch_aggregated_entries_co (FtStatsMonthPageFetchAggregatedEntriesData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = ft_database_get_repository ();
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->repository = _data_->_tmp1_;
	memset (&_data_->_tmp2_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp2_, G_TYPE_STRING);
	_data_->start_date_value = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->self->priv->display_start_date;
	_data_->_tmp4_ = ft_database_serialize_date (&_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	g_value_set_string (&_data_->start_date_value, _data_->_tmp5_);
	_g_free0 (_data_->_tmp5_);
	memset (&_data_->_tmp6_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp6_, G_TYPE_STRING);
	_data_->end_date_value = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->self->priv->display_end_date;
	_data_->_tmp8_ = ft_database_serialize_date (&_data_->_tmp7_);
	_data_->_tmp9_ = _data_->_tmp8_;
	g_value_set_string (&_data_->end_date_value, _data_->_tmp9_);
	_g_free0 (_data_->_tmp9_);
	_data_->_tmp10_ = _data_->start_date_value;
	_data_->_tmp11_ = gom_filter_new_gte (FT_TYPE_AGGREGATED_STATS_ENTRY, "date", &_data_->_tmp10_);
	g_object_ref_sink (_data_->_tmp11_);
	_data_->start_date_filter = _data_->_tmp11_;
	_data_->_tmp12_ = _data_->end_date_value;
	_data_->_tmp13_ = gom_filter_new_lte (FT_TYPE_AGGREGATED_STATS_ENTRY, "date", &_data_->_tmp12_);
	g_object_ref_sink (_data_->_tmp13_);
	_data_->end_date_filter = _data_->_tmp13_;
	_data_->_tmp14_ = _data_->start_date_filter;
	_data_->_tmp15_ = _data_->end_date_filter;
	_data_->_tmp16_ = gom_filter_new_and (_data_->_tmp14_, _data_->_tmp15_);
	g_object_ref_sink (_data_->_tmp16_);
	_data_->date_filter = _data_->_tmp16_;
	{
		_data_->_tmp17_ = _data_->repository;
		_data_->_tmp18_ = _data_->date_filter;
		_data_->_state_ = 1;
		gom_repository_find_async (_data_->_tmp17_, FT_TYPE_AGGREGATED_STATS_ENTRY, _data_->_tmp18_, ft_stats_month_page_fetch_aggregated_entries_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp19_ = gom_repository_find_finish (_data_->_tmp17_, _data_->_res_, &_data_->_inner_error0_);
		_data_->aggregated_entries = _data_->_tmp19_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp20_ = _data_->aggregated_entries;
		_data_->_tmp21_ = _data_->aggregated_entries;
		_data_->_tmp22_ = gom_resource_group_get_count (_data_->_tmp21_);
		_data_->_tmp23_ = _data_->_tmp22_;
		_data_->_state_ = 2;
		gom_resource_group_fetch_async (_data_->_tmp20_, 0U, _data_->_tmp23_, ft_stats_month_page_fetch_aggregated_entries_ready, _data_);
		return FALSE;
		_state_2:
		gom_resource_group_fetch_finish (_data_->_tmp20_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->aggregated_entries);
			goto __catch0_g_error;
		}
		_data_->result = _data_->aggregated_entries;
		_g_object_unref0 (_data_->date_filter);
		_g_object_unref0 (_data_->end_date_filter);
		_g_object_unref0 (_data_->start_date_filter);
		G_IS_VALUE (&_data_->end_date_value) ? (g_value_unset (&_data_->end_date_value), NULL) : NULL;
		G_IS_VALUE (&_data_->start_date_value) ? (g_value_unset (&_data_->start_date_value), NULL) : NULL;
		_g_object_unref0 (_data_->repository);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp24_ = _data_->_error_;
		_data_->_tmp25_ = _data_->_tmp24_->message;
		g_critical ("stats-month-page.vala:218: Error while fetching weekly stats: %s", _data_->_tmp25_);
		_data_->result = NULL;
		_g_error_free0 (_data_->_error_);
		_g_object_unref0 (_data_->date_filter);
		_g_object_unref0 (_data_->end_date_filter);
		_g_object_unref0 (_data_->start_date_filter);
		G_IS_VALUE (&_data_->end_date_value) ? (g_value_unset (&_data_->end_date_value), NULL) : NULL;
		G_IS_VALUE (&_data_->start_date_value) ? (g_value_unset (&_data_->start_date_value), NULL) : NULL;
		_g_object_unref0 (_data_->repository);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	_g_object_unref0 (_data_->date_filter);
	_g_object_unref0 (_data_->end_date_filter);
	_g_object_unref0 (_data_->start_date_filter);
	G_IS_VALUE (&_data_->end_date_value) ? (g_value_unset (&_data_->end_date_value), NULL) : NULL;
	G_IS_VALUE (&_data_->start_date_value) ? (g_value_unset (&_data_->start_date_value), NULL) : NULL;
	_g_object_unref0 (_data_->repository);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_stats_month_page_process_aggregated_entry (FtStatsMonthPage* self,
                                              FtAggregatedStatsEntry* entry)
{
	gint entry_category = 0;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GDate entry_date = {0};
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GDate _tmp4_ = {0};
	gint64 entry_duration = 0LL;
	gint64 _tmp5_;
	gint64 _tmp6_;
	guint category_index = 0U;
	guint row = 0U;
	guint column = 0U;
	GDate _tmp7_;
	guint _tmp8_ = 0U;
	guint _tmp9_ = 0U;
	gboolean _tmp10_;
	gdouble _tmp11_ = 0.0;
	gdouble bucket_value = 0.0;
	FtBubbleChart* _tmp14_;
	GDate _tmp15_ = {0};
	GDate _tmp16_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	_tmp0_ = ft_aggregated_stats_entry_get_category (entry);
	_tmp1_ = _tmp0_;
	entry_category = ft_stats_category_from_string (_tmp1_);
	_tmp2_ = ft_aggregated_stats_entry_get_date (entry);
	_tmp3_ = _tmp2_;
	ft_database_parse_date (_tmp3_, &_tmp4_);
	entry_date = _tmp4_;
	_tmp5_ = ft_aggregated_stats_entry_get_duration (entry);
	_tmp6_ = _tmp5_;
	entry_duration = _tmp6_;
	if (entry_category == ((gint) FT_STATS_CATEGORY_INVALID)) {
		return;
	}
	category_index = (guint) entry_category;
	_tmp7_ = entry_date;
	_tmp10_ = ft_stats_month_page_transform_date (self, &_tmp7_, &_tmp8_, &_tmp9_);
	row = _tmp8_;
	column = _tmp9_;
	if (!_tmp10_) {
		return;
	}
	if (entry_category != ((gint) FT_STATS_CATEGORY_INTERRUPTION)) {
		_tmp11_ = ft_interval_to_seconds (entry_duration);
	} else {
		gint64 _tmp12_;
		gint64 _tmp13_;
		_tmp12_ = ft_aggregated_stats_entry_get_count (entry);
		_tmp13_ = _tmp12_;
		_tmp11_ = (gdouble) _tmp13_;
	}
	bucket_value = _tmp11_;
	_tmp14_ = self->priv->bubble_chart;
	ft_bubble_chart_add_value (_tmp14_, row, column, category_index, bucket_value);
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp15_);
	_tmp16_ = _tmp15_;
	if (g_date_get_month (&entry_date) == g_date_get_month (&_tmp16_)) {
		gdouble total = 0.0;
		FtStatsCard* _tmp29_;
		gdouble _tmp30_;
		gdouble _tmp31_;
		FtStatsCard* _tmp32_;
		gdouble _tmp33_;
		gdouble _tmp34_;
		gdouble _tmp35_ = 0.0;
		FtStatsCard* _tmp39_;
		switch (entry_category) {
			case FT_STATS_CATEGORY_POMODORO:
			{
				FtStatsCard* _tmp17_;
				FtStatsCard* _tmp18_;
				gdouble _tmp19_;
				gdouble _tmp20_;
				_tmp17_ = self->priv->pomodoro_card;
				_tmp18_ = self->priv->pomodoro_card;
				_tmp19_ = ft_stats_card_get_value (_tmp18_);
				_tmp20_ = _tmp19_;
				ft_stats_card_set_value (_tmp18_, _tmp20_ + bucket_value);
				break;
			}
			case FT_STATS_CATEGORY_BREAK:
			{
				FtStatsCard* _tmp21_;
				FtStatsCard* _tmp22_;
				gdouble _tmp23_;
				gdouble _tmp24_;
				_tmp21_ = self->priv->breaks_card;
				_tmp22_ = self->priv->breaks_card;
				_tmp23_ = ft_stats_card_get_value (_tmp22_);
				_tmp24_ = _tmp23_;
				ft_stats_card_set_value (_tmp22_, _tmp24_ + bucket_value);
				break;
			}
			case FT_STATS_CATEGORY_INTERRUPTION:
			{
				FtStatsCard* _tmp25_;
				FtStatsCard* _tmp26_;
				gdouble _tmp27_;
				gdouble _tmp28_;
				_tmp25_ = self->priv->interruptions_card;
				_tmp26_ = self->priv->interruptions_card;
				_tmp27_ = ft_stats_card_get_value (_tmp26_);
				_tmp28_ = _tmp27_;
				ft_stats_card_set_value (_tmp26_, _tmp28_ + bucket_value);
				break;
			}
			default:
			{
				break;
			}
		}
		_tmp29_ = self->priv->pomodoro_card;
		_tmp30_ = ft_stats_card_get_value (_tmp29_);
		_tmp31_ = _tmp30_;
		_tmp32_ = self->priv->breaks_card;
		_tmp33_ = ft_stats_card_get_value (_tmp32_);
		_tmp34_ = _tmp33_;
		total = _tmp31_ + _tmp34_;
		if (total >= 3600.0) {
			FtStatsCard* _tmp36_;
			gdouble _tmp37_;
			gdouble _tmp38_;
			_tmp36_ = self->priv->breaks_card;
			_tmp37_ = ft_stats_card_get_value (_tmp36_);
			_tmp38_ = _tmp37_;
			_tmp35_ = _tmp38_ / total;
		} else {
			_tmp35_ = ((double) NAN);
		}
		_tmp39_ = self->priv->break_ratio_card;
		ft_stats_card_set_value (_tmp39_, _tmp35_);
	}
}

static void
ft_stats_month_page_process_entry (FtStatsMonthPage* self,
                                   FtStatsEntry* entry,
                                   gint sign)
{
	gint entry_category = 0;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	GDate entry_date = {0};
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GDate _tmp4_ = {0};
	gint64 entry_duration = 0LL;
	gint64 _tmp5_;
	gint64 _tmp6_;
	gboolean _tmp7_ = FALSE;
	GDate _tmp8_;
	guint row = 0U;
	guint column = 0U;
	GDate _tmp10_;
	guint _tmp11_ = 0U;
	guint _tmp12_ = 0U;
	gboolean _tmp13_;
	gdouble _tmp14_ = 0.0;
	gdouble bucket_value = 0.0;
	FtBubbleChart* _tmp15_;
	GDate _tmp16_ = {0};
	GDate _tmp17_;
	gdouble total = 0.0;
	FtStatsCard* _tmp30_;
	gdouble _tmp31_;
	gdouble _tmp32_;
	FtStatsCard* _tmp33_;
	gdouble _tmp34_;
	gdouble _tmp35_;
	gdouble _tmp36_ = 0.0;
	FtStatsCard* _tmp40_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	_vala_return_if_fail ((sign == 1) || (sign == -1), "sign == 1 || sign == -1");
	_tmp0_ = ft_stats_entry_get_category (entry);
	_tmp1_ = _tmp0_;
	entry_category = ft_stats_category_from_string (_tmp1_);
	_tmp2_ = ft_stats_entry_get_date (entry);
	_tmp3_ = _tmp2_;
	ft_database_parse_date (_tmp3_, &_tmp4_);
	entry_date = _tmp4_;
	_tmp5_ = ft_stats_entry_get_duration (entry);
	_tmp6_ = _tmp5_;
	entry_duration = _tmp6_;
	if (entry_category == ((gint) FT_STATS_CATEGORY_INVALID)) {
		return;
	}
	_tmp8_ = self->priv->display_start_date;
	if (g_date_compare (&entry_date, &_tmp8_) < 0) {
		_tmp7_ = TRUE;
	} else {
		GDate _tmp9_;
		_tmp9_ = self->priv->display_end_date;
		_tmp7_ = g_date_compare (&entry_date, &_tmp9_) > 0;
	}
	if (_tmp7_) {
		return;
	}
	_tmp10_ = entry_date;
	_tmp13_ = ft_stats_month_page_transform_date (self, &_tmp10_, &_tmp11_, &_tmp12_);
	row = _tmp11_;
	column = _tmp12_;
	if (!_tmp13_) {
		return;
	}
	if (entry_category != ((gint) FT_STATS_CATEGORY_INTERRUPTION)) {
		_tmp14_ = ft_interval_to_seconds (sign * entry_duration);
	} else {
		_tmp14_ = (gdouble) sign;
	}
	bucket_value = _tmp14_;
	_tmp15_ = self->priv->bubble_chart;
	ft_bubble_chart_add_value (_tmp15_, row, column, (guint) entry_category, bucket_value);
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp16_);
	_tmp17_ = _tmp16_;
	if (g_date_get_month (&entry_date) != g_date_get_month (&_tmp17_)) {
		return;
	}
	switch (entry_category) {
		case FT_STATS_CATEGORY_POMODORO:
		{
			FtStatsCard* _tmp18_;
			FtStatsCard* _tmp19_;
			gdouble _tmp20_;
			gdouble _tmp21_;
			_tmp18_ = self->priv->pomodoro_card;
			_tmp19_ = self->priv->pomodoro_card;
			_tmp20_ = ft_stats_card_get_value (_tmp19_);
			_tmp21_ = _tmp20_;
			ft_stats_card_set_value (_tmp19_, _tmp21_ + bucket_value);
			break;
		}
		case FT_STATS_CATEGORY_BREAK:
		{
			FtStatsCard* _tmp22_;
			FtStatsCard* _tmp23_;
			gdouble _tmp24_;
			gdouble _tmp25_;
			_tmp22_ = self->priv->breaks_card;
			_tmp23_ = self->priv->breaks_card;
			_tmp24_ = ft_stats_card_get_value (_tmp23_);
			_tmp25_ = _tmp24_;
			ft_stats_card_set_value (_tmp23_, _tmp25_ + bucket_value);
			break;
		}
		case FT_STATS_CATEGORY_INTERRUPTION:
		{
			FtStatsCard* _tmp26_;
			FtStatsCard* _tmp27_;
			gdouble _tmp28_;
			gdouble _tmp29_;
			_tmp26_ = self->priv->interruptions_card;
			_tmp27_ = self->priv->interruptions_card;
			_tmp28_ = ft_stats_card_get_value (_tmp27_);
			_tmp29_ = _tmp28_;
			ft_stats_card_set_value (_tmp27_, _tmp29_ + bucket_value);
			break;
		}
		default:
		{
			break;
		}
	}
	_tmp30_ = self->priv->pomodoro_card;
	_tmp31_ = ft_stats_card_get_value (_tmp30_);
	_tmp32_ = _tmp31_;
	_tmp33_ = self->priv->breaks_card;
	_tmp34_ = ft_stats_card_get_value (_tmp33_);
	_tmp35_ = _tmp34_;
	total = _tmp32_ + _tmp35_;
	if (total >= 3600.0) {
		FtStatsCard* _tmp37_;
		gdouble _tmp38_;
		gdouble _tmp39_;
		_tmp37_ = self->priv->breaks_card;
		_tmp38_ = ft_stats_card_get_value (_tmp37_);
		_tmp39_ = _tmp38_;
		_tmp36_ = _tmp39_ / total;
	} else {
		_tmp36_ = ((double) NAN);
	}
	_tmp40_ = self->priv->break_ratio_card;
	ft_stats_card_set_value (_tmp40_, _tmp36_);
}

static void
ft_stats_month_page_populate_data_free (gpointer _data)
{
	FtStatsMonthPagePopulateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (FtStatsMonthPagePopulateData, _data_);
}

static void
ft_stats_month_page_populate (FtStatsMonthPage* self,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	FtStatsMonthPagePopulateData* _data_;
	FtStatsMonthPage* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtStatsMonthPagePopulateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_month_page_populate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_stats_month_page_populate_co (_data_);
}

static void
ft_stats_month_page_populate_finish (FtStatsMonthPage* self,
                                     GAsyncResult* _res_)
{
	FtStatsMonthPagePopulateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
ft_stats_month_page_populate_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	FtStatsMonthPagePopulateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_month_page_populate_co (_data_);
}

static gboolean
ft_stats_month_page_populate_co (FtStatsMonthPagePopulateData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	ft_stats_month_page_fetch_aggregated_entries (_data_->self, ft_stats_month_page_populate_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = ft_stats_month_page_fetch_aggregated_entries_finish (_data_->self, _data_->_res_);
	_data_->aggregated_entries = _data_->_tmp0_;
	ft_stats_month_page_update_bubble_chart_labels (_data_->self);
	ft_stats_month_page_reset (_data_->self);
	{
		_data_->index = 0U;
		{
			_data_->_tmp1_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp1_) {
					_data_->_tmp2_ = _data_->index;
					_data_->index = _data_->_tmp2_ + 1;
				}
				_data_->_tmp1_ = FALSE;
				_data_->_tmp3_ = _data_->aggregated_entries;
				_data_->_tmp4_ = gom_resource_group_get_count (_data_->_tmp3_);
				_data_->_tmp5_ = _data_->_tmp4_;
				if (!(_data_->index < _data_->_tmp5_)) {
					break;
				}
				_data_->_tmp6_ = _data_->aggregated_entries;
				_data_->_tmp7_ = gom_resource_group_get_index (_data_->_tmp6_, _data_->index);
				ft_stats_month_page_process_aggregated_entry (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp7_, FT_TYPE_AGGREGATED_STATS_ENTRY, FtAggregatedStatsEntry));
			}
		}
	}
	_g_object_unref0 (_data_->aggregated_entries);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
ft_stats_month_page_on_entry_saved (FtStatsMonthPage* self,
                                    FtStatsEntry* entry)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	ft_stats_month_page_process_entry (self, entry, 1);
}

static void
ft_stats_month_page_on_entry_deleted (FtStatsMonthPage* self,
                                      FtStatsEntry* entry)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	ft_stats_month_page_process_entry (self, entry, -1);
}

static void
ft_stats_month_page_on_bubble_activated (FtStatsMonthPage* self,
                                         guint row,
                                         guint column)
{
	GDate date = {0};
	GDate _tmp0_ = {0};
	GDate _tmp1_;
	GVariant* _tmp2_;
	GVariant* _tmp3_;
	g_return_if_fail (self != NULL);
	ft_stats_month_page_transform_position (self, row, column, &_tmp0_);
	date = _tmp0_;
	_tmp1_ = date;
	_tmp2_ = ft_date_utils_date_to_variant (&_tmp1_);
	_tmp3_ = _tmp2_;
	gtk_widget_activate_action_variant ((GtkWidget*) self, "stats.select-day", _tmp3_);
	_g_variant_unref0 (_tmp3_);
}

static void
_ft_stats_month_page_on_bubble_activated_ft_bubble_chart_bubble_activated (FtBubbleChart* _sender,
                                                                           guint row,
                                                                           guint column,
                                                                           gpointer self)
{
	ft_stats_month_page_on_bubble_activated ((FtStatsMonthPage*) self, row, column);
}

static void
ft_stats_month_page_real_css_changed (GtkWidget* base,
                                      GtkCssStyleChange* change)
{
	FtStatsMonthPage * self;
	self = (FtStatsMonthPage*) base;
	g_return_if_fail (change != NULL);
	GTK_WIDGET_CLASS (ft_stats_month_page_parent_class)->css_changed ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin), change);
	ft_stats_month_page_update_category_colors (self);
}

static void
_ft_stats_month_page_on_entry_saved_ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                  FtStatsEntry* entry,
                                                                  gpointer self)
{
	ft_stats_month_page_on_entry_saved ((FtStatsMonthPage*) self, entry);
}

static void
_ft_stats_month_page_on_entry_deleted_ft_stats_manager_entry_deleted (FtStatsManager* _sender,
                                                                      FtStatsEntry* entry,
                                                                      gpointer self)
{
	ft_stats_month_page_on_entry_deleted ((FtStatsMonthPage*) self, entry);
}

static void
ft_stats_month_page_real_dispose (GObject* base)
{
	FtStatsMonthPage * self;
	FtStatsManager* _tmp0_;
	self = (FtStatsMonthPage*) base;
	_tmp0_ = self->priv->stats_manager;
	if (_tmp0_ != NULL) {
		FtStatsManager* _tmp1_;
		guint _tmp2_;
		FtStatsManager* _tmp3_;
		guint _tmp4_;
		_tmp1_ = self->priv->stats_manager;
		g_signal_parse_name ("entry-saved", FT_TYPE_STATS_MANAGER, &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _ft_stats_month_page_on_entry_saved_ft_stats_manager_entry_saved, self);
		_tmp3_ = self->priv->stats_manager;
		g_signal_parse_name ("entry-deleted", FT_TYPE_STATS_MANAGER, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched (_tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _ft_stats_month_page_on_entry_deleted_ft_stats_manager_entry_deleted, self);
		_g_object_unref0 (self->priv->stats_manager);
		self->priv->stats_manager = NULL;
	}
	G_OBJECT_CLASS (ft_stats_month_page_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
}

static void
ft_stats_month_page_real_get_date (FtStatsPage* base,
                                   GDate * result)
{
	FtStatsMonthPage* self;
	GDate _tmp0_;
	self = (FtStatsMonthPage*) base;
	_tmp0_ = self->priv->_date;
	*result = _tmp0_;
	return;
}

static gboolean
_g_date_equal (const GDate * s1,
               const GDate * s2)
{
	if (s1 == s2) {
		return TRUE;
	}
	if (s1 == NULL) {
		return FALSE;
	}
	if (s2 == NULL) {
		return FALSE;
	}
	return FALSE;
}

static void
ft_stats_month_page_real_set_date (FtStatsPage* base,
                                   GDate * value)
{
	FtStatsMonthPage* self;
	GDate old_value;
	self = (FtStatsMonthPage*) base;
	ft_stats_month_page_real_get_date (base, &old_value);
	if (_g_date_equal (value, &old_value) != TRUE) {
		GDate _tmp0_;
		_tmp0_ = *value;
		self->priv->_date = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, ft_stats_month_page_properties[FT_STATS_MONTH_PAGE_DATE_PROPERTY]);
	}
}

static void
_ft_stats_month_page___lambda26_ (FtStatsMonthPage* self,
                                  GObject* obj,
                                  GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	ft_stats_month_page_populate_finish (self, res);
}

static void
__ft_stats_month_page___lambda26__gasync_ready_callback (GObject* source_object,
                                                         GAsyncResult* res,
                                                         gpointer self)
{
	_ft_stats_month_page___lambda26_ ((FtStatsMonthPage*) self, source_object, res);
	g_object_unref (self);
}

static GObject *
ft_stats_month_page_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtStatsMonthPage * self;
	FtStatsManager* _tmp0_;
	FtStatsManager* _tmp1_;
	FtStatsManager* _tmp2_;
	FtBubbleChart* _tmp3_;
	FtBubbleChart* _tmp4_;
	FtBubbleChart* _tmp5_;
	FtBubbleChart* _tmp6_;
	FtBubbleChart* _tmp7_;
	FtBubbleChart* _tmp8_;
	FtBubbleChart* _tmp9_;
	GDateMonth month = 0;
	GDate _tmp10_ = {0};
	GDate _tmp11_;
	GDateYear year = (GDateYear) 0U;
	GDate _tmp12_ = {0};
	GDate _tmp13_;
	GDate month_start_date = {0};
	GDate month_end_date = {0};
	GDate _tmp14_;
	GDate _tmp15_ = {0};
	GDate _tmp16_;
	GDate _tmp17_ = {0};
	parent_class = G_OBJECT_CLASS (ft_stats_month_page_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_MONTH_PAGE, FtStatsMonthPage);
	_tmp0_ = ft_stats_manager_new ();
	_g_object_unref0 (self->priv->stats_manager);
	self->priv->stats_manager = _tmp0_;
	_tmp1_ = self->priv->stats_manager;
	g_signal_connect_object (_tmp1_, "entry-saved", (GCallback) _ft_stats_month_page_on_entry_saved_ft_stats_manager_entry_saved, self, 0);
	_tmp2_ = self->priv->stats_manager;
	g_signal_connect_object (_tmp2_, "entry-deleted", (GCallback) _ft_stats_month_page_on_entry_deleted_ft_stats_manager_entry_deleted, self, 0);
	_tmp3_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category (_tmp3_, (guint) FT_STATS_CATEGORY_POMODORO);
	_tmp4_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_label (_tmp4_, (guint) FT_STATS_CATEGORY_POMODORO, _ ("Pomodoro"));
	_tmp5_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_unit (_tmp5_, (guint) FT_STATS_CATEGORY_POMODORO, FT_UNIT_INTERVAL);
	_tmp6_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_label (_tmp6_, (guint) FT_STATS_CATEGORY_BREAK, _ ("Breaks"));
	_tmp7_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_unit (_tmp7_, (guint) FT_STATS_CATEGORY_BREAK, FT_UNIT_INTERVAL);
	_tmp8_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_label (_tmp8_, (guint) FT_STATS_CATEGORY_INTERRUPTION, _ ("Interruptions"));
	_tmp9_ = self->priv->bubble_chart;
	ft_bubble_chart_set_category_unit (_tmp9_, (guint) FT_STATS_CATEGORY_INTERRUPTION, FT_UNIT_AMOUNT);
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp10_);
	_tmp11_ = _tmp10_;
	month = g_date_get_month (&_tmp11_);
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp12_);
	_tmp13_ = _tmp12_;
	year = g_date_get_year (&_tmp13_);
	memset (&month_start_date, 0, sizeof (GDate));
	g_date_set_dmy (&month_start_date, (GDateDay) 1, (gint) month, year);
	memset (&month_end_date, 0, sizeof (GDate));
	g_date_set_dmy (&month_end_date, (GDateDay) g_date_get_days_in_month (month, year), (gint) month, year);
	_tmp14_ = month_start_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp14_, &_tmp15_);
	self->priv->display_start_date = _tmp15_;
	_tmp16_ = month_end_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp16_, &_tmp17_);
	self->priv->display_end_date = _tmp17_;
	g_date_add_days (&self->priv->display_end_date, 6U);
	ft_stats_month_page_populate (self, __ft_stats_month_page___lambda26__gasync_ready_callback, g_object_ref (self));
	return obj;
}

static void
ft_stats_month_page_class_init (FtStatsMonthPageClass * klass,
                                gpointer klass_data)
{
	ft_stats_month_page_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsMonthPage_private_offset);
	((GtkWidgetClass *) klass)->css_changed = (void (*) (GtkWidget*, GtkCssStyleChange*)) ft_stats_month_page_real_css_changed;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_stats_month_page_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_month_page_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_month_page_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_stats_month_page_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_month_page_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_MONTH_PAGE_DATE_PROPERTY, ft_stats_month_page_properties[FT_STATS_MONTH_PAGE_DATE_PROPERTY] = g_param_spec_boxed ("date", "date", "date", G_TYPE_DATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/stats-month-page.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "bubble_chart", FALSE, FtStatsMonthPage_private_offset + G_STRUCT_OFFSET (FtStatsMonthPagePrivate, bubble_chart));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pomodoro_card", FALSE, FtStatsMonthPage_private_offset + G_STRUCT_OFFSET (FtStatsMonthPagePrivate, pomodoro_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "breaks_card", FALSE, FtStatsMonthPage_private_offset + G_STRUCT_OFFSET (FtStatsMonthPagePrivate, breaks_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "interruptions_card", FALSE, FtStatsMonthPage_private_offset + G_STRUCT_OFFSET (FtStatsMonthPagePrivate, interruptions_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "break_ratio_card", FALSE, FtStatsMonthPage_private_offset + G_STRUCT_OFFSET (FtStatsMonthPagePrivate, break_ratio_card));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_bubble_activated", G_CALLBACK(_ft_stats_month_page_on_bubble_activated_ft_bubble_chart_bubble_activated));
}

static void
ft_stats_month_page_ft_stats_page_interface_init (FtStatsPageIface * iface,
                                                  gpointer iface_data)
{
	ft_stats_month_page_ft_stats_page_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_date = ft_stats_month_page_real_get_date;
	iface->set_date = ft_stats_month_page_real_set_date;
}

static void
ft_stats_month_page_instance_init (FtStatsMonthPage * self,
                                   gpointer klass)
{
	self->priv = ft_stats_month_page_get_instance_private (self);
	g_type_ensure (FT_TYPE_BUBBLE_CHART);
	g_type_ensure (FT_TYPE_STATS_CARD);
	g_type_ensure (FT_TYPE_STATS_CARD);
	g_type_ensure (FT_TYPE_STATS_CARD);
	g_type_ensure (FT_TYPE_STATS_CARD);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_stats_month_page_finalize (GObject * obj)
{
	FtStatsMonthPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_MONTH_PAGE, FtStatsMonthPage);
	_g_object_unref0 (self->priv->stats_manager);
	G_OBJECT_CLASS (ft_stats_month_page_parent_class)->finalize (obj);
}

static GType
ft_stats_month_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsMonthPageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_month_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsMonthPage), 0, (GInstanceInitFunc) ft_stats_month_page_instance_init, NULL };
	static const GInterfaceInfo ft_stats_page_info = { (GInterfaceInitFunc) ft_stats_month_page_ft_stats_page_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType ft_stats_month_page_type_id;
	ft_stats_month_page_type_id = g_type_register_static (adw_bin_get_type (), "FtStatsMonthPage", &g_define_type_info, 0);
	g_type_add_interface_static (ft_stats_month_page_type_id, FT_TYPE_STATS_PAGE, &ft_stats_page_info);
	FtStatsMonthPage_private_offset = g_type_add_instance_private (ft_stats_month_page_type_id, sizeof (FtStatsMonthPagePrivate));
	return ft_stats_month_page_type_id;
}

GType
ft_stats_month_page_get_type (void)
{
	static volatile gsize ft_stats_month_page_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_month_page_type_id__once)) {
		GType ft_stats_month_page_type_id;
		ft_stats_month_page_type_id = ft_stats_month_page_get_type_once ();
		g_once_init_leave (&ft_stats_month_page_type_id__once, ft_stats_month_page_type_id);
	}
	return ft_stats_month_page_type_id__once;
}

static void
_vala_ft_stats_month_page_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	FtStatsMonthPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_MONTH_PAGE, FtStatsMonthPage);
	switch (property_id) {
		case FT_STATS_MONTH_PAGE_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_page_get_date ((FtStatsPage*) self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_stats_month_page_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	FtStatsMonthPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_MONTH_PAGE, FtStatsMonthPage);
	switch (property_id) {
		case FT_STATS_MONTH_PAGE_DATE_PROPERTY:
		ft_stats_page_set_date ((FtStatsPage*) self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

