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

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

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

#define FT_STATS_DAY_PAGE_DEFAULT_INTERVAL (1 * FT_INTERVAL_HOUR)
#define FT_STATS_DAY_PAGE_MIN_INTERVAL (15 * FT_INTERVAL_MINUTE)
#define FT_STATS_DAY_PAGE_MAX_INTERVAL (2 * FT_INTERVAL_HOUR)
#define FT_STATS_DAY_PAGE_BASE_START_HOUR 9
#define FT_STATS_DAY_PAGE_BASE_END_HOUR 17
#define FT_STATS_DAY_PAGE_MIN_HISTOGRAM_BAR_COUNT 8
#define FT_STATS_DAY_PAGE_MIN_SIGNIFICANT_DURATION FT_INTERVAL_MINUTE
#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_DAY_PAGE_0_PROPERTY,
	FT_STATS_DAY_PAGE_DATE_PROPERTY,
	FT_STATS_DAY_PAGE_INTERVAL_PROPERTY,
	FT_STATS_DAY_PAGE_NUM_PROPERTIES
};
static GParamSpec* ft_stats_day_page_properties[FT_STATS_DAY_PAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _ft_matrix_free0(var) ((var == NULL) ? NULL : (var = (ft_matrix_free (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
typedef struct _Block12Data Block12Data;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _FtStatsDayPageFetchEntriesData FtStatsDayPageFetchEntriesData;
typedef struct _FtStatsDayPagePopulateData FtStatsDayPagePopulateData;
#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 _FtStatsDayPagePrivate {
	GDate _date;
	GtkRevealer* toolbar_revealer;
	GtkButton* zoom_in_button;
	GtkButton* zoom_out_button;
	FtBarChart* histogram;
	FtStatsCard* pomodoro_card;
	FtStatsCard* breaks_card;
	FtStatsCard* interruptions_card;
	FtStatsCard* break_ratio_card;
	gint64 _interval;
	FtStatsManager* stats_manager;
	FtTimezoneHistory* timezone_history;
	GDateTime* datetime;
	gint64 timestamp;
	gint64 start_time;
	gint64 end_time;
	gint64 entries_start_time;
	gint64 entries_end_time;
	gchar* time_format;
	FtMatrix* histogram_data;
};

struct _Block12Data {
	int _ref_count_;
	FtStatsDayPage* self;
	GDateTime** datetimes;
	gint datetimes_length1;
	gint _datetimes_size_;
	gint64 timestamp;
};

struct _FtStatsDayPageFetchEntriesData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsDayPage* self;
	GomResourceGroup* result;
	GomRepository* repository;
	GomRepository* _tmp0_;
	GomRepository* _tmp1_;
	GValue date_value;
	GValue _tmp2_;
	GDate _tmp3_;
	GDate _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GomFilter* date_filter;
	GValue _tmp7_;
	GomFilter* _tmp8_;
	GomSorting* sorting;
	GObject* _tmp9_;
	GObject* _tmp10_;
	GomSorting* _tmp11_;
	GomResourceGroup* entries;
	GomRepository* _tmp12_;
	GomFilter* _tmp13_;
	GomSorting* _tmp14_;
	GomResourceGroup* _tmp15_;
	GomResourceGroup* _tmp16_;
	GomResourceGroup* _tmp17_;
	guint _tmp18_;
	guint _tmp19_;
	GError* _error_;
	GError* _tmp20_;
	const gchar* _tmp21_;
	GError* _inner_error0_;
};

struct _FtStatsDayPagePopulateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsDayPage* self;
	GomResourceGroup* entries;
	GomResourceGroup* _tmp0_;
	GomResourceGroup* _tmp1_;
	guint index;
	gboolean _tmp2_;
	guint _tmp3_;
	GomResourceGroup* _tmp4_;
	guint _tmp5_;
	guint _tmp6_;
	GomResourceGroup* _tmp7_;
	GomResource* _tmp8_;
};

static gint FtStatsDayPage_private_offset;
static gpointer ft_stats_day_page_parent_class = NULL;
static FtStatsPageIface * ft_stats_day_page_ft_stats_page_parent_iface = NULL;

static FtMatrix* ft_stats_day_page_create_histogram_data (FtStatsDayPage* self);
static gchar* ft_stats_day_page_format_hours (gdouble value);
static gchar* ft_stats_day_page_format_minutes (gdouble value);
static inline gchar* ft_stats_day_page_format_time (FtStatsDayPage* self,
                                      GDateTime* datetime);
static void ft_stats_day_page_ensure_histogram_data (FtStatsDayPage* self);
static void ft_stats_day_page_update_category_colors (FtStatsDayPage* 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_day_page_update_time_format (FtStatsDayPage* self);
static void ft_stats_day_page_update_histogram_y_spacing (FtStatsDayPage* self);
static gchar* _ft_stats_day_page_format_hours_ft_format_value_func (gdouble value,
                                                             gpointer self);
static gchar* _ft_stats_day_page_format_minutes_ft_format_value_func (gdouble value,
                                                               gpointer self);
static void ft_stats_day_page_update_histogram_buckets (FtStatsDayPage* self);
static Block12Data* block12_data_ref (Block12Data* _data12_);
static void block12_data_unref (void * _userdata_);
static void __lambda23_ (Block12Data* _data12_,
                  gint64 start_time,
                  gint64 end_time,
                  GTimeZone* timezone);
static void _vala_array_add1 (GDateTime** * array,
                       gint* length,
                       gint* size,
                       GDateTime* value);
static void ___lambda23__ft_timezone_scan_func (gint64 start_time,
                                         gint64 end_time,
                                         GTimeZone* timezone,
                                         gpointer self);
static void ft_stats_day_page_update_histogram_transform (FtStatsDayPage* self);
static void ft_stats_day_page_fetch_entries_data_free (gpointer _data);
static void ft_stats_day_page_fetch_entries (FtStatsDayPage* self,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static GomResourceGroup* ft_stats_day_page_fetch_entries_finish (FtStatsDayPage* self,
                                                          GAsyncResult* _res_);
static gboolean ft_stats_day_page_fetch_entries_co (FtStatsDayPageFetchEntriesData* _data_);
static void ft_stats_day_page_fetch_entries_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void ft_stats_day_page_extend_time_range (FtStatsDayPage* self,
                                          gint64 entry_start_time,
                                          gint64 entry_end_time);
static void ft_stats_day_page_update_time_range (FtStatsDayPage* self);
static void ft_stats_day_page_process_entry (FtStatsDayPage* self,
                                      FtStatsEntry* entry,
                                      gint sign);
static void ft_stats_day_page_aggregate_data (FtStatsDayPage* self);
static void ft_stats_day_page_update_entries_time_range (FtStatsDayPage* self,
                                                  GomResourceGroup* entries);
static void ft_stats_day_page_reset (FtStatsDayPage* self);
static void ft_stats_day_page_populate_data_free (gpointer _data);
static void ft_stats_day_page_populate (FtStatsDayPage* self,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
static void ft_stats_day_page_populate_finish (FtStatsDayPage* self,
                                        GAsyncResult* _res_);
static gboolean ft_stats_day_page_populate_co (FtStatsDayPagePopulateData* _data_);
static void ft_stats_day_page_populate_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
static void ft_stats_day_page_invalidate_histogram_data (FtStatsDayPage* self);
static void ft_stats_day_page_on_interval_notify (FtStatsDayPage* self);
static void ft_stats_day_page_on_entry_saved (FtStatsDayPage* self,
                                       FtStatsEntry* entry);
static void ft_stats_day_page_on_entry_deleted (FtStatsDayPage* self,
                                         FtStatsEntry* entry);
static void ft_stats_day_page_on_timezone_history_changed (FtStatsDayPage* self);
static void ___lambda24_ (FtStatsDayPage* self,
                   GObject* obj,
                   GAsyncResult* res);
static void ____lambda24__gasync_ready_callback (GObject* source_object,
                                          GAsyncResult* res,
                                          gpointer self);
static void ft_stats_day_page_on_zoom_in (FtStatsDayPage* self);
static void _ft_stats_day_page_on_zoom_in_ft_chart_zoom_in (FtChart* _sender,
                                                     gpointer self);
static void ft_stats_day_page_on_zoom_out (FtStatsDayPage* self);
static void _ft_stats_day_page_on_zoom_out_ft_chart_zoom_out (FtChart* _sender,
                                                       gpointer self);
static void ft_stats_day_page_on_histogram_enter (FtStatsDayPage* self,
                                           gdouble x,
                                           gdouble y);
static void _ft_stats_day_page_on_histogram_enter_gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                                              gdouble x,
                                                                              gdouble y,
                                                                              gpointer self);
static void ft_stats_day_page_on_histogram_leave (FtStatsDayPage* self);
static void _ft_stats_day_page_on_histogram_leave_gtk_event_controller_motion_leave (GtkEventControllerMotion* _sender,
                                                                              gpointer self);
static void ft_stats_day_page_real_css_changed (GtkWidget* base,
                                         GtkCssStyleChange* change);
static void ft_stats_day_page_real_dispose (GObject* base);
static void _ft_stats_day_page_on_entry_saved_ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                     FtStatsEntry* entry,
                                                                     gpointer self);
static void _ft_stats_day_page_on_entry_deleted_ft_stats_manager_entry_deleted (FtStatsManager* _sender,
                                                                         FtStatsEntry* entry,
                                                                         gpointer self);
static void _ft_stats_day_page_on_timezone_history_changed_ft_timezone_history_changed (FtTimezoneHistory* _sender,
                                                                                 gpointer self);
static gboolean _g_date_equal (const GDate * s1,
                        const GDate * s2);
static GObject * ft_stats_day_page_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void _ft_stats_day_page___lambda25_ (FtStatsDayPage* self,
                                     GObject* obj,
                                     GAsyncResult* res);
static void __ft_stats_day_page___lambda25__gasync_ready_callback (GObject* source_object,
                                                            GAsyncResult* res,
                                                            gpointer self);
static void ft_stats_day_page_finalize (GObject * obj);
static GType ft_stats_day_page_get_type_once (void);
static void _vala_ft_stats_day_page_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_ft_stats_day_page_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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_stats_day_page_get_instance_private (FtStatsDayPage* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsDayPage_private_offset);
}

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

FtStatsDayPage*
ft_stats_day_page_new (GDate* date)
{
	return ft_stats_day_page_construct (FT_TYPE_STATS_DAY_PAGE, date);
}

/**
         * Create data container sampled at `MIN_INTERVAL` for the whole day.
         * `this.histogram` by comparison is holding displayed time range only.
         */
static FtMatrix*
ft_stats_day_page_create_histogram_data (FtStatsDayPage* self)
{
	guint bucket_count = 0U;
	FtBarChart* _tmp0_;
	FtMatrix* _tmp1_;
	FtMatrix* result;
	g_return_val_if_fail (self != NULL, NULL);
	bucket_count = (guint) ((36 * FT_INTERVAL_HOUR) / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	_tmp0_ = self->priv->histogram;
	_tmp1_ = ft_matrix_new (bucket_count, ft_bar_chart_get_categories_count (_tmp0_));
	result = _tmp1_;
	return result;
}

static gchar*
ft_stats_day_page_format_hours (gdouble value)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = ft_interval_format_short (ft_interval_from_seconds (value), FT_INTERVAL_HOUR);
	result = _tmp0_;
	return result;
}

static gchar*
ft_stats_day_page_format_minutes (gdouble value)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = ft_interval_format_short (ft_interval_from_seconds (value), FT_INTERVAL_MINUTE);
	result = _tmp0_;
	return result;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static inline gchar*
ft_stats_day_page_format_time (FtStatsDayPage* self,
                               GDateTime* datetime)
{
	gchar* time_string = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (datetime != NULL, NULL);
	_tmp0_ = self->priv->time_format;
	_tmp1_ = g_date_time_format (datetime, _tmp0_);
	time_string = _tmp1_;
	_tmp2_ = time_string;
	if (g_str_has_prefix (_tmp2_, "0")) {
		const gchar* _tmp3_;
		gchar* _tmp4_;
		_tmp3_ = time_string;
		_tmp4_ = string_substring (_tmp3_, (glong) 1, (glong) -1);
		_g_free0 (time_string);
		time_string = _tmp4_;
	}
	result = time_string;
	return result;
}

static void
ft_stats_day_page_ensure_histogram_data (FtStatsDayPage* self)
{
	FtMatrix* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->histogram_data;
	if (_tmp0_ == NULL) {
		FtMatrix* _tmp1_;
		_tmp1_ = ft_stats_day_page_create_histogram_data (self);
		_ft_matrix_free0 (self->priv->histogram_data);
		self->priv->histogram_data = _tmp1_;
	}
}

static void
ft_stats_day_page_update_category_colors (FtStatsDayPage* self)
{
	GdkRGBA foreground_color = {0};
	FtBarChart* _tmp0_;
	GdkRGBA _tmp1_ = {0};
	GdkRGBA pomodoro_color = {0};
	GdkRGBA _tmp2_;
	GdkRGBA _tmp3_ = {0};
	GdkRGBA break_color = {0};
	GdkRGBA _tmp4_;
	GdkRGBA _tmp5_ = {0};
	FtBarChart* _tmp6_;
	GdkRGBA _tmp7_;
	FtBarChart* _tmp8_;
	GdkRGBA _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->histogram;
	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->histogram;
	_tmp7_ = pomodoro_color;
	ft_bar_chart_set_category_color (_tmp6_, (guint) FT_STATS_CATEGORY_POMODORO, &_tmp7_);
	_tmp8_ = self->priv->histogram;
	_tmp9_ = break_color;
	ft_bar_chart_set_category_color (_tmp8_, (guint) FT_STATS_CATEGORY_BREAK, &_tmp9_);
}

static gchar*
string_replace (const gchar* self,
                const gchar* old,
                const gchar* replacement)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (old != NULL, NULL);
	g_return_val_if_fail (replacement != NULL, NULL);
	if ((*((gchar*) self)) == '\0') {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = (*((gchar*) old)) == '\0';
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = g_strcmp0 (old, replacement) == 0;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (self);
		result = _tmp2_;
		return result;
	}
	{
		GRegex* regex = NULL;
		gchar* _tmp3_;
		gchar* _tmp4_;
		GRegex* _tmp5_;
		GRegex* _tmp6_;
		gchar* _tmp7_ = NULL;
		GRegex* _tmp8_;
		gchar* _tmp9_;
		gchar* _tmp10_;
		_tmp3_ = g_regex_escape_string (old, -1);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_regex_new (_tmp4_, 0, 0, &_inner_error0_);
		_tmp6_ = _tmp5_;
		_g_free0 (_tmp4_);
		regex = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp8_ = regex;
		_tmp9_ = g_regex_replace_literal (_tmp8_, self, (gssize) -1, 0, replacement, 0, &_inner_error0_);
		_tmp7_ = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_regex_unref0 (regex);
			if (_inner_error0_->domain == G_REGEX_ERROR) {
				goto __catch0_g_regex_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp10_ = _tmp7_;
		_tmp7_ = NULL;
		result = _tmp10_;
		_g_free0 (_tmp7_);
		_g_regex_unref0 (regex);
		return result;
	}
	goto __finally0;
	__catch0_g_regex_error:
	{
		g_clear_error (&_inner_error0_);
		g_assert_not_reached ();
	}
	__finally0:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return NULL;
}

static void
ft_stats_day_page_update_time_format (FtStatsDayPage* self)
{
	gboolean use_12h_format = FALSE;
	gchar* time_format = NULL;
	gchar* _tmp0_;
	gboolean _tmp1_ = FALSE;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	use_12h_format = ft_locale_use_12h_format ();
	_tmp0_ = g_strdup ("%H");
	time_format = _tmp0_;
	if (self->priv->_interval < FT_INTERVAL_HOUR) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = !use_12h_format;
	}
	if (_tmp1_) {
		const gchar* _tmp2_;
		gchar* _tmp3_;
		_tmp2_ = time_format;
		_tmp3_ = g_strconcat (_tmp2_, ":%M", NULL);
		_g_free0 (time_format);
		time_format = _tmp3_;
	}
	if (use_12h_format) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		_tmp4_ = time_format;
		_tmp5_ = string_replace (_tmp4_, "%H", "%I");
		_tmp6_ = _tmp5_;
		_tmp7_ = g_strconcat (_tmp6_, " %p", NULL);
		_g_free0 (time_format);
		time_format = _tmp7_;
		_g_free0 (_tmp6_);
	}
	_tmp8_ = time_format;
	_tmp9_ = g_strdup (_tmp8_);
	_g_free0 (self->priv->time_format);
	self->priv->time_format = _tmp9_;
	_g_free0 (time_format);
}

static gchar*
_ft_stats_day_page_format_hours_ft_format_value_func (gdouble value,
                                                      gpointer self)
{
	gchar* result;
	result = ft_stats_day_page_format_hours (value);
	return result;
}

static gchar*
_ft_stats_day_page_format_minutes_ft_format_value_func (gdouble value,
                                                        gpointer self)
{
	gchar* result;
	result = ft_stats_day_page_format_minutes (value);
	return result;
}

static void
ft_stats_day_page_update_histogram_y_spacing (FtStatsDayPage* self)
{
	gfloat _tmp0_ = 0.0F;
	gfloat y_spacing = 0.0F;
	FtBarChart* _tmp1_;
	FtBarChart* _tmp2_;
	g_return_if_fail (self != NULL);
	if (self->priv->_interval <= FT_INTERVAL_HOUR) {
		_tmp0_ = ((gfloat) ft_interval_to_seconds (self->priv->_interval)) / 3.0f;
	} else {
		_tmp0_ = 3600.0f;
	}
	y_spacing = _tmp0_;
	_tmp1_ = self->priv->histogram;
	ft_chart_set_y_spacing ((FtChart*) _tmp1_, y_spacing);
	_tmp2_ = self->priv->histogram;
	ft_bar_chart_set_reference_value (_tmp2_, (gfloat) ft_interval_to_seconds (self->priv->_interval));
	if (y_spacing >= 3600.0f) {
		FtBarChart* _tmp3_;
		_tmp3_ = self->priv->histogram;
		ft_chart_set_format_value_func ((FtChart*) _tmp3_, _ft_stats_day_page_format_hours_ft_format_value_func, NULL, NULL);
	} else {
		FtBarChart* _tmp4_;
		_tmp4_ = self->priv->histogram;
		ft_chart_set_format_value_func ((FtChart*) _tmp4_, _ft_stats_day_page_format_minutes_ft_format_value_func, NULL, NULL);
	}
}

static Block12Data*
block12_data_ref (Block12Data* _data12_)
{
	g_atomic_int_inc (&_data12_->_ref_count_);
	return _data12_;
}

static void
block12_data_unref (void * _userdata_)
{
	Block12Data* _data12_;
	_data12_ = (Block12Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data12_->_ref_count_)) {
		FtStatsDayPage* self;
		self = _data12_->self;
		_data12_->datetimes = (_vala_array_free (_data12_->datetimes, _data12_->datetimes_length1, (GDestroyNotify) g_date_time_unref), NULL);
		_g_object_unref0 (self);
		g_slice_free (Block12Data, _data12_);
	}
}

static void
_vala_array_add1 (GDateTime** * array,
                  gint* length,
                  gint* size,
                  GDateTime* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (GDateTime*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
__lambda23_ (Block12Data* _data12_,
             gint64 start_time,
             gint64 end_time,
             GTimeZone* timezone)
{
	FtStatsDayPage* self;
	self = _data12_->self;
	g_return_if_fail (timezone != NULL);
	while (TRUE) {
		GDateTime* _tmp0_;
		if (!(_data12_->timestamp < end_time)) {
			break;
		}
		_tmp0_ = ft_timestamp_to_datetime (_data12_->timestamp, timezone);
		_vala_array_add1 (&_data12_->datetimes, &_data12_->datetimes_length1, &_data12_->_datetimes_size_, _tmp0_);
		_data12_->timestamp += self->priv->_interval;
	}
}

static void
___lambda23__ft_timezone_scan_func (gint64 start_time,
                                    gint64 end_time,
                                    GTimeZone* timezone,
                                    gpointer self)
{
	__lambda23_ (self, start_time, end_time, timezone);
}

static void
ft_stats_day_page_update_histogram_buckets (FtStatsDayPage* self)
{
	Block12Data* _data12_;
	GDateTime** _tmp0_;
	FtTimezoneHistory* _tmp1_;
	FtBarChart* _tmp2_;
	g_return_if_fail (self != NULL);
	_data12_ = g_slice_new0 (Block12Data);
	_data12_->_ref_count_ = 1;
	_data12_->self = g_object_ref (self);
	_tmp0_ = g_new0 (GDateTime*, 0 + 1);
	_data12_->datetimes = _tmp0_;
	_data12_->datetimes_length1 = 0;
	_data12_->_datetimes_size_ = _data12_->datetimes_length1;
	_data12_->timestamp = self->priv->start_time;
	_tmp1_ = self->priv->timezone_history;
	ft_timezone_history_scan (_tmp1_, self->priv->start_time, self->priv->end_time + self->priv->_interval, ___lambda23__ft_timezone_scan_func, _data12_);
	_tmp2_ = self->priv->histogram;
	ft_bar_chart_remove_all_bars (_tmp2_);
	{
		gint bar_index = 0;
		bar_index = 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				GDateTime** _tmp5_;
				gint _tmp5__length1;
				gchar* bar_label = NULL;
				GDateTime** _tmp6_;
				gint _tmp6__length1;
				GDateTime* _tmp7_;
				gchar* _tmp8_;
				gchar* tooltip_label = NULL;
				const gchar* _tmp9_;
				GDateTime** _tmp10_;
				gint _tmp10__length1;
				GDateTime* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				FtBarChart* _tmp16_;
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = bar_index;
					bar_index = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp5_ = _data12_->datetimes;
				_tmp5__length1 = _data12_->datetimes_length1;
				if (!(bar_index < (_tmp5__length1 - 1))) {
					break;
				}
				_tmp6_ = _data12_->datetimes;
				_tmp6__length1 = _data12_->datetimes_length1;
				_tmp7_ = _tmp6_[bar_index];
				_tmp8_ = ft_stats_day_page_format_time (self, _tmp7_);
				bar_label = _tmp8_;
				_tmp9_ = bar_label;
				_tmp10_ = _data12_->datetimes;
				_tmp10__length1 = _data12_->datetimes_length1;
				_tmp11_ = _tmp10_[bar_index + 1];
				_tmp12_ = ft_stats_day_page_format_time (self, _tmp11_);
				_tmp13_ = _tmp12_;
				_tmp14_ = g_strdup_printf ("%s － %s", _tmp9_, _tmp13_);
				_tmp15_ = _tmp14_;
				_g_free0 (_tmp13_);
				tooltip_label = _tmp15_;
				_tmp16_ = self->priv->histogram;
				_tmp17_ = bar_label;
				_tmp18_ = tooltip_label;
				ft_bar_chart_set_bar_label (_tmp16_, (guint) bar_index, _tmp17_, _tmp18_);
				_g_free0 (tooltip_label);
				_g_free0 (bar_label);
			}
		}
	}
	block12_data_unref (_data12_);
	_data12_ = NULL;
}

/**
         * Set a transform from `bar_index` to `bucket_index`
         */
static void
ft_stats_day_page_update_histogram_transform (FtStatsDayPage* self)
{
	gint64 bars_per_bucket = 0LL;
	gint64 bucket_start_index = 0LL;
	FtBarChart* _tmp0_;
	g_return_if_fail (self != NULL);
	bars_per_bucket = self->priv->_interval / FT_STATS_DAY_PAGE_MIN_INTERVAL;
	bucket_start_index = (self->priv->start_time - self->priv->timestamp) / FT_STATS_DAY_PAGE_MIN_INTERVAL;
	_tmp0_ = self->priv->histogram;
	ft_bar_chart_set_transform (_tmp0_, (gdouble) bars_per_bucket, (gdouble) bucket_start_index);
}

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

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

static void
ft_stats_day_page_fetch_entries (FtStatsDayPage* self,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	FtStatsDayPageFetchEntriesData* _data_;
	FtStatsDayPage* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtStatsDayPageFetchEntriesData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_day_page_fetch_entries_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_stats_day_page_fetch_entries_co (_data_);
}

static GomResourceGroup*
ft_stats_day_page_fetch_entries_finish (FtStatsDayPage* self,
                                        GAsyncResult* _res_)
{
	GomResourceGroup* result;
	FtStatsDayPageFetchEntriesData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
ft_stats_day_page_fetch_entries_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	FtStatsDayPageFetchEntriesData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_day_page_fetch_entries_co (_data_);
}

static gboolean
ft_stats_day_page_fetch_entries_co (FtStatsDayPageFetchEntriesData* _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_->date_value = _data_->_tmp2_;
	memset (&_data_->_tmp3_, 0, sizeof (GDate));
	ft_stats_page_get_date ((FtStatsPage*) _data_->self, &_data_->_tmp3_);
	_data_->_tmp4_ = _data_->_tmp3_;
	_data_->_tmp5_ = ft_database_serialize_date (&_data_->_tmp4_);
	_data_->_tmp6_ = _data_->_tmp5_;
	g_value_set_string (&_data_->date_value, _data_->_tmp6_);
	_g_free0 (_data_->_tmp6_);
	_data_->_tmp7_ = _data_->date_value;
	_data_->_tmp8_ = gom_filter_new_eq (FT_TYPE_STATS_ENTRY, "date", &_data_->_tmp7_);
	g_object_ref_sink (_data_->_tmp8_);
	_data_->date_filter = _data_->_tmp8_;
	_data_->_tmp9_ = g_object_new (gom_sorting_get_type (), NULL);
	_data_->_tmp10_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp9_) ? g_object_ref_sink (_data_->_tmp9_) : _data_->_tmp9_;
	_data_->sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp10_, gom_sorting_get_type (), GomSorting);
	_data_->_tmp11_ = _data_->sorting;
	gom_sorting_add (_data_->_tmp11_, FT_TYPE_STATS_ENTRY, "time", GOM_SORTING_ASCENDING);
	{
		_data_->_tmp12_ = _data_->repository;
		_data_->_tmp13_ = _data_->date_filter;
		_data_->_tmp14_ = _data_->sorting;
		_data_->_state_ = 1;
		gom_repository_find_sorted_async (_data_->_tmp12_, FT_TYPE_STATS_ENTRY, _data_->_tmp13_, _data_->_tmp14_, ft_stats_day_page_fetch_entries_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp15_ = gom_repository_find_finish (_data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
		_data_->entries = _data_->_tmp15_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp16_ = _data_->entries;
		_data_->_tmp17_ = _data_->entries;
		_data_->_tmp18_ = gom_resource_group_get_count (_data_->_tmp17_);
		_data_->_tmp19_ = _data_->_tmp18_;
		_data_->_state_ = 2;
		gom_resource_group_fetch_async (_data_->_tmp16_, 0U, _data_->_tmp19_, ft_stats_day_page_fetch_entries_ready, _data_);
		return FALSE;
		_state_2:
		gom_resource_group_fetch_finish (_data_->_tmp16_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->entries);
			goto __catch0_g_error;
		}
		_data_->result = _data_->entries;
		_g_object_unref0 (_data_->sorting);
		_g_object_unref0 (_data_->date_filter);
		G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->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_->_tmp20_ = _data_->_error_;
		_data_->_tmp21_ = _data_->_tmp20_->message;
		g_critical ("stats-day-page.vala:264: Error while fetching daily stats: %s", _data_->_tmp21_);
		_data_->result = NULL;
		_g_error_free0 (_data_->_error_);
		_g_object_unref0 (_data_->sorting);
		_g_object_unref0 (_data_->date_filter);
		G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->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_->sorting);
	_g_object_unref0 (_data_->date_filter);
	G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->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_day_page_extend_time_range (FtStatsDayPage* self,
                                     gint64 entry_start_time,
                                     gint64 entry_end_time)
{
	gboolean changed = FALSE;
	g_return_if_fail (self != NULL);
	changed = FALSE;
	if (self->priv->entries_start_time > entry_start_time) {
		self->priv->entries_start_time = entry_start_time;
		changed = TRUE;
	}
	if (self->priv->entries_end_time < entry_end_time) {
		self->priv->entries_end_time = entry_end_time;
		changed = TRUE;
	}
	if (changed) {
		ft_stats_day_page_update_time_range (self);
		ft_stats_day_page_update_histogram_transform (self);
		ft_stats_day_page_update_histogram_buckets (self);
	}
}

static void
ft_stats_day_page_process_entry (FtStatsDayPage* self,
                                 FtStatsEntry* entry,
                                 gint sign)
{
	FtMatrix* _tmp0_;
	gint entry_category = 0;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gint64 entry_time = 0LL;
	gint64 _tmp3_;
	gint64 _tmp4_;
	gint64 entry_duration = 0LL;
	gint64 _tmp5_;
	gint64 _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	GDate _tmp9_ = {0};
	GDate _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gboolean _tmp13_;
	gboolean _tmp14_ = FALSE;
	gint bucket_index = 0;
	gint category_index = 0;
	gint bars_per_bucket = 0;
	gint bucket_start_index = 0;
	gint64 remaining_duration = 0LL;
	gint64 remaining_offset = 0LL;
	gdouble total = 0.0;
	FtStatsCard* _tmp39_;
	gdouble _tmp40_;
	gdouble _tmp41_;
	FtStatsCard* _tmp42_;
	gdouble _tmp43_;
	gdouble _tmp44_;
	gdouble _tmp45_ = 0.0;
	FtStatsCard* _tmp49_;
	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_ = self->priv->histogram_data;
	g_return_if_fail (_tmp0_ != NULL);
	_tmp1_ = ft_stats_entry_get_category (entry);
	_tmp2_ = _tmp1_;
	entry_category = ft_stats_category_from_string (_tmp2_);
	_tmp3_ = ft_stats_entry_get_time (entry);
	_tmp4_ = _tmp3_;
	entry_time = _tmp4_;
	_tmp5_ = ft_stats_entry_get_duration (entry);
	_tmp6_ = _tmp5_;
	entry_duration = _tmp6_;
	if (entry_category == ((gint) FT_STATS_CATEGORY_INVALID)) {
		return;
	}
	_tmp7_ = ft_stats_entry_get_date (entry);
	_tmp8_ = _tmp7_;
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp9_);
	_tmp10_ = _tmp9_;
	_tmp11_ = ft_database_serialize_date (&_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strcmp0 (_tmp8_, _tmp12_) != 0;
	_g_free0 (_tmp12_);
	if (_tmp13_) {
		return;
	}
	if (entry_time < self->priv->timestamp) {
		entry_duration -= self->priv->timestamp - entry_time;
		entry_time = self->priv->timestamp;
	}
	if (entry_category != ((gint) FT_STATS_CATEGORY_INTERRUPTION)) {
		_tmp14_ = entry_duration >= FT_STATS_DAY_PAGE_MIN_SIGNIFICANT_DURATION;
	} else {
		_tmp14_ = FALSE;
	}
	if (_tmp14_) {
		ft_stats_day_page_extend_time_range (self, entry_time, entry_time + entry_duration);
	}
	bucket_index = (gint) ((entry_time - self->priv->timestamp) / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	category_index = (gint) entry_category;
	bars_per_bucket = (gint) (self->priv->_interval / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	bucket_start_index = (gint) ((self->priv->start_time - self->priv->timestamp) / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	remaining_duration = entry_duration;
	remaining_offset = entry_time - (self->priv->timestamp + (bucket_index * FT_STATS_DAY_PAGE_MIN_INTERVAL));
	while (TRUE) {
		gboolean _tmp15_ = FALSE;
		gboolean _tmp16_ = FALSE;
		gboolean _tmp17_ = FALSE;
		gint64 consumed_duration = 0LL;
		gdouble bucket_value = 0.0;
		FtMatrix* _tmp24_;
		gint _tmp26_;
		if (remaining_duration > ((gint64) 0)) {
			FtMatrix* _tmp18_;
			guint* _tmp19_;
			gint _tmp19__length1;
			guint _tmp20_;
			_tmp18_ = self->priv->histogram_data;
			_tmp19_ = _tmp18_->shape;
			_tmp19__length1 = _tmp18_->shape_length1;
			_tmp20_ = _tmp19_[0];
			_tmp17_ = ((guint) bucket_index) < _tmp20_;
		} else {
			_tmp17_ = FALSE;
		}
		if (_tmp17_) {
			FtMatrix* _tmp21_;
			guint* _tmp22_;
			gint _tmp22__length1;
			guint _tmp23_;
			_tmp21_ = self->priv->histogram_data;
			_tmp22_ = _tmp21_->shape;
			_tmp22__length1 = _tmp21_->shape_length1;
			_tmp23_ = _tmp22_[1];
			_tmp16_ = ((guint) category_index) < _tmp23_;
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			_tmp15_ = category_index != ((gint) FT_STATS_CATEGORY_INTERRUPTION);
		} else {
			_tmp15_ = FALSE;
		}
		if (!_tmp15_) {
			break;
		}
		consumed_duration = MIN (remaining_duration, FT_STATS_DAY_PAGE_MIN_INTERVAL - remaining_offset);
		bucket_value = ft_interval_to_seconds (sign * consumed_duration);
		_tmp24_ = self->priv->histogram_data;
		ft_matrix_add_value (_tmp24_, bucket_index, category_index, bucket_value);
		if (bucket_index >= bucket_start_index) {
			gint bar_index = 0;
			FtBarChart* _tmp25_;
			bar_index = (bucket_index - bucket_start_index) / bars_per_bucket;
			_tmp25_ = self->priv->histogram;
			ft_bar_chart_add_value (_tmp25_, (guint) bar_index, (guint) category_index, bucket_value);
		}
		remaining_duration -= consumed_duration;
		remaining_offset = (gint64) 0;
		_tmp26_ = bucket_index;
		bucket_index = _tmp26_ + 1;
	}
	switch (entry_category) {
		case FT_STATS_CATEGORY_POMODORO:
		{
			FtStatsCard* _tmp27_;
			FtStatsCard* _tmp28_;
			gdouble _tmp29_;
			gdouble _tmp30_;
			_tmp27_ = self->priv->pomodoro_card;
			_tmp28_ = self->priv->pomodoro_card;
			_tmp29_ = ft_stats_card_get_value (_tmp28_);
			_tmp30_ = _tmp29_;
			ft_stats_card_set_value (_tmp28_, _tmp30_ + ft_interval_to_seconds (sign * entry_duration));
			break;
		}
		case FT_STATS_CATEGORY_BREAK:
		{
			FtStatsCard* _tmp31_;
			FtStatsCard* _tmp32_;
			gdouble _tmp33_;
			gdouble _tmp34_;
			_tmp31_ = self->priv->breaks_card;
			_tmp32_ = self->priv->breaks_card;
			_tmp33_ = ft_stats_card_get_value (_tmp32_);
			_tmp34_ = _tmp33_;
			ft_stats_card_set_value (_tmp32_, _tmp34_ + ft_interval_to_seconds (sign * entry_duration));
			break;
		}
		case FT_STATS_CATEGORY_INTERRUPTION:
		{
			FtStatsCard* _tmp35_;
			FtStatsCard* _tmp36_;
			gdouble _tmp37_;
			gdouble _tmp38_;
			_tmp35_ = self->priv->interruptions_card;
			_tmp36_ = self->priv->interruptions_card;
			_tmp37_ = ft_stats_card_get_value (_tmp36_);
			_tmp38_ = _tmp37_;
			ft_stats_card_set_value (_tmp36_, _tmp38_ + ((gdouble) sign));
			break;
		}
		default:
		{
			break;
		}
	}
	_tmp39_ = self->priv->pomodoro_card;
	_tmp40_ = ft_stats_card_get_value (_tmp39_);
	_tmp41_ = _tmp40_;
	_tmp42_ = self->priv->breaks_card;
	_tmp43_ = ft_stats_card_get_value (_tmp42_);
	_tmp44_ = _tmp43_;
	total = _tmp41_ + _tmp44_;
	if (total >= 3600.0) {
		FtStatsCard* _tmp46_;
		gdouble _tmp47_;
		gdouble _tmp48_;
		_tmp46_ = self->priv->breaks_card;
		_tmp47_ = ft_stats_card_get_value (_tmp46_);
		_tmp48_ = _tmp47_;
		_tmp45_ = _tmp48_ / total;
	} else {
		_tmp45_ = ((double) NAN);
	}
	_tmp49_ = self->priv->break_ratio_card;
	ft_stats_card_set_value (_tmp49_, _tmp45_);
}

/**
         * Fill histogram with aggregated data
         */
static void
ft_stats_day_page_aggregate_data (FtStatsDayPage* self)
{
	FtBarChart* _tmp0_;
	FtMatrix* _tmp1_;
	gint bucket_start_index = 0;
	gint bucket_end_index = 0;
	gint buckets_per_bar = 0;
	gint categories_count = 0;
	FtMatrix* _tmp2_;
	guint* _tmp3_;
	gint _tmp3__length1;
	guint _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->histogram;
	ft_bar_chart_fill (_tmp0_, 0.0);
	_tmp1_ = self->priv->histogram_data;
	if (_tmp1_ == NULL) {
		return;
	}
	_vala_assert (self->priv->start_time >= self->priv->timestamp, "this.start_time >= this.timestamp");
	bucket_start_index = (gint) ((self->priv->start_time - self->priv->timestamp) / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	bucket_end_index = (gint) ((self->priv->end_time - self->priv->timestamp) / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	buckets_per_bar = (gint) (self->priv->_interval / FT_STATS_DAY_PAGE_MIN_INTERVAL);
	_tmp2_ = self->priv->histogram_data;
	_tmp3_ = _tmp2_->shape;
	_tmp3__length1 = _tmp2_->shape_length1;
	_tmp4_ = _tmp3_[1];
	categories_count = (gint) _tmp4_;
	if (bucket_start_index < 0) {
		bucket_start_index = 0;
	}
	{
		gint category_index = 0;
		category_index = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = category_index;
					category_index = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(category_index < categories_count)) {
					break;
				}
				{
					gint bucket_index = 0;
					bucket_index = bucket_start_index;
					{
						gboolean _tmp7_ = FALSE;
						_tmp7_ = TRUE;
						while (TRUE) {
							gint bar_index = 0;
							gdouble bucket_value = 0.0;
							FtMatrix* _tmp9_;
							FtBarChart* _tmp10_;
							if (!_tmp7_) {
								gint _tmp8_;
								_tmp8_ = bucket_index;
								bucket_index = _tmp8_ + 1;
							}
							_tmp7_ = FALSE;
							if (!(bucket_index < bucket_end_index)) {
								break;
							}
							bar_index = (bucket_index - bucket_start_index) / buckets_per_bar;
							_tmp9_ = self->priv->histogram_data;
							bucket_value = ft_matrix_get (_tmp9_, bucket_index, category_index, 0.0);
							_tmp10_ = self->priv->histogram;
							ft_bar_chart_add_value (_tmp10_, (guint) bar_index, (guint) category_index, bucket_value);
						}
					}
				}
			}
		}
	}
}

/**
         * Calculate time range for given entries
         */
static void
ft_stats_day_page_update_entries_time_range (FtStatsDayPage* self,
                                             GomResourceGroup* entries)
{
	g_return_if_fail (self != NULL);
	self->priv->entries_start_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->entries_end_time = FT_TIMESTAMP_UNDEFINED;
	if (entries == NULL) {
		return;
	}
	{
		guint index = 0U;
		index = 0U;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				guint _tmp2_;
				guint _tmp3_;
				FtStatsEntry* entry = NULL;
				GomResource* _tmp4_;
				FtStatsEntry* _tmp5_;
				gint64 entry_start_time = 0LL;
				FtStatsEntry* _tmp6_;
				gint64 _tmp7_;
				gint64 _tmp8_;
				gint64 entry_end_time = 0LL;
				FtStatsEntry* _tmp9_;
				gint64 _tmp10_;
				gint64 _tmp11_;
				FtStatsEntry* _tmp12_;
				gint64 _tmp13_;
				gint64 _tmp14_;
				FtStatsEntry* _tmp15_;
				gint64 _tmp16_;
				gint64 _tmp17_;
				gboolean _tmp18_ = FALSE;
				gboolean _tmp19_ = FALSE;
				if (!_tmp0_) {
					guint _tmp1_;
					_tmp1_ = index;
					index = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = gom_resource_group_get_count (entries);
				_tmp3_ = _tmp2_;
				if (!(index < _tmp3_)) {
					break;
				}
				_tmp4_ = gom_resource_group_get_index (entries, index);
				_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, FT_TYPE_STATS_ENTRY, FtStatsEntry));
				entry = _tmp5_;
				_tmp6_ = entry;
				_tmp7_ = ft_stats_entry_get_time (_tmp6_);
				_tmp8_ = _tmp7_;
				entry_start_time = _tmp8_;
				_tmp9_ = entry;
				_tmp10_ = ft_stats_entry_get_time (_tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = entry;
				_tmp13_ = ft_stats_entry_get_duration (_tmp12_);
				_tmp14_ = _tmp13_;
				entry_end_time = _tmp11_ + _tmp14_;
				_tmp15_ = entry;
				_tmp16_ = ft_stats_entry_get_duration (_tmp15_);
				_tmp17_ = _tmp16_;
				if (_tmp17_ < FT_STATS_DAY_PAGE_MIN_SIGNIFICANT_DURATION) {
					_g_object_unref0 (entry);
					continue;
				}
				if (entry_start_time < self->priv->entries_start_time) {
					_tmp18_ = TRUE;
				} else {
					_tmp18_ = ft_timestamp_is_undefined (self->priv->entries_start_time);
				}
				if (_tmp18_) {
					self->priv->entries_start_time = entry_start_time;
				}
				if (entry_end_time > self->priv->entries_end_time) {
					_tmp19_ = TRUE;
				} else {
					_tmp19_ = ft_timestamp_is_undefined (self->priv->entries_end_time);
				}
				if (_tmp19_) {
					self->priv->entries_end_time = entry_end_time;
				}
				_g_object_unref0 (entry);
			}
		}
	}
}

/**
         * Calculate display time range based on default work hours and entries
         */
static void
ft_stats_day_page_update_time_range (FtStatsDayPage* self)
{
	gint midnight_hour = 0;
	gint64 start_time = 0LL;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	gint64 _tmp3_;
	gint64 end_time = 0LL;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	gint64 _tmp7_;
	gboolean _tmp8_ = FALSE;
	gboolean _tmp9_ = FALSE;
	gint64 _tmp10_ = 0LL;
	gint bar_count = 0;
	g_return_if_fail (self != NULL);
	midnight_hour = (gint) (FT_STATS_MANAGER_MIDNIGHT_OFFSET / FT_INTERVAL_HOUR);
	_tmp0_ = self->priv->datetime;
	_tmp1_ = g_date_time_add_hours (_tmp0_, FT_STATS_DAY_PAGE_BASE_START_HOUR - midnight_hour);
	_tmp2_ = _tmp1_;
	_tmp3_ = ft_timestamp_from_datetime (_tmp2_);
	_g_date_time_unref0 (_tmp2_);
	start_time = _tmp3_;
	_tmp4_ = self->priv->datetime;
	_tmp5_ = g_date_time_add_hours (_tmp4_, FT_STATS_DAY_PAGE_BASE_END_HOUR - midnight_hour);
	_tmp6_ = _tmp5_;
	_tmp7_ = ft_timestamp_from_datetime (_tmp6_);
	_g_date_time_unref0 (_tmp6_);
	end_time = _tmp7_;
	if (ft_timestamp_is_defined (self->priv->entries_start_time)) {
		_tmp8_ = start_time > self->priv->entries_start_time;
	} else {
		_tmp8_ = FALSE;
	}
	if (_tmp8_) {
		start_time = self->priv->entries_start_time;
	}
	if (ft_timestamp_is_defined (self->priv->entries_end_time)) {
		_tmp9_ = end_time < self->priv->entries_end_time;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		end_time = self->priv->entries_end_time;
	}
	start_time = self->priv->timestamp + (self->priv->_interval * ((start_time - self->priv->timestamp) / self->priv->_interval));
	if (((end_time - start_time) % self->priv->_interval) != ((gint64) 0)) {
		_tmp10_ = start_time + (self->priv->_interval * (((end_time - start_time) / self->priv->_interval) + 1));
	} else {
		_tmp10_ = start_time + (self->priv->_interval * ((end_time - start_time) / self->priv->_interval));
	}
	end_time = _tmp10_;
	bar_count = (gint) ((end_time - start_time) / self->priv->_interval);
	if (bar_count < FT_STATS_DAY_PAGE_MIN_HISTOGRAM_BAR_COUNT) {
		start_time = MAX (self->priv->timestamp, start_time - (((FT_STATS_DAY_PAGE_MIN_HISTOGRAM_BAR_COUNT - bar_count) / 2) * self->priv->_interval));
		end_time = MAX (end_time, start_time + (FT_STATS_DAY_PAGE_MIN_HISTOGRAM_BAR_COUNT * self->priv->_interval));
	}
	self->priv->start_time = start_time;
	self->priv->end_time = end_time;
}

static void
ft_stats_day_page_reset (FtStatsDayPage* self)
{
	FtMatrix* _tmp0_;
	FtBarChart* _tmp1_;
	FtStatsCard* _tmp2_;
	FtStatsCard* _tmp3_;
	FtStatsCard* _tmp4_;
	FtStatsCard* _tmp5_;
	g_return_if_fail (self != NULL);
	ft_stats_day_page_ensure_histogram_data (self);
	_tmp0_ = self->priv->histogram_data;
	ft_matrix_fill (_tmp0_, 0.0);
	_tmp1_ = self->priv->histogram;
	ft_bar_chart_fill (_tmp1_, 0.0);
	_tmp2_ = self->priv->pomodoro_card;
	ft_stats_card_set_value (_tmp2_, 0.0);
	_tmp3_ = self->priv->breaks_card;
	ft_stats_card_set_value (_tmp3_, 0.0);
	_tmp4_ = self->priv->interruptions_card;
	ft_stats_card_set_value (_tmp4_, 0.0);
	_tmp5_ = self->priv->break_ratio_card;
	ft_stats_card_set_value (_tmp5_, ((double) NAN));
}

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

static void
ft_stats_day_page_populate (FtStatsDayPage* self,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	FtStatsDayPagePopulateData* _data_;
	FtStatsDayPage* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtStatsDayPagePopulateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_day_page_populate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_stats_day_page_populate_co (_data_);
}

static void
ft_stats_day_page_populate_finish (FtStatsDayPage* self,
                                   GAsyncResult* _res_)
{
	FtStatsDayPagePopulateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
ft_stats_day_page_populate_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	FtStatsDayPagePopulateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_day_page_populate_co (_data_);
}

static gboolean
ft_stats_day_page_populate_co (FtStatsDayPagePopulateData* _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_day_page_fetch_entries (_data_->self, ft_stats_day_page_populate_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = ft_stats_day_page_fetch_entries_finish (_data_->self, _data_->_res_);
	_data_->entries = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->entries;
	ft_stats_day_page_update_entries_time_range (_data_->self, _data_->_tmp1_);
	ft_stats_day_page_update_time_range (_data_->self);
	ft_stats_day_page_update_histogram_y_spacing (_data_->self);
	ft_stats_day_page_update_histogram_transform (_data_->self);
	ft_stats_day_page_update_histogram_buckets (_data_->self);
	ft_stats_day_page_reset (_data_->self);
	{
		_data_->index = 0U;
		{
			_data_->_tmp2_ = TRUE;
			while (TRUE) {
				if (!_data_->_tmp2_) {
					_data_->_tmp3_ = _data_->index;
					_data_->index = _data_->_tmp3_ + 1;
				}
				_data_->_tmp2_ = FALSE;
				_data_->_tmp4_ = _data_->entries;
				_data_->_tmp5_ = gom_resource_group_get_count (_data_->_tmp4_);
				_data_->_tmp6_ = _data_->_tmp5_;
				if (!(_data_->index < _data_->_tmp6_)) {
					break;
				}
				_data_->_tmp7_ = _data_->entries;
				_data_->_tmp8_ = gom_resource_group_get_index (_data_->_tmp7_, _data_->index);
				ft_stats_day_page_process_entry (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp8_, FT_TYPE_STATS_ENTRY, FtStatsEntry), 1);
			}
		}
	}
	_g_object_unref0 (_data_->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_day_page_invalidate_histogram_data (FtStatsDayPage* self)
{
	g_return_if_fail (self != NULL);
	_ft_matrix_free0 (self->priv->histogram_data);
	self->priv->histogram_data = NULL;
}

static void
ft_stats_day_page_on_interval_notify (FtStatsDayPage* self)
{
	GtkButton* _tmp0_;
	GtkButton* _tmp1_;
	g_return_if_fail (self != NULL);
	ft_stats_day_page_update_time_format (self);
	ft_stats_day_page_update_time_range (self);
	ft_stats_day_page_update_histogram_y_spacing (self);
	ft_stats_day_page_update_histogram_transform (self);
	ft_stats_day_page_update_histogram_buckets (self);
	ft_stats_day_page_aggregate_data (self);
	_tmp0_ = self->priv->zoom_in_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp0_, self->priv->_interval > FT_STATS_DAY_PAGE_MIN_INTERVAL);
	_tmp1_ = self->priv->zoom_out_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp1_, self->priv->_interval < FT_STATS_DAY_PAGE_MAX_INTERVAL);
}

static void
ft_stats_day_page_on_entry_saved (FtStatsDayPage* self,
                                  FtStatsEntry* entry)
{
	FtMatrix* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	_tmp0_ = self->priv->histogram_data;
	if (_tmp0_ != NULL) {
		ft_stats_day_page_process_entry (self, entry, 1);
	}
}

static void
ft_stats_day_page_on_entry_deleted (FtStatsDayPage* self,
                                    FtStatsEntry* entry)
{
	FtMatrix* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (entry != NULL);
	_tmp0_ = self->priv->histogram_data;
	if (_tmp0_ != NULL) {
		ft_stats_day_page_process_entry (self, entry, -1);
	}
}

static void
___lambda24_ (FtStatsDayPage* self,
              GObject* obj,
              GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	ft_stats_day_page_populate_finish (self, res);
}

static void
____lambda24__gasync_ready_callback (GObject* source_object,
                                     GAsyncResult* res,
                                     gpointer self)
{
	___lambda24_ ((FtStatsDayPage*) self, source_object, res);
	g_object_unref (self);
}

static void
ft_stats_day_page_on_timezone_history_changed (FtStatsDayPage* self)
{
	g_return_if_fail (self != NULL);
	if (gtk_widget_get_mapped ((GtkWidget*) self)) {
		ft_stats_day_page_populate (self, ____lambda24__gasync_ready_callback, g_object_ref (self));
	} else {
		ft_stats_day_page_invalidate_histogram_data (self);
	}
}

static void
ft_stats_day_page_on_zoom_in (FtStatsDayPage* self)
{
	g_return_if_fail (self != NULL);
	ft_stats_day_page_set_interval (self, CLAMP (self->priv->_interval / 2, FT_STATS_DAY_PAGE_MIN_INTERVAL, FT_STATS_DAY_PAGE_MAX_INTERVAL));
}

static void
_ft_stats_day_page_on_zoom_in_ft_chart_zoom_in (FtChart* _sender,
                                                gpointer self)
{
	ft_stats_day_page_on_zoom_in ((FtStatsDayPage*) self);
}

static void
ft_stats_day_page_on_zoom_out (FtStatsDayPage* self)
{
	g_return_if_fail (self != NULL);
	ft_stats_day_page_set_interval (self, CLAMP (self->priv->_interval * 2, FT_STATS_DAY_PAGE_MIN_INTERVAL, FT_STATS_DAY_PAGE_MAX_INTERVAL));
}

static void
_ft_stats_day_page_on_zoom_out_ft_chart_zoom_out (FtChart* _sender,
                                                  gpointer self)
{
	ft_stats_day_page_on_zoom_out ((FtStatsDayPage*) self);
}

static void
ft_stats_day_page_on_histogram_enter (FtStatsDayPage* self,
                                      gdouble x,
                                      gdouble y)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->toolbar_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, TRUE);
}

static void
_ft_stats_day_page_on_histogram_enter_gtk_event_controller_motion_enter (GtkEventControllerMotion* _sender,
                                                                         gdouble x,
                                                                         gdouble y,
                                                                         gpointer self)
{
	ft_stats_day_page_on_histogram_enter ((FtStatsDayPage*) self, x, y);
}

static void
ft_stats_day_page_on_histogram_leave (FtStatsDayPage* self)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->toolbar_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, FALSE);
}

static void
_ft_stats_day_page_on_histogram_leave_gtk_event_controller_motion_leave (GtkEventControllerMotion* _sender,
                                                                         gpointer self)
{
	ft_stats_day_page_on_histogram_leave ((FtStatsDayPage*) self);
}

static void
ft_stats_day_page_real_css_changed (GtkWidget* base,
                                    GtkCssStyleChange* change)
{
	FtStatsDayPage * self;
	self = (FtStatsDayPage*) base;
	g_return_if_fail (change != NULL);
	GTK_WIDGET_CLASS (ft_stats_day_page_parent_class)->css_changed ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin), change);
	ft_stats_day_page_update_category_colors (self);
}

static void
_ft_stats_day_page_on_entry_saved_ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                FtStatsEntry* entry,
                                                                gpointer self)
{
	ft_stats_day_page_on_entry_saved ((FtStatsDayPage*) self, entry);
}

static void
_ft_stats_day_page_on_entry_deleted_ft_stats_manager_entry_deleted (FtStatsManager* _sender,
                                                                    FtStatsEntry* entry,
                                                                    gpointer self)
{
	ft_stats_day_page_on_entry_deleted ((FtStatsDayPage*) self, entry);
}

static void
_ft_stats_day_page_on_timezone_history_changed_ft_timezone_history_changed (FtTimezoneHistory* _sender,
                                                                            gpointer self)
{
	ft_stats_day_page_on_timezone_history_changed ((FtStatsDayPage*) self);
}

static void
ft_stats_day_page_real_dispose (GObject* base)
{
	FtStatsDayPage * self;
	FtBarChart* _tmp0_;
	FtStatsManager* _tmp1_;
	guint _tmp2_;
	FtStatsManager* _tmp3_;
	guint _tmp4_;
	FtTimezoneHistory* _tmp5_;
	guint _tmp6_;
	self = (FtStatsDayPage*) base;
	_tmp0_ = self->priv->histogram;
	ft_chart_set_format_value_func ((FtChart*) _tmp0_, NULL, NULL, NULL);
	_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_day_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_day_page_on_entry_deleted_ft_stats_manager_entry_deleted, self);
	_tmp5_ = self->priv->timezone_history;
	g_signal_parse_name ("changed", FT_TYPE_TIMEZONE_HISTORY, &_tmp6_, NULL, FALSE);
	g_signal_handlers_disconnect_matched (_tmp5_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp6_, 0, NULL, (GCallback) _ft_stats_day_page_on_timezone_history_changed_ft_timezone_history_changed, self);
	_g_object_unref0 (self->priv->stats_manager);
	self->priv->stats_manager = NULL;
	_g_object_unref0 (self->priv->timezone_history);
	self->priv->timezone_history = NULL;
	_g_date_time_unref0 (self->priv->datetime);
	self->priv->datetime = NULL;
	_ft_matrix_free0 (self->priv->histogram_data);
	self->priv->histogram_data = NULL;
	G_OBJECT_CLASS (ft_stats_day_page_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
}

static void
ft_stats_day_page_real_get_date (FtStatsPage* base,
                                 GDate * result)
{
	FtStatsDayPage* self;
	GDate _tmp0_;
	self = (FtStatsDayPage*) 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_day_page_real_set_date (FtStatsPage* base,
                                 GDate * value)
{
	FtStatsDayPage* self;
	GDate old_value;
	self = (FtStatsDayPage*) base;
	ft_stats_day_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_day_page_properties[FT_STATS_DAY_PAGE_DATE_PROPERTY]);
	}
}

gint64
ft_stats_day_page_get_interval (FtStatsDayPage* self)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = self->priv->_interval;
	return result;
}

void
ft_stats_day_page_set_interval (FtStatsDayPage* self,
                                gint64 value)
{
	g_return_if_fail (self != NULL);
	value = CLAMP (value, FT_STATS_DAY_PAGE_MIN_INTERVAL, FT_STATS_DAY_PAGE_MAX_INTERVAL);
	if (self->priv->_interval == value) {
		return;
	}
	self->priv->_interval = value;
	ft_stats_day_page_on_interval_notify (self);
	g_object_notify ((GObject*) self, "interval");
}

static void
_ft_stats_day_page___lambda25_ (FtStatsDayPage* self,
                                GObject* obj,
                                GAsyncResult* res)
{
	g_return_if_fail (res != NULL);
	ft_stats_day_page_populate_finish (self, res);
}

static void
__ft_stats_day_page___lambda25__gasync_ready_callback (GObject* source_object,
                                                       GAsyncResult* res,
                                                       gpointer self)
{
	_ft_stats_day_page___lambda25_ ((FtStatsDayPage*) self, source_object, res);
	g_object_unref (self);
}

static GObject *
ft_stats_day_page_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtStatsDayPage * self;
	FtStatsManager* _tmp0_;
	FtTimezoneHistory* _tmp1_;
	FtStatsManager* _tmp2_;
	GDate _tmp3_ = {0};
	GDate _tmp4_;
	GDateTime* _tmp5_;
	GDateTime* _tmp6_;
	FtBarChart* _tmp7_;
	FtBarChart* _tmp8_;
	FtBarChart* _tmp9_;
	FtBarChart* _tmp10_;
	FtStatsManager* _tmp11_;
	FtStatsManager* _tmp12_;
	parent_class = G_OBJECT_CLASS (ft_stats_day_page_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_DAY_PAGE, FtStatsDayPage);
	_tmp0_ = ft_stats_manager_new ();
	_g_object_unref0 (self->priv->stats_manager);
	self->priv->stats_manager = _tmp0_;
	_tmp1_ = ft_timezone_history_new ();
	_g_object_unref0 (self->priv->timezone_history);
	self->priv->timezone_history = _tmp1_;
	_tmp2_ = self->priv->stats_manager;
	ft_stats_page_get_date ((FtStatsPage*) self, &_tmp3_);
	_tmp4_ = _tmp3_;
	_tmp5_ = ft_stats_manager_get_midnight (_tmp2_, &_tmp4_);
	_g_date_time_unref0 (self->priv->datetime);
	self->priv->datetime = _tmp5_;
	_tmp6_ = self->priv->datetime;
	self->priv->timestamp = ft_timestamp_from_datetime (_tmp6_);
	_tmp7_ = self->priv->histogram;
	ft_bar_chart_set_category_label (_tmp7_, (guint) FT_STATS_CATEGORY_POMODORO, _ ("Pomodoro"));
	_tmp8_ = self->priv->histogram;
	ft_bar_chart_set_category_unit (_tmp8_, (guint) FT_STATS_CATEGORY_POMODORO, FT_UNIT_INTERVAL);
	_tmp9_ = self->priv->histogram;
	ft_bar_chart_set_category_label (_tmp9_, (guint) FT_STATS_CATEGORY_BREAK, _ ("Breaks"));
	_tmp10_ = self->priv->histogram;
	ft_bar_chart_set_category_unit (_tmp10_, (guint) FT_STATS_CATEGORY_BREAK, FT_UNIT_INTERVAL);
	ft_stats_day_page_update_time_format (self);
	ft_stats_day_page_update_histogram_y_spacing (self);
	_tmp11_ = self->priv->stats_manager;
	g_signal_connect_object (_tmp11_, "entry-saved", (GCallback) _ft_stats_day_page_on_entry_saved_ft_stats_manager_entry_saved, self, 0);
	_tmp12_ = self->priv->stats_manager;
	g_signal_connect_object (_tmp12_, "entry-deleted", (GCallback) _ft_stats_day_page_on_entry_deleted_ft_stats_manager_entry_deleted, self, 0);
	ft_stats_day_page_populate (self, __ft_stats_day_page___lambda25__gasync_ready_callback, g_object_ref (self));
	return obj;
}

static void
ft_stats_day_page_class_init (FtStatsDayPageClass * klass,
                              gpointer klass_data)
{
	ft_stats_day_page_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsDayPage_private_offset);
	((GtkWidgetClass *) klass)->css_changed = (void (*) (GtkWidget*, GtkCssStyleChange*)) ft_stats_day_page_real_css_changed;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_stats_day_page_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_day_page_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_day_page_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_stats_day_page_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_day_page_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_DAY_PAGE_DATE_PROPERTY, ft_stats_day_page_properties[FT_STATS_DAY_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));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_DAY_PAGE_INTERVAL_PROPERTY, ft_stats_day_page_properties[FT_STATS_DAY_PAGE_INTERVAL_PROPERTY] = g_param_spec_int64 ("interval", "interval", "interval", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/stats-day-page.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "toolbar_revealer", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, toolbar_revealer));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "zoom_in_button", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, zoom_in_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "zoom_out_button", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, zoom_out_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "histogram", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, histogram));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pomodoro_card", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, pomodoro_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "breaks_card", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, breaks_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "interruptions_card", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, interruptions_card));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "break_ratio_card", FALSE, FtStatsDayPage_private_offset + G_STRUCT_OFFSET (FtStatsDayPagePrivate, break_ratio_card));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_zoom_in", G_CALLBACK(_ft_stats_day_page_on_zoom_in_ft_chart_zoom_in));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_zoom_out", G_CALLBACK(_ft_stats_day_page_on_zoom_out_ft_chart_zoom_out));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_histogram_enter", G_CALLBACK(_ft_stats_day_page_on_histogram_enter_gtk_event_controller_motion_enter));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_histogram_leave", G_CALLBACK(_ft_stats_day_page_on_histogram_leave_gtk_event_controller_motion_leave));
}

static void
ft_stats_day_page_ft_stats_page_interface_init (FtStatsPageIface * iface,
                                                gpointer iface_data)
{
	ft_stats_day_page_ft_stats_page_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_date = ft_stats_day_page_real_get_date;
	iface->set_date = ft_stats_day_page_real_set_date;
}

static void
ft_stats_day_page_instance_init (FtStatsDayPage * self,
                                 gpointer klass)
{
	self->priv = ft_stats_day_page_get_instance_private (self);
	self->priv->_interval = FT_STATS_DAY_PAGE_DEFAULT_INTERVAL;
	self->priv->entries_start_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->entries_end_time = FT_TIMESTAMP_UNDEFINED;
	g_type_ensure (FT_TYPE_BAR_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_day_page_finalize (GObject * obj)
{
	FtStatsDayPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_DAY_PAGE, FtStatsDayPage);
	_g_object_unref0 (self->priv->stats_manager);
	_g_object_unref0 (self->priv->timezone_history);
	_g_date_time_unref0 (self->priv->datetime);
	_g_free0 (self->priv->time_format);
	_ft_matrix_free0 (self->priv->histogram_data);
	G_OBJECT_CLASS (ft_stats_day_page_parent_class)->finalize (obj);
}

static GType
ft_stats_day_page_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsDayPageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_day_page_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsDayPage), 0, (GInstanceInitFunc) ft_stats_day_page_instance_init, NULL };
	static const GInterfaceInfo ft_stats_page_info = { (GInterfaceInitFunc) ft_stats_day_page_ft_stats_page_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType ft_stats_day_page_type_id;
	ft_stats_day_page_type_id = g_type_register_static (adw_bin_get_type (), "FtStatsDayPage", &g_define_type_info, 0);
	g_type_add_interface_static (ft_stats_day_page_type_id, FT_TYPE_STATS_PAGE, &ft_stats_page_info);
	FtStatsDayPage_private_offset = g_type_add_instance_private (ft_stats_day_page_type_id, sizeof (FtStatsDayPagePrivate));
	return ft_stats_day_page_type_id;
}

GType
ft_stats_day_page_get_type (void)
{
	static volatile gsize ft_stats_day_page_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_day_page_type_id__once)) {
		GType ft_stats_day_page_type_id;
		ft_stats_day_page_type_id = ft_stats_day_page_get_type_once ();
		g_once_init_leave (&ft_stats_day_page_type_id__once, ft_stats_day_page_type_id);
	}
	return ft_stats_day_page_type_id__once;
}

static void
_vala_ft_stats_day_page_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	FtStatsDayPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_DAY_PAGE, FtStatsDayPage);
	switch (property_id) {
		case FT_STATS_DAY_PAGE_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_page_get_date ((FtStatsPage*) self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_STATS_DAY_PAGE_INTERVAL_PROPERTY:
		g_value_set_int64 (value, ft_stats_day_page_get_interval (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_stats_day_page_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	FtStatsDayPage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_DAY_PAGE, FtStatsDayPage);
	switch (property_id) {
		case FT_STATS_DAY_PAGE_DATE_PROPERTY:
		ft_stats_page_set_date ((FtStatsPage*) self, g_value_get_boxed (value));
		break;
		case FT_STATS_DAY_PAGE_INTERVAL_PROPERTY:
		ft_stats_day_page_set_interval (self, g_value_get_int64 (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);
}

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;
}

