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

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

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

#define FT_STATS_VIEW_PAGES_HISTORY_LIMIT ((guint) 2)
#define FT_STATS_VIEW_TOAST_DISMISS_TIMEOUT ((guint) 2)
#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

#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
enum  {
	FT_STATS_VIEW_MODEL_0_PROPERTY,
	FT_STATS_VIEW_MODEL_TIMEFRAME_PROPERTY,
	FT_STATS_VIEW_MODEL_DATE_PROPERTY,
	FT_STATS_VIEW_MODEL_MIN_DATE_PROPERTY,
	FT_STATS_VIEW_MODEL_MAX_DATE_PROPERTY,
	FT_STATS_VIEW_MODEL_NUM_PROPERTIES
};
static GParamSpec* ft_stats_view_model_properties[FT_STATS_VIEW_MODEL_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _FtStatsViewModelFetchMinDateData FtStatsViewModelFetchMinDateData;
typedef struct _FtStatsViewModelFetchClosestDateData FtStatsViewModelFetchClosestDateData;
typedef struct _FtStatsViewModelNavigateData FtStatsViewModelNavigateData;
enum  {
	FT_STATS_VIEW_MODEL_NAVIGATED_SIGNAL,
	FT_STATS_VIEW_MODEL_NUM_SIGNALS
};
static guint ft_stats_view_model_signals[FT_STATS_VIEW_MODEL_NUM_SIGNALS] = {0};
enum  {
	FT_STATS_VIEW_0_PROPERTY,
	FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY,
	FT_STATS_VIEW_NUM_PROPERTIES
};
static GParamSpec* ft_stats_view_properties[FT_STATS_VIEW_NUM_PROPERTIES];
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))

struct _FtStatsViewModelPrivate {
	FtTimeframe _timeframe;
	GDate _date;
	GDate _min_date;
	GDate _max_date;
	GDate user_selected_date;
	GomRepository* repository;
	FtStatsManager* stats_manager;
	FtSleepMonitor* sleep_monitor;
	GCancellable* navigation_cancellable;
	gulong woke_up_id;
	gulong entry_saved_id;
};

struct _FtStatsViewModelFetchMinDateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsViewModel* self;
	GDate result;
	GDate min_date;
	GomRepository* _tmp0_;
	GomSorting* sorting;
	GObject* _tmp1_;
	GObject* _tmp2_;
	GomSorting* _tmp3_;
	GomResourceGroup* results;
	GomRepository* _tmp4_;
	GomSorting* _tmp5_;
	GomResourceGroup* _tmp6_;
	GomResourceGroup* _tmp7_;
	guint _tmp8_;
	guint _tmp9_;
	GomResourceGroup* _tmp10_;
	FtAggregatedStatsEntry* entry;
	GomResourceGroup* _tmp11_;
	GomResource* _tmp12_;
	FtAggregatedStatsEntry* _tmp13_;
	gboolean _tmp14_;
	FtAggregatedStatsEntry* _tmp15_;
	FtAggregatedStatsEntry* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	FtAggregatedStatsEntry* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	GDate _tmp22_;
	GError* _error_;
	GError* _tmp23_;
	const gchar* _tmp24_;
	GError* _inner_error0_;
};

struct _FtStatsViewModelFetchClosestDateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsViewModel* self;
	GDate date;
	FtNavigationDirection direction;
	GDate result;
	GomRepository* _tmp0_;
	GDate _tmp1_;
	GValue date_value;
	GValue _tmp2_;
	GDate _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	GValue category_value;
	GValue _tmp6_;
	GValue duration_value;
	GValue _tmp7_;
	GomFilter* date_filter;
	GomSorting* sorting;
	GObject* _tmp8_;
	GObject* _tmp9_;
	GValue _tmp10_;
	GomFilter* _tmp11_;
	GomSorting* _tmp12_;
	GValue _tmp13_;
	GomFilter* _tmp14_;
	GomSorting* _tmp15_;
	GomFilter* category_filter;
	GValue _tmp16_;
	GomFilter* _tmp17_;
	GomFilter* duration_filter;
	GValue _tmp18_;
	GomFilter* _tmp19_;
	GomFilter* filter;
	GomFilter* _tmp20_;
	GomFilter* _tmp21_;
	GomFilter* _tmp22_;
	GomFilter* _tmp23_;
	GomFilter* _tmp24_;
	GomFilter* _tmp25_;
	GomFilter* _tmp26_;
	GomResourceGroup* results;
	GomRepository* _tmp27_;
	GomFilter* _tmp28_;
	GomSorting* _tmp29_;
	GomResourceGroup* _tmp30_;
	GomResourceGroup* _tmp31_;
	guint _tmp32_;
	guint _tmp33_;
	GDate _tmp34_;
	GDate _tmp35_;
	GDate _tmp36_;
	GomResourceGroup* _tmp37_;
	FtAggregatedStatsEntry* entry;
	GomResourceGroup* _tmp38_;
	GomResource* _tmp39_;
	FtAggregatedStatsEntry* _tmp40_;
	GDate _tmp41_;
	FtAggregatedStatsEntry* _tmp42_;
	FtAggregatedStatsEntry* _tmp43_;
	const gchar* _tmp44_;
	const gchar* _tmp45_;
	GDate _tmp46_;
	GDate _tmp47_;
	GError* _error_;
	GError* _tmp48_;
	const gchar* _tmp49_;
	GDate _tmp50_;
	GError* _inner_error0_;
};

struct _FtStatsViewModelNavigateData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	FtStatsViewModel* self;
	FtNavigationDirection direction;
	GCancellable* cancellable;
	GDate* current_date;
	GDate* _tmp0_;
	GDate* date;
	GDate* _tmp1_;
	FtTimeframe timeframe;
	GDate* _tmp2_;
	GDate* _tmp3_;
	GDate* _tmp4_;
	GDate* _tmp5_;
	GDate closest_date;
	GDate* _tmp6_;
	GDate _tmp7_;
	GDate _tmp8_;
	guint skipped;
	gboolean _tmp9_;
	GDate _tmp10_;
	GDate _tmp11_;
	GDate* _tmp12_;
	GDate* _tmp13_;
	GDate* _tmp14_;
	GDate _tmp15_;
	GDate* _tmp16_;
	GDate* _tmp17_;
	GDate _tmp18_;
	gint skipped_int;
	GDate* _tmp19_;
	GDate* _tmp20_;
	GDate* _tmp21_;
	GDate* _tmp22_;
	GDate* _tmp23_;
	GDate* _tmp24_;
	GDate* _tmp25_;
	GDate* _tmp26_;
	GDate* _tmp27_;
	GDate* _tmp28_;
	GDate _tmp29_;
	GDate* _tmp30_;
	GDate _tmp31_;
	GDate* _tmp32_;
	GDate _tmp33_;
};

struct _FtStatsViewPrivate {
	gint64 _daily_interval;
	GtkStack* stack;
	GtkLabel* title_label;
	GtkLabel* subtitle_label;
	FtStatsDatePopover* date_popover;
	GtkButton* up_button;
	GtkStack* pages;
	FtStatsViewModel* model;
	GSimpleAction* previous_action;
	GSimpleAction* next_action;
	GSimpleAction* today_action;
	GSimpleAction* up_action;
	GSimpleAction* timeframe_action;
	GQueue* pages_history;
	GCancellable* navigation_cancellable;
	AdwToast* last_toast;
	gint64 last_user_active_time;
	guint update_page_idle_id;
	guint timeout_id;
};

static gint FtStatsViewModel_private_offset;
static gpointer ft_stats_view_model_parent_class = NULL;
static gint FtStatsView_private_offset;
static gpointer ft_stats_view_parent_class = NULL;

static void ft_stats_view_model_validate_user_selected_date (FtStatsViewModel* self);
static void ft_stats_view_model_set_max_date (FtStatsViewModel* self,
                                       GDate * value);
static void ft_stats_view_model_fetch_min_date_sync (FtStatsViewModel* self,
                                              GDate* result);
static void ft_stats_view_model_set_min_date (FtStatsViewModel* self,
                                       GDate * value);
static void ft_stats_view_model_fetch_min_date_data_free (gpointer _data);
static void ft_stats_view_model_fetch_min_date (FtStatsViewModel* self,
                                         GAsyncReadyCallback _callback_,
                                         gpointer _user_data_);
static void ft_stats_view_model_fetch_min_date_finish (FtStatsViewModel* self,
                                                GAsyncResult* _res_,
                                                GDate* result);
static gboolean ft_stats_view_model_fetch_min_date_co (FtStatsViewModelFetchMinDateData* _data_);
static void ft_stats_view_model_fetch_min_date_ready (GObject* source_object,
                                               GAsyncResult* _res_,
                                               gpointer _user_data_);
static void ft_stats_view_model_fetch_closest_date_data_free (gpointer _data);
static void ft_stats_view_model_fetch_closest_date (FtStatsViewModel* self,
                                             GDate* date,
                                             FtNavigationDirection direction,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_);
static void ft_stats_view_model_fetch_closest_date_finish (FtStatsViewModel* self,
                                                    GAsyncResult* _res_,
                                                    GDate* result);
static gboolean ft_stats_view_model_fetch_closest_date_co (FtStatsViewModelFetchClosestDateData* _data_);
static void ft_stats_view_model_fetch_closest_date_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void ft_stats_view_model_navigate_data_free (gpointer _data);
static gboolean ft_stats_view_model_navigate_co (FtStatsViewModelNavigateData* _data_);
static void ft_stats_view_model_navigate_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_);
static GDate* _g_date_dup (GDate* self);
static void ft_stats_view_model_real_dispose (GObject* base);
static void g_cclosure_user_marshal_VOID__ENUM_BOXED_UINT (GClosure * closure,
                                                    GValue * return_value,
                                                    guint n_param_values,
                                                    const GValue * param_values,
                                                    gpointer invocation_hint,
                                                    gpointer marshal_data);
static GObject * ft_stats_view_model_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties);
static void _ft_stats_view_model___lambda27_ (FtStatsViewModel* self,
                                       GObject* obj,
                                       GAsyncResult* res);
static void __ft_stats_view_model___lambda27__gasync_ready_callback (GObject* source_object,
                                                              GAsyncResult* res,
                                                              gpointer self);
static void _ft_stats_view_model___lambda28_ (FtStatsViewModel* self,
                                       FtStatsEntry* entry);
static void __ft_stats_view_model___lambda28__ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                     FtStatsEntry* entry,
                                                                     gpointer self);
static void _ft_stats_view_model___lambda29_ (FtStatsViewModel* self);
static void __ft_stats_view_model___lambda29__ft_sleep_monitor_woke_up (FtSleepMonitor* _sender,
                                                                 gpointer self);
static void ft_stats_view_model_finalize (GObject * obj);
static GType ft_stats_view_model_get_type_once (void);
static void _vala_ft_stats_view_model_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static void _vala_ft_stats_view_model_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec);
static gchar* ft_stats_view_build_page_name (FtStatsView* self,
                                      FtTimeframe timeframe,
                                      GDate* date);
static FtStatsPage* ft_stats_view_create_page (FtStatsView* self,
                                        FtTimeframe timeframe,
                                        GDate* date);
static FtStatsPage* ft_stats_view_get_page (FtStatsView* self,
                                     const gchar* name);
static FtStatsPage* ft_stats_view_get_or_create_page (FtStatsView* self,
                                               FtTimeframe timeframe,
                                               GDate* date);
static void ft_stats_view_update_page (FtStatsView* self,
                                GtkStackTransitionType transition);
static void ft_stats_view_update_title (FtStatsView* self);
static void ft_stats_view_update_actions (FtStatsView* self);
static void ft_stats_view_mark_user_active (FtStatsView* self);
static void ft_stats_view_queue_update_page (FtStatsView* self);
static gboolean __lambda31_ (FtStatsView* self);
static gboolean ___lambda31__gtk_tick_callback (GtkWidget* widget,
                                         GdkFrameClock* frame_clock,
                                         gpointer self);
static void ft_stats_view_clear_pages (FtStatsView* self);
static void ft_stats_view_notify_skipped_pages (FtStatsView* self,
                                         guint count);
static void __lambda32_ (FtStatsView* self);
static void ___lambda32__adw_toast_dismissed (AdwToast* _sender,
                                       gpointer self);
static void ft_stats_view_navigate_to_today (FtStatsView* self);
static void ft_stats_view_navigate_up (FtStatsView* self);
static void ft_stats_view_activate_previous (FtStatsView* self,
                                      GSimpleAction* action,
                                      GVariant* parameter);
static void ft_stats_view_activate_next (FtStatsView* self,
                                  GSimpleAction* action,
                                  GVariant* parameter);
static void ft_stats_view_activate_today (FtStatsView* self,
                                   GSimpleAction* action,
                                   GVariant* parameter);
static void ft_stats_view_activate_up (FtStatsView* self);
static void ft_stats_view_activate_timeframe (FtStatsView* self,
                                       GSimpleAction* action,
                                       GVariant* parameter);
static void ft_stats_view_activate_set_timeframe (FtStatsView* self,
                                           GSimpleAction* action,
                                           GVariant* parameter);
static void ft_stats_view_activate_select_day_action (FtStatsView* self,
                                               GSimpleAction* action,
                                               GVariant* parameter);
static void ft_stats_view_initialize_action_group (FtStatsView* self);
static void _ft_stats_view_activate_previous_g_simple_action_activate (GSimpleAction* _sender,
                                                                GVariant* parameter,
                                                                gpointer self);
static void _ft_stats_view_activate_next_g_simple_action_activate (GSimpleAction* _sender,
                                                            GVariant* parameter,
                                                            gpointer self);
static void _ft_stats_view_activate_today_g_simple_action_activate (GSimpleAction* _sender,
                                                             GVariant* parameter,
                                                             gpointer self);
static void _ft_stats_view_activate_up_g_simple_action_activate (GSimpleAction* _sender,
                                                          GVariant* parameter,
                                                          gpointer self);
static void _ft_stats_view_activate_timeframe_g_simple_action_activate (GSimpleAction* _sender,
                                                                 GVariant* parameter,
                                                                 gpointer self);
static void _ft_stats_view_activate_set_timeframe_g_simple_action_activate (GSimpleAction* _sender,
                                                                     GVariant* parameter,
                                                                     gpointer self);
static void _ft_stats_view_activate_select_day_action_g_simple_action_activate (GSimpleAction* _sender,
                                                                         GVariant* parameter,
                                                                         gpointer self);
static gboolean ft_stats_view_is_user_idle (FtStatsView* self);
VALA_EXTERN gchar* ft_capitalize_words (const gchar* text);
static void ft_stats_view_schedule_navigate_to_today (FtStatsView* self);
static gboolean __lambda55_ (FtStatsView* self);
static gboolean ___lambda55__gsource_func (gpointer self);
static void ft_stats_view_update_placeholder (FtStatsView* self);
static void ft_stats_view_on_timeframe_selected (FtStatsView* self,
                                          FtStatsDatePopover* date_popover,
                                          FtTimeframe timeframe);
static void _ft_stats_view_on_timeframe_selected_ft_stats_date_popover_timeframe_selected (FtStatsDatePopover* _sender,
                                                                                    FtTimeframe timeframe,
                                                                                    gpointer self);
static void ft_stats_view_on_date_selected (FtStatsView* self,
                                     FtStatsDatePopover* date_popover,
                                     GDate* date);
static void _ft_stats_view_on_date_selected_ft_stats_date_popover_date_selected (FtStatsDatePopover* _sender,
                                                                          GDate* date,
                                                                          gpointer self);
static void ft_stats_view_real_map (GtkWidget* base);
static void ft_stats_view_real_unmap (GtkWidget* base);
static void ft_stats_view_real_dispose (GObject* base);
static GObject * ft_stats_view_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties);
static void _ft_stats_view___lambda56_ (FtStatsView* self,
                                 GParamSpec* pspec);
static void __ft_stats_view___lambda56__g_object_notify (GObject* _sender,
                                                  GParamSpec* pspec,
                                                  gpointer self);
static void _ft_stats_view___lambda57_ (FtStatsView* self,
                                 GParamSpec* pspec);
static void __ft_stats_view___lambda57__g_object_notify (GObject* _sender,
                                                  GParamSpec* pspec,
                                                  gpointer self);
static void _ft_stats_view___lambda58_ (FtStatsView* self,
                                 GParamSpec* pspec);
static void __ft_stats_view___lambda58__g_object_notify (GObject* _sender,
                                                  GParamSpec* pspec,
                                                  gpointer self);
static void _ft_stats_view___lambda59_ (FtStatsView* self,
                                 GParamSpec* pspec);
static void __ft_stats_view___lambda59__g_object_notify (GObject* _sender,
                                                  GParamSpec* pspec,
                                                  gpointer self);
static void _ft_stats_view___lambda60_ (FtStatsView* self,
                                 FtNavigationDirection direction,
                                 GDate* date,
                                 guint skipped);
static void __ft_stats_view___lambda60__ft_stats_view_model_navigated (FtStatsViewModel* _sender,
                                                                FtNavigationDirection direction,
                                                                GDate* date,
                                                                guint skipped,
                                                                gpointer self);
static void ft_stats_view_finalize (GObject * obj);
static GType ft_stats_view_get_type_once (void);
static void _vala_ft_stats_view_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_ft_stats_view_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

FtTimeframe
ft_timeframe_from_string (const gchar* timeframe)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	FtTimeframe result;
	_tmp0_ = timeframe;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("day")))) {
		switch (0) {
			default:
			{
				result = FT_TIMEFRAME_DAY;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("week")))) {
		switch (0) {
			default:
			{
				result = FT_TIMEFRAME_WEEK;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("month")))) {
		switch (0) {
			default:
			{
				result = FT_TIMEFRAME_MONTH;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				result = FT_TIMEFRAME_DAY;
				return result;
			}
		}
	}
}

gchar*
ft_timeframe_to_string (FtTimeframe self)
{
	gchar* result;
	switch (self) {
		case FT_TIMEFRAME_DAY:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("day");
			result = _tmp0_;
			return result;
		}
		case FT_TIMEFRAME_WEEK:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("week");
			result = _tmp1_;
			return result;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("month");
			result = _tmp2_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

gchar*
ft_timeframe_get_label (FtTimeframe self)
{
	gchar* result;
	switch (self) {
		case FT_TIMEFRAME_DAY:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("Day"));
			result = _tmp0_;
			return result;
		}
		case FT_TIMEFRAME_WEEK:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("Week"));
			result = _tmp1_;
			return result;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("Month"));
			result = _tmp2_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

void
ft_timeframe_normalize_date (FtTimeframe self,
                             GDate* date,
                             GDate* result)
{
	GDate* normalized_date = NULL;
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDate* _tmp6_;
	GDate _tmp7_;
	g_return_if_fail (date != NULL);
	_tmp0_ = g_date_copy (date);
	normalized_date = _tmp0_;
	_tmp1_ = normalized_date;
	if (!g_date_valid (_tmp1_)) {
		GDate* _tmp2_;
		GDate _tmp3_;
		_tmp2_ = normalized_date;
		_tmp3_ = *_tmp2_;
		_g_free0 (_tmp2_);
		*result = _tmp3_;
		return;
	}
	switch (self) {
		case FT_TIMEFRAME_DAY:
		{
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			GDateWeekday first_day_of_week = 0;
			gint offset = 0;
			GDate* _tmp4_;
			first_day_of_week = ft_locale_get_first_day_of_week ();
			offset = ((gint) g_date_get_weekday (date)) - ((gint) first_day_of_week);
			if (offset < 0) {
				offset += 7;
			}
			_tmp4_ = normalized_date;
			g_date_subtract_days (_tmp4_, (guint) offset);
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			GDate* _tmp5_;
			_tmp5_ = normalized_date;
			g_date_set_day (_tmp5_, (GDateDay) 1);
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp6_ = normalized_date;
	_tmp7_ = *_tmp6_;
	_g_free0 (_tmp6_);
	*result = _tmp7_;
	return;
}

static GType
ft_timeframe_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_TIMEFRAME_DAY, "FT_TIMEFRAME_DAY", "day"}, {FT_TIMEFRAME_WEEK, "FT_TIMEFRAME_WEEK", "week"}, {FT_TIMEFRAME_MONTH, "FT_TIMEFRAME_MONTH", "month"}, {0, NULL, NULL}};
	GType ft_timeframe_type_id;
	ft_timeframe_type_id = g_enum_register_static ("FtTimeframe", values);
	return ft_timeframe_type_id;
}

GType
ft_timeframe_get_type (void)
{
	static volatile gsize ft_timeframe_type_id__once = 0;
	if (g_once_init_enter (&ft_timeframe_type_id__once)) {
		GType ft_timeframe_type_id;
		ft_timeframe_type_id = ft_timeframe_get_type_once ();
		g_once_init_leave (&ft_timeframe_type_id__once, ft_timeframe_type_id);
	}
	return ft_timeframe_type_id__once;
}

static GType
ft_navigation_direction_get_type_once (void)
{
	static const GEnumValue values[] = {{FT_NAVIGATION_DIRECTION_FORWARD, "FT_NAVIGATION_DIRECTION_FORWARD", "forward"}, {FT_NAVIGATION_DIRECTION_BACKWARD, "FT_NAVIGATION_DIRECTION_BACKWARD", "backward"}, {0, NULL, NULL}};
	GType ft_navigation_direction_type_id;
	ft_navigation_direction_type_id = g_enum_register_static ("FtNavigationDirection", values);
	return ft_navigation_direction_type_id;
}

GType
ft_navigation_direction_get_type (void)
{
	static volatile gsize ft_navigation_direction_type_id__once = 0;
	if (g_once_init_enter (&ft_navigation_direction_type_id__once)) {
		GType ft_navigation_direction_type_id;
		ft_navigation_direction_type_id = ft_navigation_direction_get_type_once ();
		g_once_init_leave (&ft_navigation_direction_type_id__once, ft_navigation_direction_type_id);
	}
	return ft_navigation_direction_type_id__once;
}

static inline gpointer
ft_stats_view_model_get_instance_private (FtStatsViewModel* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsViewModel_private_offset);
}

static void
ft_stats_view_model_validate_user_selected_date (FtStatsViewModel* self)
{
	gboolean is_valid = FALSE;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (&self->priv->user_selected_date)) {
		return;
	}
	is_valid = TRUE;
	switch (self->priv->_timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			GDate _tmp0_;
			_tmp0_ = self->priv->_date;
			is_valid = g_date_compare (&self->priv->user_selected_date, &_tmp0_) == 0;
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			GDate* week_start = NULL;
			GDate* _tmp1_;
			GDate* week_end = NULL;
			GDate* _tmp2_;
			GDate* _tmp3_;
			gboolean _tmp4_ = FALSE;
			GDate* _tmp5_;
			GDate _tmp6_;
			_tmp1_ = g_date_copy (&self->priv->_date);
			week_start = _tmp1_;
			_tmp2_ = g_date_copy (&self->priv->_date);
			week_end = _tmp2_;
			_tmp3_ = week_end;
			g_date_add_days (_tmp3_, 6U);
			_tmp5_ = week_start;
			_tmp6_ = *_tmp5_;
			if (g_date_compare (&self->priv->user_selected_date, &_tmp6_) >= 0) {
				GDate* _tmp7_;
				GDate _tmp8_;
				_tmp7_ = week_end;
				_tmp8_ = *_tmp7_;
				_tmp4_ = g_date_compare (&self->priv->user_selected_date, &_tmp8_) <= 0;
			} else {
				_tmp4_ = FALSE;
			}
			is_valid = _tmp4_;
			_g_free0 (week_end);
			_g_free0 (week_start);
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gboolean _tmp9_ = FALSE;
			if (g_date_get_month (&self->priv->user_selected_date) == g_date_get_month (&self->priv->_date)) {
				_tmp9_ = g_date_get_year (&self->priv->user_selected_date) == g_date_get_year (&self->priv->_date);
			} else {
				_tmp9_ = FALSE;
			}
			is_valid = _tmp9_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	if (!is_valid) {
		memset (&self->priv->user_selected_date, 0, sizeof (GDate));
	}
}

void
ft_stats_view_model_select_date (FtStatsViewModel* self,
                                 GDate* date)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDate _tmp2_;
	GDate _tmp3_ = {0};
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = g_date_copy (date);
	_tmp1_ = _tmp0_;
	self->priv->user_selected_date = *_tmp1_;
	_g_free0 (_tmp1_);
	_tmp2_ = *date;
	ft_timeframe_normalize_date (self->priv->_timeframe, &_tmp2_, &_tmp3_);
	ft_stats_view_model_set_date (self, &_tmp3_);
}

void
ft_stats_view_model_select_timeframe (FtStatsViewModel* self,
                                      FtTimeframe timeframe)
{
	g_return_if_fail (self != NULL);
	ft_stats_view_model_set_timeframe (self, timeframe);
}

void
ft_stats_view_model_select (FtStatsViewModel* self,
                            GDate* date,
                            FtTimeframe timeframe)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDate _tmp2_;
	GDate _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	gboolean date_changed = FALSE;
	gboolean timeframe_changed = FALSE;
	GDate _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = g_date_copy (date);
	_tmp1_ = _tmp0_;
	self->priv->user_selected_date = *_tmp1_;
	_g_free0 (_tmp1_);
	_tmp2_ = *date;
	ft_timeframe_normalize_date (timeframe, &_tmp2_, &_tmp3_);
	*date = _tmp3_;
	if (g_date_valid (&self->priv->_date)) {
		GDate _tmp5_;
		_tmp5_ = *date;
		_tmp4_ = g_date_compare (&self->priv->_date, &_tmp5_) != 0;
	} else {
		_tmp4_ = g_date_valid (date);
	}
	date_changed = _tmp4_;
	timeframe_changed = self->priv->_timeframe != timeframe;
	self->priv->_timeframe = timeframe;
	_tmp6_ = *date;
	self->priv->_date = _tmp6_;
	if (timeframe_changed) {
		g_object_notify ((GObject*) self, "timeframe");
	}
	if (date_changed) {
		g_object_notify ((GObject*) self, "date");
	}
}

void
ft_stats_view_model_get_selection_date (FtStatsViewModel* self,
                                        GDate* result)
{
	GDate* _tmp0_ = NULL;
	GDate* _tmp3_;
	GDate* _tmp4_;
	GDate _tmp5_;
	g_return_if_fail (self != NULL);
	if (g_date_valid (&self->priv->user_selected_date)) {
		GDate* _tmp1_;
		_tmp1_ = g_date_copy (&self->priv->user_selected_date);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp1_;
	} else {
		GDate* _tmp2_;
		_tmp2_ = g_date_copy (&self->priv->_date);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp2_;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	_tmp4_ = _tmp3_;
	_tmp5_ = *_tmp4_;
	_g_free0 (_tmp4_);
	*result = _tmp5_;
	_g_free0 (_tmp0_);
	return;
}

void
ft_stats_view_model_update_date_range (FtStatsViewModel* self)
{
	FtStatsManager* _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_ = {0};
	GDate _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->stats_manager;
	ft_stats_manager_get_today (_tmp0_, &_tmp1_);
	ft_stats_view_model_set_max_date (self, &_tmp1_);
	ft_stats_view_model_get_min_date (self, &_tmp2_);
	_tmp3_ = _tmp2_;
	if (!g_date_valid (&_tmp3_)) {
		GDate _tmp4_ = {0};
		ft_stats_view_model_fetch_min_date_sync (self, &_tmp4_);
		ft_stats_view_model_set_min_date (self, &_tmp4_);
	}
}

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

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

static void
ft_stats_view_model_fetch_min_date (FtStatsViewModel* self,
                                    GAsyncReadyCallback _callback_,
                                    gpointer _user_data_)
{
	FtStatsViewModelFetchMinDateData* _data_;
	FtStatsViewModel* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (FtStatsViewModelFetchMinDateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_view_model_fetch_min_date_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	ft_stats_view_model_fetch_min_date_co (_data_);
}

static void
ft_stats_view_model_fetch_min_date_finish (FtStatsViewModel* self,
                                           GAsyncResult* _res_,
                                           GDate* result)
{
	FtStatsViewModelFetchMinDateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	*result = _data_->result;
}

static void
ft_stats_view_model_fetch_min_date_ready (GObject* source_object,
                                          GAsyncResult* _res_,
                                          gpointer _user_data_)
{
	FtStatsViewModelFetchMinDateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_view_model_fetch_min_date_co (_data_);
}

static gboolean
ft_stats_view_model_fetch_min_date_co (FtStatsViewModelFetchMinDateData* _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:
	memset (&_data_->min_date, 0, sizeof (GDate));
	_data_->_tmp0_ = _data_->self->priv->repository;
	if (_data_->_tmp0_ == NULL) {
		_data_->result = _data_->min_date;
		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;
	}
	_data_->_tmp1_ = g_object_new (gom_sorting_get_type (), NULL);
	_data_->_tmp2_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp1_) ? g_object_ref_sink (_data_->_tmp1_) : _data_->_tmp1_;
	_data_->sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, gom_sorting_get_type (), GomSorting);
	_data_->_tmp3_ = _data_->sorting;
	gom_sorting_add (_data_->_tmp3_, FT_TYPE_AGGREGATED_STATS_ENTRY, "date", GOM_SORTING_ASCENDING);
	{
		_data_->_tmp4_ = _data_->self->priv->repository;
		_data_->_tmp5_ = _data_->sorting;
		_data_->_state_ = 1;
		gom_repository_find_sorted_async (_data_->_tmp4_, FT_TYPE_AGGREGATED_STATS_ENTRY, NULL, _data_->_tmp5_, ft_stats_view_model_fetch_min_date_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp6_ = gom_repository_find_finish (_data_->_tmp4_, _data_->_res_, &_data_->_inner_error0_);
		_data_->results = _data_->_tmp6_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp7_ = _data_->results;
		_data_->_tmp8_ = gom_resource_group_get_count (_data_->_tmp7_);
		_data_->_tmp9_ = _data_->_tmp8_;
		if (_data_->_tmp9_ > ((guint) 0)) {
			_data_->_tmp10_ = _data_->results;
			_data_->_state_ = 2;
			gom_resource_group_fetch_async (_data_->_tmp10_, 0U, 1U, ft_stats_view_model_fetch_min_date_ready, _data_);
			return FALSE;
			_state_2:
			gom_resource_group_fetch_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->results);
				goto __catch0_g_error;
			}
			_data_->_tmp11_ = _data_->results;
			_data_->_tmp12_ = gom_resource_group_get_index (_data_->_tmp11_, (guint) 0);
			_data_->_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp12_, FT_TYPE_AGGREGATED_STATS_ENTRY, FtAggregatedStatsEntry));
			_data_->entry = _data_->_tmp13_;
			_data_->_tmp15_ = _data_->entry;
			if (_data_->_tmp15_ != NULL) {
				_data_->_tmp16_ = _data_->entry;
				_data_->_tmp17_ = ft_aggregated_stats_entry_get_date (_data_->_tmp16_);
				_data_->_tmp18_ = _data_->_tmp17_;
				_data_->_tmp14_ = _data_->_tmp18_ != NULL;
			} else {
				_data_->_tmp14_ = FALSE;
			}
			if (_data_->_tmp14_) {
				_data_->_tmp19_ = _data_->entry;
				_data_->_tmp20_ = ft_aggregated_stats_entry_get_date (_data_->_tmp19_);
				_data_->_tmp21_ = _data_->_tmp20_;
				memset (&_data_->_tmp22_, 0, sizeof (GDate));
				ft_database_parse_date (_data_->_tmp21_, &_data_->_tmp22_);
				_data_->result = _data_->_tmp22_;
				_g_object_unref0 (_data_->entry);
				_g_object_unref0 (_data_->results);
				_g_object_unref0 (_data_->sorting);
				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;
			}
			_g_object_unref0 (_data_->entry);
		}
		_g_object_unref0 (_data_->results);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_error_ = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp23_ = _data_->_error_;
		_data_->_tmp24_ = _data_->_tmp23_->message;
		g_critical ("stats-view.vala:340: Error while fetching minimal stats date: %s", _data_->_tmp24_);
		_g_error_free0 (_data_->_error_);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_object_unref0 (_data_->sorting);
		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;
	}
	_data_->result = _data_->min_date;
	_g_object_unref0 (_data_->sorting);
	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_view_model_fetch_min_date_sync (FtStatsViewModel* self,
                                         GDate* result)
{
	GDate min_date = {0};
	GomRepository* _tmp0_;
	GomSorting* sorting = NULL;
	GObject* _tmp1_;
	GObject* _tmp2_;
	GomSorting* _tmp3_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	memset (&min_date, 0, sizeof (GDate));
	_tmp0_ = self->priv->repository;
	if (_tmp0_ == NULL) {
		*result = min_date;
		return;
	}
	_tmp1_ = g_object_new (gom_sorting_get_type (), NULL);
	_tmp2_ = G_IS_INITIALLY_UNOWNED (_tmp1_) ? g_object_ref_sink (_tmp1_) : _tmp1_;
	sorting = G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, gom_sorting_get_type (), GomSorting);
	_tmp3_ = sorting;
	gom_sorting_add (_tmp3_, FT_TYPE_AGGREGATED_STATS_ENTRY, "date", GOM_SORTING_ASCENDING);
	{
		GomResourceGroup* results = NULL;
		GomRepository* _tmp4_;
		GomSorting* _tmp5_;
		GomResourceGroup* _tmp6_;
		GomResourceGroup* _tmp7_;
		guint _tmp8_;
		guint _tmp9_;
		_tmp4_ = self->priv->repository;
		_tmp5_ = sorting;
		_tmp6_ = gom_repository_find_sorted_sync (_tmp4_, FT_TYPE_AGGREGATED_STATS_ENTRY, NULL, _tmp5_, &_inner_error0_);
		results = _tmp6_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp7_ = results;
		_tmp8_ = gom_resource_group_get_count (_tmp7_);
		_tmp9_ = _tmp8_;
		if (_tmp9_ > ((guint) 0)) {
			GomResourceGroup* _tmp10_;
			FtAggregatedStatsEntry* entry = NULL;
			GomResourceGroup* _tmp11_;
			GomResource* _tmp12_;
			FtAggregatedStatsEntry* _tmp13_;
			gboolean _tmp14_ = FALSE;
			FtAggregatedStatsEntry* _tmp15_;
			_tmp10_ = results;
			gom_resource_group_fetch_sync (_tmp10_, 0U, 1U, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_g_object_unref0 (results);
				goto __catch0_g_error;
			}
			_tmp11_ = results;
			_tmp12_ = gom_resource_group_get_index (_tmp11_, (guint) 0);
			_tmp13_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp12_, FT_TYPE_AGGREGATED_STATS_ENTRY, FtAggregatedStatsEntry));
			entry = _tmp13_;
			_tmp15_ = entry;
			if (_tmp15_ != NULL) {
				FtAggregatedStatsEntry* _tmp16_;
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				_tmp16_ = entry;
				_tmp17_ = ft_aggregated_stats_entry_get_date (_tmp16_);
				_tmp18_ = _tmp17_;
				_tmp14_ = _tmp18_ != NULL;
			} else {
				_tmp14_ = FALSE;
			}
			if (_tmp14_) {
				FtAggregatedStatsEntry* _tmp19_;
				const gchar* _tmp20_;
				const gchar* _tmp21_;
				GDate _tmp22_ = {0};
				_tmp19_ = entry;
				_tmp20_ = ft_aggregated_stats_entry_get_date (_tmp19_);
				_tmp21_ = _tmp20_;
				ft_database_parse_date (_tmp21_, &_tmp22_);
				*result = _tmp22_;
				_g_object_unref0 (entry);
				_g_object_unref0 (results);
				_g_object_unref0 (sorting);
				return;
			}
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (results);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp23_;
		const gchar* _tmp24_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp23_ = _error_;
		_tmp24_ = _tmp23_->message;
		g_critical ("stats-view.vala:375: Error while fetching minimal stats date: %s", _tmp24_);
		_g_error_free0 (_error_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (sorting);
		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;
	}
	*result = min_date;
	_g_object_unref0 (sorting);
	return;
}

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

static void
ft_stats_view_model_fetch_closest_date (FtStatsViewModel* self,
                                        GDate* date,
                                        FtNavigationDirection direction,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_)
{
	FtStatsViewModelFetchClosestDateData* _data_;
	FtStatsViewModel* _tmp0_;
	GDate _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_data_ = g_slice_new0 (FtStatsViewModelFetchClosestDateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_view_model_fetch_closest_date_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = *date;
	_data_->date = _tmp1_;
	_data_->direction = direction;
	ft_stats_view_model_fetch_closest_date_co (_data_);
}

static void
ft_stats_view_model_fetch_closest_date_finish (FtStatsViewModel* self,
                                               GAsyncResult* _res_,
                                               GDate* result)
{
	FtStatsViewModelFetchClosestDateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	*result = _data_->result;
}

static void
ft_stats_view_model_fetch_closest_date_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	FtStatsViewModelFetchClosestDateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_view_model_fetch_closest_date_co (_data_);
}

static gboolean
ft_stats_view_model_fetch_closest_date_co (FtStatsViewModelFetchClosestDateData* _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_ = _data_->self->priv->repository;
	if (_data_->_tmp0_ == NULL) {
		_data_->_tmp1_ = _data_->date;
		_data_->result = _data_->_tmp1_;
		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;
	}
	memset (&_data_->_tmp2_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp2_, G_TYPE_STRING);
	_data_->date_value = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->date;
	_data_->_tmp4_ = ft_database_serialize_date (&_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	g_value_set_string (&_data_->date_value, _data_->_tmp5_);
	_g_free0 (_data_->_tmp5_);
	memset (&_data_->_tmp6_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp6_, G_TYPE_STRING);
	_data_->category_value = _data_->_tmp6_;
	g_value_set_string (&_data_->category_value, "pomodoro");
	memset (&_data_->_tmp7_, 0, sizeof (GValue));
	g_value_init (&_data_->_tmp7_, G_TYPE_INT64);
	_data_->duration_value = _data_->_tmp7_;
	g_value_set_int64 (&_data_->duration_value, FT_INTERVAL_MINUTE);
	_data_->_tmp8_ = g_object_new (gom_sorting_get_type (), NULL);
	_data_->_tmp9_ = G_IS_INITIALLY_UNOWNED (_data_->_tmp8_) ? g_object_ref_sink (_data_->_tmp8_) : _data_->_tmp8_;
	_data_->sorting = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp9_, gom_sorting_get_type (), GomSorting);
	if (_data_->direction == FT_NAVIGATION_DIRECTION_FORWARD) {
		_data_->_tmp10_ = _data_->date_value;
		_data_->_tmp11_ = gom_filter_new_gte (FT_TYPE_AGGREGATED_STATS_ENTRY, "date", &_data_->_tmp10_);
		g_object_ref_sink (_data_->_tmp11_);
		_g_object_unref0 (_data_->date_filter);
		_data_->date_filter = _data_->_tmp11_;
		_data_->_tmp12_ = _data_->sorting;
		gom_sorting_add (_data_->_tmp12_, FT_TYPE_AGGREGATED_STATS_ENTRY, "date", GOM_SORTING_ASCENDING);
	} else {
		_data_->_tmp13_ = _data_->date_value;
		_data_->_tmp14_ = gom_filter_new_lte (FT_TYPE_AGGREGATED_STATS_ENTRY, "date", &_data_->_tmp13_);
		g_object_ref_sink (_data_->_tmp14_);
		_g_object_unref0 (_data_->date_filter);
		_data_->date_filter = _data_->_tmp14_;
		_data_->_tmp15_ = _data_->sorting;
		gom_sorting_add (_data_->_tmp15_, FT_TYPE_AGGREGATED_STATS_ENTRY, "date", GOM_SORTING_DESCENDING);
	}
	_data_->_tmp16_ = _data_->category_value;
	_data_->_tmp17_ = gom_filter_new_eq (FT_TYPE_AGGREGATED_STATS_ENTRY, "category", &_data_->_tmp16_);
	g_object_ref_sink (_data_->_tmp17_);
	_data_->category_filter = _data_->_tmp17_;
	_data_->_tmp18_ = _data_->duration_value;
	_data_->_tmp19_ = gom_filter_new_gte (FT_TYPE_AGGREGATED_STATS_ENTRY, "duration", &_data_->_tmp18_);
	g_object_ref_sink (_data_->_tmp19_);
	_data_->duration_filter = _data_->_tmp19_;
	_data_->_tmp20_ = _data_->date_filter;
	_data_->_tmp21_ = _data_->category_filter;
	_data_->_tmp22_ = gom_filter_new_and (_data_->_tmp20_, _data_->_tmp21_);
	g_object_ref_sink (_data_->_tmp22_);
	_data_->_tmp23_ = _data_->_tmp22_;
	_data_->_tmp24_ = _data_->duration_filter;
	_data_->_tmp25_ = gom_filter_new_and (_data_->_tmp23_, _data_->_tmp24_);
	g_object_ref_sink (_data_->_tmp25_);
	_data_->_tmp26_ = _data_->_tmp25_;
	_g_object_unref0 (_data_->_tmp23_);
	_data_->filter = _data_->_tmp26_;
	{
		_data_->_tmp27_ = _data_->self->priv->repository;
		_data_->_tmp28_ = _data_->filter;
		_data_->_tmp29_ = _data_->sorting;
		_data_->_state_ = 1;
		gom_repository_find_sorted_async (_data_->_tmp27_, FT_TYPE_AGGREGATED_STATS_ENTRY, _data_->_tmp28_, _data_->_tmp29_, ft_stats_view_model_fetch_closest_date_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp30_ = gom_repository_find_finish (_data_->_tmp27_, _data_->_res_, &_data_->_inner_error0_);
		_data_->results = _data_->_tmp30_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->_tmp31_ = _data_->results;
		_data_->_tmp32_ = gom_resource_group_get_count (_data_->_tmp31_);
		_data_->_tmp33_ = _data_->_tmp32_;
		if (_data_->_tmp33_ == ((guint) 0)) {
			if (_data_->direction == FT_NAVIGATION_DIRECTION_FORWARD) {
				_data_->_tmp35_ = _data_->self->priv->_max_date;
				_data_->_tmp34_ = _data_->_tmp35_;
			} else {
				_data_->_tmp36_ = _data_->self->priv->_min_date;
				_data_->_tmp34_ = _data_->_tmp36_;
			}
			_data_->result = _data_->_tmp34_;
			_g_object_unref0 (_data_->results);
			_g_object_unref0 (_data_->filter);
			_g_object_unref0 (_data_->duration_filter);
			_g_object_unref0 (_data_->category_filter);
			_g_object_unref0 (_data_->sorting);
			_g_object_unref0 (_data_->date_filter);
			G_IS_VALUE (&_data_->duration_value) ? (g_value_unset (&_data_->duration_value), NULL) : NULL;
			G_IS_VALUE (&_data_->category_value) ? (g_value_unset (&_data_->category_value), NULL) : NULL;
			G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->date_value), NULL) : NULL;
			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;
		}
		_data_->_tmp37_ = _data_->results;
		_data_->_state_ = 2;
		gom_resource_group_fetch_async (_data_->_tmp37_, 0U, 1U, ft_stats_view_model_fetch_closest_date_ready, _data_);
		return FALSE;
		_state_2:
		gom_resource_group_fetch_finish (_data_->_tmp37_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->results);
			goto __catch0_g_error;
		}
		_data_->_tmp38_ = _data_->results;
		_data_->_tmp39_ = gom_resource_group_get_index (_data_->_tmp38_, (guint) 0);
		_data_->_tmp40_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp39_, FT_TYPE_AGGREGATED_STATS_ENTRY, FtAggregatedStatsEntry));
		_data_->entry = _data_->_tmp40_;
		_data_->_tmp42_ = _data_->entry;
		if (_data_->_tmp42_ != NULL) {
			_data_->_tmp43_ = _data_->entry;
			_data_->_tmp44_ = ft_aggregated_stats_entry_get_date (_data_->_tmp43_);
			_data_->_tmp45_ = _data_->_tmp44_;
			memset (&_data_->_tmp46_, 0, sizeof (GDate));
			ft_database_parse_date (_data_->_tmp45_, &_data_->_tmp46_);
			_data_->_tmp41_ = _data_->_tmp46_;
		} else {
			_data_->_tmp47_ = _data_->date;
			_data_->_tmp41_ = _data_->_tmp47_;
		}
		_data_->result = _data_->_tmp41_;
		_g_object_unref0 (_data_->entry);
		_g_object_unref0 (_data_->results);
		_g_object_unref0 (_data_->filter);
		_g_object_unref0 (_data_->duration_filter);
		_g_object_unref0 (_data_->category_filter);
		_g_object_unref0 (_data_->sorting);
		_g_object_unref0 (_data_->date_filter);
		G_IS_VALUE (&_data_->duration_value) ? (g_value_unset (&_data_->duration_value), NULL) : NULL;
		G_IS_VALUE (&_data_->category_value) ? (g_value_unset (&_data_->category_value), NULL) : NULL;
		G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->date_value), NULL) : NULL;
		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_->_tmp48_ = _data_->_error_;
		_data_->_tmp49_ = _data_->_tmp48_->message;
		g_warning ("stats-view.vala:445: Error fetching closest date: %s", _data_->_tmp49_);
		_data_->_tmp50_ = _data_->date;
		_data_->result = _data_->_tmp50_;
		_g_error_free0 (_data_->_error_);
		_g_object_unref0 (_data_->filter);
		_g_object_unref0 (_data_->duration_filter);
		_g_object_unref0 (_data_->category_filter);
		_g_object_unref0 (_data_->sorting);
		_g_object_unref0 (_data_->date_filter);
		G_IS_VALUE (&_data_->duration_value) ? (g_value_unset (&_data_->duration_value), NULL) : NULL;
		G_IS_VALUE (&_data_->category_value) ? (g_value_unset (&_data_->category_value), NULL) : NULL;
		G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->date_value), NULL) : NULL;
		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_->filter);
	_g_object_unref0 (_data_->duration_filter);
	_g_object_unref0 (_data_->category_filter);
	_g_object_unref0 (_data_->sorting);
	_g_object_unref0 (_data_->date_filter);
	G_IS_VALUE (&_data_->duration_value) ? (g_value_unset (&_data_->duration_value), NULL) : NULL;
	G_IS_VALUE (&_data_->category_value) ? (g_value_unset (&_data_->category_value), NULL) : NULL;
	G_IS_VALUE (&_data_->date_value) ? (g_value_unset (&_data_->date_value), NULL) : NULL;
	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_view_model_navigate_data_free (gpointer _data)
{
	FtStatsViewModelNavigateData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (FtStatsViewModelNavigateData, _data_);
}

void
ft_stats_view_model_navigate (FtStatsViewModel* self,
                              FtNavigationDirection direction,
                              GCancellable* cancellable,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	FtStatsViewModelNavigateData* _data_;
	FtStatsViewModel* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (cancellable != NULL);
	_data_ = g_slice_new0 (FtStatsViewModelNavigateData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, ft_stats_view_model_navigate_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->direction = direction;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	ft_stats_view_model_navigate_co (_data_);
}

void
ft_stats_view_model_navigate_finish (FtStatsViewModel* self,
                                     GAsyncResult* _res_)
{
	FtStatsViewModelNavigateData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (NULL == _data_) {
		return;
	}
}

static void
ft_stats_view_model_navigate_ready (GObject* source_object,
                                    GAsyncResult* _res_,
                                    gpointer _user_data_)
{
	FtStatsViewModelNavigateData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	ft_stats_view_model_navigate_co (_data_);
}

static GDate*
_g_date_dup (GDate* self)
{
	GDate* dup;
	dup = g_new0 (GDate, 1);
	memcpy (dup, self, sizeof (GDate));
	return dup;
}

static gpointer
__g_date_dup0 (gpointer self)
{
	return self ? _g_date_dup (self) : NULL;
}

static gboolean
ft_stats_view_model_navigate_co (FtStatsViewModelNavigateData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_date_copy (&_data_->self->priv->_date);
	_data_->current_date = _data_->_tmp0_;
	_data_->_tmp1_ = g_date_copy (&_data_->self->priv->_date);
	_data_->date = _data_->_tmp1_;
	_data_->timeframe = _data_->self->priv->_timeframe;
	if (_data_->direction == FT_NAVIGATION_DIRECTION_FORWARD) {
		switch (_data_->timeframe) {
			case FT_TIMEFRAME_DAY:
			{
				_data_->_tmp2_ = _data_->date;
				g_date_add_days (_data_->_tmp2_, (guint) 1);
				break;
			}
			case FT_TIMEFRAME_WEEK:
			{
				_data_->_tmp3_ = _data_->date;
				g_date_add_days (_data_->_tmp3_, (guint) 7);
				break;
			}
			case FT_TIMEFRAME_MONTH:
			{
				_data_->_tmp4_ = _data_->date;
				g_date_add_months (_data_->_tmp4_, (guint) 1);
				break;
			}
			default:
			{
				g_assert_not_reached ();
			}
		}
	} else {
		_data_->_tmp5_ = _data_->date;
		g_date_subtract_days (_data_->_tmp5_, (guint) 1);
	}
	_data_->_tmp6_ = _data_->date;
	_data_->_tmp7_ = *_data_->_tmp6_;
	memset (&_data_->_tmp8_, 0, sizeof (GDate));
	_data_->_state_ = 1;
	ft_stats_view_model_fetch_closest_date (_data_->self, &_data_->_tmp7_, _data_->direction, ft_stats_view_model_navigate_ready, _data_);
	return FALSE;
	_state_1:
	ft_stats_view_model_fetch_closest_date_finish (_data_->self, _data_->_res_, &_data_->_tmp8_);
	_data_->closest_date = _data_->_tmp8_;
	_data_->skipped = 0U;
	if (!g_date_valid (&_data_->closest_date)) {
		_data_->_tmp9_ = TRUE;
	} else {
		_data_->_tmp9_ = g_cancellable_is_cancelled (_data_->cancellable);
	}
	if (_data_->_tmp9_) {
		_g_free0 (_data_->date);
		_g_free0 (_data_->current_date);
		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;
	}
	_data_->_tmp10_ = _data_->closest_date;
	memset (&_data_->_tmp11_, 0, sizeof (GDate));
	ft_timeframe_normalize_date (_data_->timeframe, &_data_->_tmp10_, &_data_->_tmp11_);
	_data_->_tmp12_ = __g_date_dup0 (&_data_->_tmp11_);
	_g_free0 (_data_->date);
	_data_->date = _data_->_tmp12_;
	switch (_data_->self->priv->_timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			_data_->_tmp13_ = _data_->current_date;
			_data_->_tmp14_ = _data_->date;
			_data_->_tmp15_ = *_data_->_tmp14_;
			_data_->skipped = (guint) abs (g_date_days_between (_data_->_tmp13_, &_data_->_tmp15_));
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			_data_->_tmp16_ = _data_->current_date;
			_data_->_tmp17_ = _data_->date;
			_data_->_tmp18_ = *_data_->_tmp17_;
			_data_->skipped = (guint) (abs (g_date_days_between (_data_->_tmp16_, &_data_->_tmp18_)) / 7);
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			_data_->_tmp19_ = _data_->date;
			_data_->_tmp20_ = _data_->current_date;
			_data_->_tmp21_ = _data_->date;
			_data_->_tmp22_ = _data_->current_date;
			_data_->skipped_int = ((((gint) g_date_get_year (_data_->_tmp19_)) - ((gint) g_date_get_year (_data_->_tmp20_))) * 12) + (((gint) g_date_get_month (_data_->_tmp21_)) - ((gint) g_date_get_month (_data_->_tmp22_)));
			_data_->skipped = (guint) abs (_data_->skipped_int);
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_data_->_tmp23_ = _data_->date;
	_data_->_tmp24_ = g_date_copy (_data_->_tmp23_);
	_data_->_tmp25_ = _data_->_tmp24_;
	_data_->self->priv->user_selected_date = *_data_->_tmp25_;
	_g_free0 (_data_->_tmp25_);
	_data_->_tmp26_ = _data_->date;
	_data_->_tmp27_ = g_date_copy (_data_->_tmp26_);
	_data_->_tmp28_ = _data_->_tmp27_;
	_data_->_tmp29_ = *_data_->_tmp28_;
	ft_stats_view_model_set_date (_data_->self, &_data_->_tmp29_);
	_g_free0 (_data_->_tmp28_);
	if (_data_->skipped > 1U) {
		_data_->_tmp30_ = _data_->date;
		_data_->_tmp31_ = *_data_->_tmp30_;
		g_signal_emit (_data_->self, ft_stats_view_model_signals[FT_STATS_VIEW_MODEL_NAVIGATED_SIGNAL], 0, _data_->direction, &_data_->_tmp31_, _data_->skipped - 1U);
	} else {
		_data_->_tmp32_ = _data_->date;
		_data_->_tmp33_ = *_data_->_tmp32_;
		g_signal_emit (_data_->self, ft_stats_view_model_signals[FT_STATS_VIEW_MODEL_NAVIGATED_SIGNAL], 0, _data_->direction, &_data_->_tmp33_, 0U);
	}
	_g_free0 (_data_->date);
	_g_free0 (_data_->current_date);
	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_view_model_real_dispose (GObject* base)
{
	FtStatsViewModel * self;
	self = (FtStatsViewModel*) base;
	if (self->priv->woke_up_id != ((gulong) 0)) {
		FtSleepMonitor* _tmp0_;
		_tmp0_ = self->priv->sleep_monitor;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->woke_up_id);
		self->priv->woke_up_id = (gulong) 0;
	}
	if (self->priv->entry_saved_id != ((gulong) 0)) {
		FtStatsManager* _tmp1_;
		_tmp1_ = self->priv->stats_manager;
		g_signal_handler_disconnect ((GObject*) _tmp1_, self->priv->entry_saved_id);
		self->priv->entry_saved_id = (gulong) 0;
	}
	_g_object_unref0 (self->priv->repository);
	self->priv->repository = NULL;
	_g_object_unref0 (self->priv->stats_manager);
	self->priv->stats_manager = NULL;
	_g_object_unref0 (self->priv->sleep_monitor);
	self->priv->sleep_monitor = NULL;
	_g_object_unref0 (self->priv->navigation_cancellable);
	self->priv->navigation_cancellable = NULL;
	G_OBJECT_CLASS (ft_stats_view_model_parent_class)->dispose (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject));
}

FtStatsViewModel*
ft_stats_view_model_construct (GType object_type)
{
	FtStatsViewModel * self = NULL;
	self = (FtStatsViewModel*) g_object_new (object_type, NULL);
	return self;
}

FtStatsViewModel*
ft_stats_view_model_new (void)
{
	return ft_stats_view_model_construct (FT_TYPE_STATS_VIEW_MODEL);
}

FtTimeframe
ft_stats_view_model_get_timeframe (FtStatsViewModel* self)
{
	FtTimeframe result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_timeframe;
	return result;
}

void
ft_stats_view_model_set_timeframe (FtStatsViewModel* self,
                                   FtTimeframe value)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_timeframe == value) {
		return;
	}
	self->priv->_timeframe = value;
	g_object_notify ((GObject*) self, "timeframe");
}

void
ft_stats_view_model_get_date (FtStatsViewModel* self,
                              GDate * result)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_date;
	*result = _tmp0_;
	return;
}

void
ft_stats_view_model_set_date (FtStatsViewModel* self,
                              GDate * value)
{
	gboolean _tmp0_ = FALSE;
	GDate* _tmp2_;
	GDate* _tmp3_;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (value)) {
		return;
	}
	if (g_date_valid (&self->priv->_date)) {
		GDate _tmp1_;
		_tmp1_ = *value;
		_tmp0_ = g_date_compare (&self->priv->_date, &_tmp1_) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = g_date_copy (value);
	_tmp3_ = _tmp2_;
	self->priv->_date = *_tmp3_;
	_g_free0 (_tmp3_);
	ft_stats_view_model_validate_user_selected_date (self);
	g_object_notify ((GObject*) self, "date");
}

void
ft_stats_view_model_get_min_date (FtStatsViewModel* self,
                                  GDate * result)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_min_date;
	*result = _tmp0_;
	return;
}

static void
ft_stats_view_model_set_min_date (FtStatsViewModel* self,
                                  GDate * value)
{
	gboolean _tmp0_ = FALSE;
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	if (g_date_valid (&self->priv->_min_date)) {
		GDate _tmp1_;
		_tmp1_ = *value;
		_tmp0_ = g_date_compare (&self->priv->_min_date, &_tmp1_) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = *value;
	self->priv->_min_date = _tmp2_;
	g_object_notify ((GObject*) self, "min-date");
}

void
ft_stats_view_model_get_max_date (FtStatsViewModel* self,
                                  GDate * result)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_max_date;
	*result = _tmp0_;
	return;
}

static void
ft_stats_view_model_set_max_date (FtStatsViewModel* self,
                                  GDate * value)
{
	gboolean _tmp0_ = FALSE;
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	if (g_date_valid (&self->priv->_max_date)) {
		GDate _tmp1_;
		_tmp1_ = *value;
		_tmp0_ = g_date_compare (&self->priv->_max_date, &_tmp1_) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp2_ = *value;
	self->priv->_max_date = _tmp2_;
	g_object_notify ((GObject*) self, "max-date");
}

static void
g_cclosure_user_marshal_VOID__ENUM_BOXED_UINT (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__ENUM_BOXED_UINT) (gpointer data1, gint arg_1, gpointer arg_2, guint arg_3, gpointer data2);
	register GMarshalFunc_VOID__ENUM_BOXED_UINT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__ENUM_BOXED_UINT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_enum (param_values + 1), g_value_get_boxed (param_values + 2), g_value_get_uint (param_values + 3), data2);
}

static void
_ft_stats_view_model___lambda27_ (FtStatsViewModel* self,
                                  GObject* obj,
                                  GAsyncResult* res)
{
	GDate _tmp0_ = {0};
	g_return_if_fail (res != NULL);
	ft_stats_view_model_fetch_min_date_finish (self, res, &_tmp0_);
	ft_stats_view_model_set_min_date (self, &_tmp0_);
}

static void
__ft_stats_view_model___lambda27__gasync_ready_callback (GObject* source_object,
                                                         GAsyncResult* res,
                                                         gpointer self)
{
	_ft_stats_view_model___lambda27_ ((FtStatsViewModel*) self, source_object, res);
	g_object_unref (self);
}

static void
_ft_stats_view_model___lambda28_ (FtStatsViewModel* self,
                                  FtStatsEntry* entry)
{
	g_return_if_fail (entry != NULL);
	ft_stats_view_model_update_date_range (self);
}

static void
__ft_stats_view_model___lambda28__ft_stats_manager_entry_saved (FtStatsManager* _sender,
                                                                FtStatsEntry* entry,
                                                                gpointer self)
{
	_ft_stats_view_model___lambda28_ ((FtStatsViewModel*) self, entry);
}

static void
_ft_stats_view_model___lambda29_ (FtStatsViewModel* self)
{
	ft_stats_view_model_update_date_range (self);
}

static void
__ft_stats_view_model___lambda29__ft_sleep_monitor_woke_up (FtSleepMonitor* _sender,
                                                            gpointer self)
{
	_ft_stats_view_model___lambda29_ ((FtStatsViewModel*) self);
}

static GObject *
ft_stats_view_model_constructor (GType type,
                                 guint n_construct_properties,
                                 GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtStatsViewModel * self;
	GomRepository* _tmp0_;
	GomRepository* _tmp1_;
	FtStatsManager* _tmp2_;
	FtSleepMonitor* _tmp3_;
	GDate today = {0};
	FtStatsManager* _tmp4_;
	GDate _tmp5_ = {0};
	GDate* _tmp6_;
	GDate* _tmp7_;
	GDate* _tmp8_;
	GDate* _tmp9_;
	GDate* _tmp10_;
	GDate* _tmp11_;
	FtStatsManager* _tmp12_;
	gulong _tmp13_;
	FtSleepMonitor* _tmp14_;
	gulong _tmp15_;
	parent_class = G_OBJECT_CLASS (ft_stats_view_model_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_VIEW_MODEL, FtStatsViewModel);
	_tmp0_ = ft_database_get_repository ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->repository);
	self->priv->repository = _tmp1_;
	_tmp2_ = ft_stats_manager_new ();
	_g_object_unref0 (self->priv->stats_manager);
	self->priv->stats_manager = _tmp2_;
	_tmp3_ = ft_sleep_monitor_new ();
	_g_object_unref0 (self->priv->sleep_monitor);
	self->priv->sleep_monitor = _tmp3_;
	_tmp4_ = self->priv->stats_manager;
	ft_stats_manager_get_today (_tmp4_, &_tmp5_);
	today = _tmp5_;
	_tmp6_ = g_date_copy (&today);
	_tmp7_ = _tmp6_;
	self->priv->user_selected_date = *_tmp7_;
	_g_free0 (_tmp7_);
	_tmp8_ = g_date_copy (&today);
	_tmp9_ = _tmp8_;
	self->priv->_max_date = *_tmp9_;
	_g_free0 (_tmp9_);
	_tmp10_ = g_date_copy (&today);
	_tmp11_ = _tmp10_;
	self->priv->_date = *_tmp11_;
	_g_free0 (_tmp11_);
	ft_stats_view_model_fetch_min_date (self, __ft_stats_view_model___lambda27__gasync_ready_callback, g_object_ref (self));
	_tmp12_ = self->priv->stats_manager;
	_tmp13_ = g_signal_connect_object (_tmp12_, "entry-saved", (GCallback) __ft_stats_view_model___lambda28__ft_stats_manager_entry_saved, self, 0);
	self->priv->entry_saved_id = _tmp13_;
	_tmp14_ = self->priv->sleep_monitor;
	_tmp15_ = g_signal_connect_object (_tmp14_, "woke-up", (GCallback) __ft_stats_view_model___lambda29__ft_sleep_monitor_woke_up, self, 0);
	self->priv->woke_up_id = _tmp15_;
	return obj;
}

static void
ft_stats_view_model_class_init (FtStatsViewModelClass * klass,
                                gpointer klass_data)
{
	ft_stats_view_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsViewModel_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_stats_view_model_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_view_model_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_view_model_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_stats_view_model_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_view_model_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_VIEW_MODEL_TIMEFRAME_PROPERTY, ft_stats_view_model_properties[FT_STATS_VIEW_MODEL_TIMEFRAME_PROPERTY] = g_param_spec_enum ("timeframe", "timeframe", "timeframe", FT_TYPE_TIMEFRAME, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_VIEW_MODEL_DATE_PROPERTY, ft_stats_view_model_properties[FT_STATS_VIEW_MODEL_DATE_PROPERTY] = g_param_spec_boxed ("date", "date", "date", G_TYPE_DATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_VIEW_MODEL_MIN_DATE_PROPERTY, ft_stats_view_model_properties[FT_STATS_VIEW_MODEL_MIN_DATE_PROPERTY] = g_param_spec_boxed ("min-date", "min-date", "min-date", G_TYPE_DATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_VIEW_MODEL_MAX_DATE_PROPERTY, ft_stats_view_model_properties[FT_STATS_VIEW_MODEL_MAX_DATE_PROPERTY] = g_param_spec_boxed ("max-date", "max-date", "max-date", G_TYPE_DATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY));
	ft_stats_view_model_signals[FT_STATS_VIEW_MODEL_NAVIGATED_SIGNAL] = g_signal_new ("navigated", FT_TYPE_STATS_VIEW_MODEL, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__ENUM_BOXED_UINT, G_TYPE_NONE, 3, FT_TYPE_NAVIGATION_DIRECTION, G_TYPE_DATE, G_TYPE_UINT);
}

static void
ft_stats_view_model_instance_init (FtStatsViewModel * self,
                                   gpointer klass)
{
	self->priv = ft_stats_view_model_get_instance_private (self);
	self->priv->_timeframe = FT_TIMEFRAME_DAY;
	self->priv->repository = NULL;
	self->priv->stats_manager = NULL;
	self->priv->sleep_monitor = NULL;
	self->priv->navigation_cancellable = NULL;
	self->priv->woke_up_id = (gulong) 0;
	self->priv->entry_saved_id = (gulong) 0;
}

static void
ft_stats_view_model_finalize (GObject * obj)
{
	FtStatsViewModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_VIEW_MODEL, FtStatsViewModel);
	_g_object_unref0 (self->priv->repository);
	_g_object_unref0 (self->priv->stats_manager);
	_g_object_unref0 (self->priv->sleep_monitor);
	_g_object_unref0 (self->priv->navigation_cancellable);
	G_OBJECT_CLASS (ft_stats_view_model_parent_class)->finalize (obj);
}

static GType
ft_stats_view_model_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsViewModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_view_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsViewModel), 0, (GInstanceInitFunc) ft_stats_view_model_instance_init, NULL };
	GType ft_stats_view_model_type_id;
	ft_stats_view_model_type_id = g_type_register_static (G_TYPE_OBJECT, "FtStatsViewModel", &g_define_type_info, 0);
	FtStatsViewModel_private_offset = g_type_add_instance_private (ft_stats_view_model_type_id, sizeof (FtStatsViewModelPrivate));
	return ft_stats_view_model_type_id;
}

GType
ft_stats_view_model_get_type (void)
{
	static volatile gsize ft_stats_view_model_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_view_model_type_id__once)) {
		GType ft_stats_view_model_type_id;
		ft_stats_view_model_type_id = ft_stats_view_model_get_type_once ();
		g_once_init_leave (&ft_stats_view_model_type_id__once, ft_stats_view_model_type_id);
	}
	return ft_stats_view_model_type_id__once;
}

static void
_vala_ft_stats_view_model_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	FtStatsViewModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_VIEW_MODEL, FtStatsViewModel);
	switch (property_id) {
		case FT_STATS_VIEW_MODEL_TIMEFRAME_PROPERTY:
		g_value_set_enum (value, ft_stats_view_model_get_timeframe (self));
		break;
		case FT_STATS_VIEW_MODEL_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_view_model_get_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_STATS_VIEW_MODEL_MIN_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_view_model_get_min_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_STATS_VIEW_MODEL_MAX_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_view_model_get_max_date (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_view_model_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec)
{
	FtStatsViewModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_VIEW_MODEL, FtStatsViewModel);
	switch (property_id) {
		case FT_STATS_VIEW_MODEL_TIMEFRAME_PROPERTY:
		ft_stats_view_model_set_timeframe (self, g_value_get_enum (value));
		break;
		case FT_STATS_VIEW_MODEL_DATE_PROPERTY:
		ft_stats_view_model_set_date (self, g_value_get_boxed (value));
		break;
		case FT_STATS_VIEW_MODEL_MIN_DATE_PROPERTY:
		ft_stats_view_model_set_min_date (self, g_value_get_boxed (value));
		break;
		case FT_STATS_VIEW_MODEL_MAX_DATE_PROPERTY:
		ft_stats_view_model_set_max_date (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
ft_stats_view_get_instance_private (FtStatsView* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsView_private_offset);
}

static gchar*
ft_stats_view_build_page_name (FtStatsView* self,
                               FtTimeframe timeframe,
                               GDate* date)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	GDate _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = ft_timeframe_to_string (timeframe);
	_tmp1_ = _tmp0_;
	_tmp2_ = *date;
	_tmp3_ = ft_date_utils_format_date (&_tmp2_, "%d-%m-%Y");
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strdup_printf ("%s:%s", _tmp1_, _tmp4_);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	_g_free0 (_tmp1_);
	result = _tmp6_;
	return result;
}

static FtStatsPage*
ft_stats_view_create_page (FtStatsView* self,
                           FtTimeframe timeframe,
                           GDate* date)
{
	FtStatsPage* page = NULL;
	FtStatsPage* _tmp7_;
	FtStatsPage* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	switch (timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			GDate _tmp0_;
			FtStatsDayPage* _tmp1_;
			FtStatsPage* _tmp2_;
			_tmp0_ = *date;
			_tmp1_ = ft_stats_day_page_new (&_tmp0_);
			g_object_ref_sink (_tmp1_);
			_g_object_unref0 (page);
			page = (FtStatsPage*) _tmp1_;
			_tmp2_ = page;
			g_object_bind_property_with_closures ((GObject*) self, "daily-interval", (GObject*) _tmp2_, "interval", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			GDate _tmp3_;
			FtStatsWeekPage* _tmp4_;
			_tmp3_ = *date;
			_tmp4_ = ft_stats_week_page_new (&_tmp3_);
			g_object_ref_sink (_tmp4_);
			_g_object_unref0 (page);
			page = (FtStatsPage*) _tmp4_;
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			GDate _tmp5_;
			FtStatsMonthPage* _tmp6_;
			_tmp5_ = *date;
			_tmp6_ = ft_stats_month_page_new (&_tmp5_);
			g_object_ref_sink (_tmp6_);
			_g_object_unref0 (page);
			page = (FtStatsPage*) _tmp6_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp7_ = page;
	gtk_widget_set_valign ((GtkWidget*) _tmp7_, GTK_ALIGN_START);
	result = page;
	return result;
}

static FtStatsPage*
ft_stats_view_get_page (FtStatsView* self,
                        const gchar* name)
{
	GtkStack* _tmp0_;
	GtkWidget* _tmp1_;
	FtStatsPage* _tmp2_;
	FtStatsPage* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->pages;
	_tmp1_ = gtk_stack_get_child_by_name (_tmp0_, name);
	_tmp2_ = _g_object_ref0 (FT_IS_STATS_PAGE (_tmp1_) ? ((FtStatsPage*) _tmp1_) : NULL);
	result = _tmp2_;
	return result;
}

static FtStatsPage*
ft_stats_view_get_or_create_page (FtStatsView* self,
                                  FtTimeframe timeframe,
                                  GDate* date)
{
	gchar* page_name = NULL;
	GDate _tmp0_;
	gchar* _tmp1_;
	FtStatsPage* page = NULL;
	const gchar* _tmp2_;
	FtStatsPage* _tmp3_;
	FtStatsPage* _tmp4_;
	FtStatsPage* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = *date;
	_tmp1_ = ft_stats_view_build_page_name (self, timeframe, &_tmp0_);
	page_name = _tmp1_;
	_tmp2_ = page_name;
	_tmp3_ = ft_stats_view_get_page (self, _tmp2_);
	page = _tmp3_;
	_tmp4_ = page;
	if (_tmp4_ == NULL) {
		GDate _tmp5_;
		FtStatsPage* _tmp6_;
		GtkStack* _tmp7_;
		FtStatsPage* _tmp8_;
		const gchar* _tmp9_;
		_tmp5_ = *date;
		_tmp6_ = ft_stats_view_create_page (self, timeframe, &_tmp5_);
		_g_object_unref0 (page);
		page = _tmp6_;
		_tmp7_ = self->priv->pages;
		_tmp8_ = page;
		_tmp9_ = page_name;
		gtk_stack_add_named (_tmp7_, G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, gtk_widget_get_type (), GtkWidget), _tmp9_);
	}
	result = page;
	_g_free0 (page_name);
	return result;
}

static void
ft_stats_view_update_page (FtStatsView* self,
                           GtkStackTransitionType transition)
{
	GtkStack* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	FtStatsPage* page = NULL;
	FtStatsViewModel* _tmp3_;
	FtTimeframe _tmp4_;
	FtTimeframe _tmp5_;
	FtStatsViewModel* _tmp6_;
	GDate _tmp7_ = {0};
	GDate _tmp8_;
	FtStatsPage* _tmp9_;
	gchar* page_name = NULL;
	GtkStack* _tmp10_;
	FtStatsPage* _tmp11_;
	GtkStackPage* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	GQueue* _tmp16_;
	FtStatsPage* _tmp17_;
	GQueue* _tmp18_;
	FtStatsPage* _tmp19_;
	GtkStack* _tmp26_;
	const gchar* _tmp27_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->stack;
	_tmp1_ = gtk_stack_get_visible_child_name (_tmp0_);
	_tmp2_ = _tmp1_;
	if (g_strcmp0 (_tmp2_, "content") != 0) {
		return;
	}
	if (!gtk_widget_get_mapped ((GtkWidget*) self)) {
		return;
	}
	_tmp3_ = self->priv->model;
	_tmp4_ = ft_stats_view_model_get_timeframe (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->priv->model;
	ft_stats_view_model_get_date (_tmp6_, &_tmp7_);
	_tmp8_ = _tmp7_;
	_tmp9_ = ft_stats_view_get_or_create_page (self, _tmp5_, &_tmp8_);
	page = _tmp9_;
	_tmp10_ = self->priv->pages;
	_tmp11_ = page;
	_tmp12_ = gtk_stack_get_page (_tmp10_, (GtkWidget*) _tmp11_);
	_tmp13_ = gtk_stack_page_get_name (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = g_strdup (_tmp14_);
	page_name = _tmp15_;
	_tmp16_ = self->priv->pages_history;
	_tmp17_ = page;
	g_queue_remove (_tmp16_, _tmp17_);
	_tmp18_ = self->priv->pages_history;
	_tmp19_ = page;
	g_queue_push_head (_tmp18_, _tmp19_);
	while (TRUE) {
		GQueue* _tmp20_;
		FtStatsPage* last_page = NULL;
		GQueue* _tmp21_;
		gpointer _tmp22_;
		FtStatsPage* _tmp23_;
		GtkStack* _tmp24_;
		FtStatsPage* _tmp25_;
		_tmp20_ = self->priv->pages_history;
		if (!(_tmp20_->length > FT_STATS_VIEW_PAGES_HISTORY_LIMIT)) {
			break;
		}
		_tmp21_ = self->priv->pages_history;
		_tmp22_ = g_queue_pop_tail (_tmp21_);
		_tmp23_ = _g_object_ref0 ((FtStatsPage*) _tmp22_);
		last_page = _tmp23_;
		_tmp24_ = self->priv->pages;
		_tmp25_ = last_page;
		gtk_stack_remove (_tmp24_, (GtkWidget*) _tmp25_);
		_g_object_unref0 (last_page);
	}
	_tmp26_ = self->priv->pages;
	_tmp27_ = page_name;
	gtk_stack_set_visible_child_full (_tmp26_, _tmp27_, transition);
	ft_stats_view_update_title (self);
	ft_stats_view_update_actions (self);
	ft_stats_view_mark_user_active (self);
	_g_free0 (page_name);
	_g_object_unref0 (page);
}

static gboolean
__lambda31_ (FtStatsView* self)
{
	gboolean result;
	self->priv->update_page_idle_id = (guint) 0;
	ft_stats_view_update_page (self, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda31__gtk_tick_callback (GtkWidget* widget,
                                GdkFrameClock* frame_clock,
                                gpointer self)
{
	gboolean result;
	result = __lambda31_ ((FtStatsView*) self);
	return result;
}

static void
ft_stats_view_queue_update_page (FtStatsView* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->update_page_idle_id != ((guint) 0)) {
		return;
	}
	self->priv->update_page_idle_id = gtk_widget_add_tick_callback ((GtkWidget*) self, ___lambda31__gtk_tick_callback, g_object_ref (self), g_object_unref);
}

static void
ft_stats_view_clear_pages (FtStatsView* self)
{
	g_return_if_fail (self != NULL);
	while (TRUE) {
		GQueue* _tmp0_;
		FtStatsPage* last_page = NULL;
		GQueue* _tmp1_;
		gpointer _tmp2_;
		FtStatsPage* _tmp3_;
		GtkStack* _tmp4_;
		FtStatsPage* _tmp5_;
		_tmp0_ = self->priv->pages_history;
		if (!(_tmp0_->length > ((guint) 0))) {
			break;
		}
		_tmp1_ = self->priv->pages_history;
		_tmp2_ = g_queue_pop_tail (_tmp1_);
		_tmp3_ = _g_object_ref0 ((FtStatsPage*) _tmp2_);
		last_page = _tmp3_;
		_tmp4_ = self->priv->pages;
		_tmp5_ = last_page;
		gtk_stack_remove (_tmp4_, (GtkWidget*) _tmp5_);
		_g_object_unref0 (last_page);
	}
}

static void
__lambda32_ (FtStatsView* self)
{
	_g_object_unref0 (self->priv->last_toast);
	self->priv->last_toast = NULL;
}

static void
___lambda32__adw_toast_dismissed (AdwToast* _sender,
                                  gpointer self)
{
	__lambda32_ ((FtStatsView*) self);
}

static void
ft_stats_view_notify_skipped_pages (FtStatsView* self,
                                    guint count)
{
	gchar* message = NULL;
	FtStatsViewModel* _tmp0_;
	FtTimeframe _tmp1_;
	FtTimeframe _tmp2_;
	AdwToast* toast = NULL;
	const gchar* _tmp6_;
	AdwToast* _tmp7_;
	AdwToast* _tmp8_;
	AdwToast* _tmp9_;
	AdwToast* _tmp10_;
	AdwToast* _tmp11_;
	FtWindow* window = NULL;
	GtkRoot* _tmp12_;
	FtWindow* _tmp13_;
	FtWindow* _tmp14_;
	FtWindow* _tmp16_;
	AdwToast* _tmp17_;
	AdwToast* _tmp18_;
	AdwToast* _tmp19_;
	AdwToast* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = ft_stats_view_model_get_timeframe (_tmp0_);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case FT_TIMEFRAME_DAY:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup_printf (ngettext ("Skipped %u day", "Skipped %u days", (gulong) count), count);
			_g_free0 (message);
			message = _tmp3_;
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup_printf (ngettext ("Skipped %u week", "Skipped %u weeks", (gulong) count), count);
			_g_free0 (message);
			message = _tmp4_;
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup_printf (ngettext ("Skipped %u month", "Skipped %u months", (gulong) count), count);
			_g_free0 (message);
			message = _tmp5_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp6_ = message;
	_tmp7_ = adw_toast_new (_tmp6_);
	toast = _tmp7_;
	_tmp8_ = toast;
	adw_toast_set_use_markup (_tmp8_, FALSE);
	_tmp9_ = toast;
	adw_toast_set_priority (_tmp9_, ADW_TOAST_PRIORITY_NORMAL);
	_tmp10_ = toast;
	adw_toast_set_timeout (_tmp10_, FT_STATS_VIEW_TOAST_DISMISS_TIMEOUT);
	_tmp11_ = toast;
	g_signal_connect_object (_tmp11_, "dismissed", (GCallback) ___lambda32__adw_toast_dismissed, self, 0);
	_tmp12_ = gtk_widget_get_root ((GtkWidget*) self);
	_tmp13_ = _g_object_ref0 (FT_IS_WINDOW (_tmp12_) ? ((FtWindow*) _tmp12_) : NULL);
	window = _tmp13_;
	_tmp14_ = window;
	if (_tmp14_ == NULL) {
		const gchar* _tmp15_;
		_tmp15_ = message;
		g_warning ("stats-view.vala:860: Unable to show a toast '%s'", _tmp15_);
		_g_object_unref0 (window);
		_g_object_unref0 (toast);
		_g_free0 (message);
		return;
	}
	_tmp16_ = window;
	_tmp17_ = toast;
	_tmp18_ = _g_object_ref0 (_tmp17_);
	ft_window_add_toast (_tmp16_, _tmp18_);
	_tmp19_ = toast;
	_tmp20_ = _g_object_ref0 (_tmp19_);
	_g_object_unref0 (self->priv->last_toast);
	self->priv->last_toast = _tmp20_;
	_g_object_unref0 (window);
	_g_object_unref0 (toast);
	_g_free0 (message);
}

static void
ft_stats_view_navigate_to_today (FtStatsView* self)
{
	FtStatsViewModel* _tmp0_;
	FtStatsViewModel* _tmp1_;
	GDate _tmp2_ = {0};
	GDate _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = self->priv->model;
	ft_stats_view_model_get_max_date (_tmp1_, &_tmp2_);
	_tmp3_ = _tmp2_;
	ft_stats_view_model_select_date (_tmp0_, &_tmp3_);
}

static void
ft_stats_view_navigate_up (FtStatsView* self)
{
	FtTimeframe timeframe = 0;
	FtStatsViewModel* _tmp0_;
	FtTimeframe _tmp1_;
	FtTimeframe _tmp2_;
	GDate date = {0};
	FtStatsViewModel* _tmp3_;
	GDate _tmp4_ = {0};
	FtStatsViewModel* _tmp5_;
	GDate _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = ft_stats_view_model_get_timeframe (_tmp0_);
	_tmp2_ = _tmp1_;
	timeframe = _tmp2_;
	_tmp3_ = self->priv->model;
	ft_stats_view_model_get_selection_date (_tmp3_, &_tmp4_);
	date = _tmp4_;
	switch (timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			timeframe = FT_TIMEFRAME_WEEK;
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			timeframe = FT_TIMEFRAME_MONTH;
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			return;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp5_ = self->priv->model;
	_tmp6_ = date;
	ft_stats_view_model_select (_tmp5_, &_tmp6_, timeframe);
}

static void
ft_stats_view_activate_previous (FtStatsView* self,
                                 GSimpleAction* action,
                                 GVariant* parameter)
{
	GCancellable* _tmp0_;
	GCancellable* _tmp2_;
	FtStatsViewModel* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->navigation_cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->navigation_cancellable;
		g_cancellable_cancel (_tmp1_);
	}
	_tmp2_ = g_cancellable_new ();
	_g_object_unref0 (self->priv->navigation_cancellable);
	self->priv->navigation_cancellable = _tmp2_;
	_tmp3_ = self->priv->model;
	_tmp4_ = self->priv->navigation_cancellable;
	ft_stats_view_model_navigate (_tmp3_, FT_NAVIGATION_DIRECTION_BACKWARD, _tmp4_, NULL, NULL);
}

static void
ft_stats_view_activate_next (FtStatsView* self,
                             GSimpleAction* action,
                             GVariant* parameter)
{
	GCancellable* _tmp0_;
	GCancellable* _tmp2_;
	FtStatsViewModel* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->navigation_cancellable;
	if (_tmp0_ != NULL) {
		GCancellable* _tmp1_;
		_tmp1_ = self->priv->navigation_cancellable;
		g_cancellable_cancel (_tmp1_);
	}
	_tmp2_ = g_cancellable_new ();
	_g_object_unref0 (self->priv->navigation_cancellable);
	self->priv->navigation_cancellable = _tmp2_;
	_tmp3_ = self->priv->model;
	_tmp4_ = self->priv->navigation_cancellable;
	ft_stats_view_model_navigate (_tmp3_, FT_NAVIGATION_DIRECTION_FORWARD, _tmp4_, NULL, NULL);
}

static void
ft_stats_view_activate_today (FtStatsView* self,
                              GSimpleAction* action,
                              GVariant* parameter)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	ft_stats_view_navigate_to_today (self);
}

static void
ft_stats_view_activate_up (FtStatsView* self)
{
	g_return_if_fail (self != NULL);
	ft_stats_view_navigate_up (self);
}

static void
ft_stats_view_activate_timeframe (FtStatsView* self,
                                  GSimpleAction* action,
                                  GVariant* parameter)
{
	FtStatsViewModel* _tmp0_;
	const gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = g_variant_get_string (parameter, NULL);
	ft_stats_view_model_select_timeframe (_tmp0_, ft_timeframe_from_string (_tmp1_));
}

static void
ft_stats_view_activate_set_timeframe (FtStatsView* self,
                                      GSimpleAction* action,
                                      GVariant* parameter)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	if (parameter != NULL) {
		GSimpleAction* _tmp0_;
		_tmp0_ = self->priv->timeframe_action;
		g_signal_emit_by_name (_tmp0_, "activate", parameter);
	}
}

static void
ft_stats_view_activate_select_day_action (FtStatsView* self,
                                          GSimpleAction* action,
                                          GVariant* parameter)
{
	GDate date = {0};
	GDate _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	g_return_if_fail (action != NULL);
	if (parameter == NULL) {
		return;
	}
	ft_date_utils_date_from_variant (parameter, &_tmp0_);
	date = _tmp0_;
	if (g_date_valid (&date)) {
		FtStatsViewModel* _tmp1_;
		GDate _tmp2_;
		_tmp1_ = self->priv->model;
		_tmp2_ = date;
		ft_stats_view_model_select (_tmp1_, &_tmp2_, FT_TIMEFRAME_DAY);
	}
}

static void
_ft_stats_view_activate_previous_g_simple_action_activate (GSimpleAction* _sender,
                                                           GVariant* parameter,
                                                           gpointer self)
{
	ft_stats_view_activate_previous ((FtStatsView*) self, _sender, parameter);
}

static void
_ft_stats_view_activate_next_g_simple_action_activate (GSimpleAction* _sender,
                                                       GVariant* parameter,
                                                       gpointer self)
{
	ft_stats_view_activate_next ((FtStatsView*) self, _sender, parameter);
}

static void
_ft_stats_view_activate_today_g_simple_action_activate (GSimpleAction* _sender,
                                                        GVariant* parameter,
                                                        gpointer self)
{
	ft_stats_view_activate_today ((FtStatsView*) self, _sender, parameter);
}

static void
_ft_stats_view_activate_up_g_simple_action_activate (GSimpleAction* _sender,
                                                     GVariant* parameter,
                                                     gpointer self)
{
	ft_stats_view_activate_up ((FtStatsView*) self);
}

static void
_ft_stats_view_activate_timeframe_g_simple_action_activate (GSimpleAction* _sender,
                                                            GVariant* parameter,
                                                            gpointer self)
{
	ft_stats_view_activate_timeframe ((FtStatsView*) self, _sender, parameter);
}

static void
_ft_stats_view_activate_set_timeframe_g_simple_action_activate (GSimpleAction* _sender,
                                                                GVariant* parameter,
                                                                gpointer self)
{
	ft_stats_view_activate_set_timeframe ((FtStatsView*) self, _sender, parameter);
}

static void
_ft_stats_view_activate_select_day_action_g_simple_action_activate (GSimpleAction* _sender,
                                                                    GVariant* parameter,
                                                                    gpointer self)
{
	ft_stats_view_activate_select_day_action ((FtStatsView*) self, _sender, parameter);
}

static void
ft_stats_view_initialize_action_group (FtStatsView* self)
{
	GSimpleAction* previous_action = NULL;
	GSimpleAction* _tmp0_;
	GSimpleAction* next_action = NULL;
	GSimpleAction* _tmp1_;
	GSimpleAction* today_action = NULL;
	GSimpleAction* _tmp2_;
	GSimpleAction* up_action = NULL;
	GSimpleAction* _tmp3_;
	GtkButton* _tmp4_;
	GSimpleAction* timeframe_action = NULL;
	const GVariantType* _tmp5_;
	FtStatsViewModel* _tmp6_;
	FtTimeframe _tmp7_;
	FtTimeframe _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	GVariant* _tmp11_;
	GVariant* _tmp12_;
	GSimpleAction* _tmp13_;
	GSimpleAction* _tmp14_;
	GSimpleAction* set_timeframe_action = NULL;
	const GVariantType* _tmp15_;
	GSimpleAction* _tmp16_;
	GSimpleAction* select_day_action = NULL;
	const GVariantType* _tmp17_;
	GSimpleAction* _tmp18_;
	GSimpleActionGroup* action_group = NULL;
	GSimpleActionGroup* _tmp19_;
	GSimpleAction* _tmp20_;
	GSimpleAction* _tmp21_;
	GSimpleAction* _tmp22_;
	GSimpleAction* _tmp23_;
	GSimpleAction* _tmp24_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_simple_action_new ("previous", NULL);
	previous_action = _tmp0_;
	g_signal_connect_object (previous_action, "activate", (GCallback) _ft_stats_view_activate_previous_g_simple_action_activate, self, 0);
	_tmp1_ = g_simple_action_new ("next", NULL);
	next_action = _tmp1_;
	g_signal_connect_object (next_action, "activate", (GCallback) _ft_stats_view_activate_next_g_simple_action_activate, self, 0);
	_tmp2_ = g_simple_action_new ("today", NULL);
	today_action = _tmp2_;
	g_signal_connect_object (today_action, "activate", (GCallback) _ft_stats_view_activate_today_g_simple_action_activate, self, 0);
	_tmp3_ = g_simple_action_new ("up", NULL);
	up_action = _tmp3_;
	_tmp4_ = self->priv->up_button;
	g_object_bind_property_with_closures ((GObject*) up_action, "enabled", (GObject*) _tmp4_, "visible", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	g_signal_connect_object (up_action, "activate", (GCallback) _ft_stats_view_activate_up_g_simple_action_activate, self, 0);
	_tmp5_ = G_VARIANT_TYPE_STRING;
	_tmp6_ = self->priv->model;
	_tmp7_ = ft_stats_view_model_get_timeframe (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = ft_timeframe_to_string (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_variant_new_string (_tmp10_);
	g_variant_ref_sink (_tmp11_);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_simple_action_new_stateful ("timeframe", _tmp5_, _tmp12_);
	_tmp14_ = _tmp13_;
	_g_variant_unref0 (_tmp12_);
	_g_free0 (_tmp10_);
	timeframe_action = _tmp14_;
	g_signal_connect_object (timeframe_action, "activate", (GCallback) _ft_stats_view_activate_timeframe_g_simple_action_activate, self, 0);
	_tmp15_ = G_VARIANT_TYPE_STRING;
	_tmp16_ = g_simple_action_new ("set-timeframe", _tmp15_);
	set_timeframe_action = _tmp16_;
	g_signal_connect_object (set_timeframe_action, "activate", (GCallback) _ft_stats_view_activate_set_timeframe_g_simple_action_activate, self, 0);
	_tmp17_ = G_VARIANT_TYPE_TUPLE;
	_tmp18_ = g_simple_action_new ("select-day", _tmp17_);
	select_day_action = _tmp18_;
	g_signal_connect_object (select_day_action, "activate", (GCallback) _ft_stats_view_activate_select_day_action_g_simple_action_activate, self, 0);
	_tmp19_ = g_simple_action_group_new ();
	action_group = _tmp19_;
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) previous_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) next_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) today_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) up_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) timeframe_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) set_timeframe_action);
	g_action_map_add_action ((GActionMap*) action_group, (GAction*) select_day_action);
	_tmp20_ = _g_object_ref0 (previous_action);
	_g_object_unref0 (self->priv->previous_action);
	self->priv->previous_action = _tmp20_;
	_tmp21_ = _g_object_ref0 (next_action);
	_g_object_unref0 (self->priv->next_action);
	self->priv->next_action = _tmp21_;
	_tmp22_ = _g_object_ref0 (today_action);
	_g_object_unref0 (self->priv->today_action);
	self->priv->today_action = _tmp22_;
	_tmp23_ = _g_object_ref0 (up_action);
	_g_object_unref0 (self->priv->up_action);
	self->priv->up_action = _tmp23_;
	_tmp24_ = _g_object_ref0 (timeframe_action);
	_g_object_unref0 (self->priv->timeframe_action);
	self->priv->timeframe_action = _tmp24_;
	gtk_widget_insert_action_group ((GtkWidget*) self, "stats", (GActionGroup*) action_group);
	_g_object_unref0 (action_group);
	_g_object_unref0 (select_day_action);
	_g_object_unref0 (set_timeframe_action);
	_g_object_unref0 (timeframe_action);
	_g_object_unref0 (up_action);
	_g_object_unref0 (today_action);
	_g_object_unref0 (next_action);
	_g_object_unref0 (previous_action);
}

static gboolean
ft_stats_view_is_user_idle (FtStatsView* self)
{
	gint64 now = 0LL;
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	now = ft_timestamp_from_now ();
	if (ft_timestamp_is_defined (self->priv->last_user_active_time)) {
		_tmp0_ = (now - self->priv->last_user_active_time) > FT_INTERVAL_HOUR;
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

static void
ft_stats_view_mark_user_active (FtStatsView* self)
{
	g_return_if_fail (self != NULL);
	self->priv->last_user_active_time = ft_timestamp_from_now ();
}

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_view_update_title (FtStatsView* self)
{
	gchar* title = NULL;
	gchar* subtitle = NULL;
	FtTimeframe timeframe = 0;
	FtStatsViewModel* _tmp0_;
	FtTimeframe _tmp1_;
	FtTimeframe _tmp2_;
	GDate date = {0};
	FtStatsViewModel* _tmp3_;
	GDate _tmp4_ = {0};
	GDate _tmp5_;
	GDate today = {0};
	FtStatsViewModel* _tmp6_;
	GDate _tmp7_ = {0};
	GDate _tmp8_;
	GDate _tmp9_ = {0};
	GtkLabel* _tmp101_;
	const gchar* _tmp102_;
	GtkLabel* _tmp103_;
	const gchar* _tmp104_;
	GtkLabel* _tmp105_;
	const gchar* _tmp106_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = ft_stats_view_model_get_timeframe (_tmp0_);
	_tmp2_ = _tmp1_;
	timeframe = _tmp2_;
	_tmp3_ = self->priv->model;
	ft_stats_view_model_get_date (_tmp3_, &_tmp4_);
	_tmp5_ = _tmp4_;
	date = _tmp5_;
	_tmp6_ = self->priv->model;
	ft_stats_view_model_get_max_date (_tmp6_, &_tmp7_);
	_tmp8_ = _tmp7_;
	ft_timeframe_normalize_date (timeframe, &_tmp8_, &_tmp9_);
	today = _tmp9_;
	switch (timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			GDate _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			GDate _tmp14_;
			_tmp10_ = date;
			_tmp11_ = ft_date_utils_format_date (&_tmp10_, "%A");
			_tmp12_ = _tmp11_;
			_tmp13_ = ft_capitalize_words (_tmp12_);
			_g_free0 (subtitle);
			subtitle = _tmp13_;
			_g_free0 (_tmp12_);
			_tmp14_ = today;
			if (g_date_compare (&date, &_tmp14_) == 0) {
				gchar* _tmp15_;
				const gchar* _tmp16_;
				GDate _tmp17_;
				gchar* _tmp18_;
				gchar* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				_tmp15_ = g_strdup (_ ("Today"));
				_g_free0 (title);
				title = _tmp15_;
				_tmp16_ = subtitle;
				_tmp17_ = date;
				_tmp18_ = ft_date_utils_format_date (&_tmp17_, ", %e %B");
				_tmp19_ = _tmp18_;
				_tmp20_ = string_replace (_tmp19_, " ", "");
				_tmp21_ = _tmp20_;
				_tmp22_ = ft_capitalize_words (_tmp21_);
				_tmp23_ = _tmp22_;
				_tmp24_ = g_strconcat (_tmp16_, _tmp23_, NULL);
				_g_free0 (subtitle);
				subtitle = _tmp24_;
				_g_free0 (_tmp23_);
				_g_free0 (_tmp21_);
				_g_free0 (_tmp19_);
			} else {
				GDate _tmp25_;
				_tmp25_ = today;
				if (g_date_days_between (&date, &_tmp25_) == 1) {
					gchar* _tmp26_;
					const gchar* _tmp27_;
					GDate _tmp28_;
					gchar* _tmp29_;
					gchar* _tmp30_;
					gchar* _tmp31_;
					gchar* _tmp32_;
					gchar* _tmp33_;
					gchar* _tmp34_;
					gchar* _tmp35_;
					_tmp26_ = g_strdup (_ ("Yesterday"));
					_g_free0 (title);
					title = _tmp26_;
					_tmp27_ = subtitle;
					_tmp28_ = date;
					_tmp29_ = ft_date_utils_format_date (&_tmp28_, ", %e %B");
					_tmp30_ = _tmp29_;
					_tmp31_ = string_replace (_tmp30_, " ", "");
					_tmp32_ = _tmp31_;
					_tmp33_ = ft_capitalize_words (_tmp32_);
					_tmp34_ = _tmp33_;
					_tmp35_ = g_strconcat (_tmp27_, _tmp34_, NULL);
					_g_free0 (subtitle);
					subtitle = _tmp35_;
					_g_free0 (_tmp34_);
					_g_free0 (_tmp32_);
					_g_free0 (_tmp30_);
				} else {
					if (g_date_get_year (&date) == g_date_get_year (&today)) {
						GDate _tmp36_;
						gchar* _tmp37_;
						gchar* _tmp38_;
						gchar* _tmp39_;
						gchar* _tmp40_;
						gchar* _tmp41_;
						_tmp36_ = date;
						_tmp37_ = ft_date_utils_format_date (&_tmp36_, "%e %B");
						_tmp38_ = _tmp37_;
						_tmp39_ = string_replace (_tmp38_, " ", "");
						_tmp40_ = _tmp39_;
						_tmp41_ = ft_capitalize_words (_tmp40_);
						_g_free0 (title);
						title = _tmp41_;
						_g_free0 (_tmp40_);
						_g_free0 (_tmp38_);
					} else {
						GDate _tmp42_;
						gchar* _tmp43_;
						gchar* _tmp44_;
						gchar* _tmp45_;
						gchar* _tmp46_;
						gchar* _tmp47_;
						_tmp42_ = date;
						_tmp43_ = ft_date_utils_format_date (&_tmp42_, "%e %B %Y");
						_tmp44_ = _tmp43_;
						_tmp45_ = string_replace (_tmp44_, " ", "");
						_tmp46_ = _tmp45_;
						_tmp47_ = ft_capitalize_words (_tmp46_);
						_g_free0 (title);
						title = _tmp47_;
						_g_free0 (_tmp46_);
						_g_free0 (_tmp44_);
					}
				}
			}
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			GDate* week_start_date = NULL;
			GDate* _tmp48_;
			GDate* week_end_date = NULL;
			GDate* _tmp49_;
			GDate* _tmp50_;
			GDate* _tmp51_;
			GDate* _tmp52_;
			GDate _tmp53_;
			gchar* week_start_format = NULL;
			gchar* _tmp66_;
			gchar* week_end_format = NULL;
			gchar* _tmp67_;
			GDate* _tmp68_;
			GDate* _tmp69_;
			GDate* _tmp72_;
			GDate* _tmp75_;
			const gchar* _tmp76_;
			GDate _tmp77_;
			gchar* _tmp78_;
			gchar* _tmp79_;
			gchar* _tmp80_;
			gchar* _tmp81_;
			GDate* _tmp82_;
			const gchar* _tmp83_;
			GDate _tmp84_;
			gchar* _tmp85_;
			gchar* _tmp86_;
			gchar* _tmp87_;
			gchar* _tmp88_;
			gchar* _tmp89_;
			gchar* _tmp90_;
			gchar* _tmp91_;
			_tmp48_ = g_date_copy (&date);
			week_start_date = _tmp48_;
			_tmp49_ = week_start_date;
			_tmp50_ = g_date_copy (_tmp49_);
			week_end_date = _tmp50_;
			_tmp51_ = week_end_date;
			g_date_add_days (_tmp51_, 6U);
			_tmp52_ = week_start_date;
			_tmp53_ = today;
			if (g_date_compare (_tmp52_, &_tmp53_) == 0) {
				gchar* _tmp54_;
				_tmp54_ = g_strdup (_ ("This week"));
				_g_free0 (title);
				title = _tmp54_;
			} else {
				GDateWeekday first_day_of_week = 0;
				GDate first_week_date = {0};
				GDate* _tmp55_;
				guint _tmp56_ = 0U;
				guint week_number_offset = 0U;
				guint _tmp57_ = 0U;
				guint week_number = 0U;
				guint year = 0U;
				GDate* _tmp60_;
				gchar* _tmp61_ = NULL;
				GDate* _tmp62_;
				gchar* _tmp65_;
				first_day_of_week = ft_locale_get_first_day_of_week ();
				memset (&first_week_date, 0, sizeof (GDate));
				_tmp55_ = week_end_date;
				g_date_set_dmy (&first_week_date, (GDateDay) 1, 1, g_date_get_year (_tmp55_));
				if (first_day_of_week == G_DATE_MONDAY) {
					_tmp56_ = g_date_get_monday_week_of_year (&first_week_date);
				} else {
					_tmp56_ = g_date_get_sunday_week_of_year (&first_week_date);
				}
				week_number_offset = 1U - _tmp56_;
				if (first_day_of_week == G_DATE_MONDAY) {
					GDate* _tmp58_;
					_tmp58_ = week_end_date;
					_tmp57_ = g_date_get_monday_week_of_year (_tmp58_);
				} else {
					GDate* _tmp59_;
					_tmp59_ = week_end_date;
					_tmp57_ = g_date_get_sunday_week_of_year (_tmp59_);
				}
				week_number = week_number_offset + _tmp57_;
				_tmp60_ = week_end_date;
				year = (guint) g_date_get_year (_tmp60_);
				_tmp62_ = week_end_date;
				if (g_date_get_year (_tmp62_) == g_date_get_year (&today)) {
					gchar* _tmp63_;
					_tmp63_ = g_strdup_printf (_ ("Week %u"), week_number);
					_g_free0 (_tmp61_);
					_tmp61_ = _tmp63_;
				} else {
					gchar* _tmp64_;
					_tmp64_ = g_strdup_printf (_ ("Week %u of %u"), week_number, year);
					_g_free0 (_tmp61_);
					_tmp61_ = _tmp64_;
				}
				_tmp65_ = _tmp61_;
				_tmp61_ = NULL;
				_g_free0 (title);
				title = _tmp65_;
				_g_free0 (_tmp61_);
			}
			_tmp66_ = g_strdup ("%e");
			week_start_format = _tmp66_;
			_tmp67_ = g_strdup ("%e %B");
			week_end_format = _tmp67_;
			_tmp68_ = week_start_date;
			_tmp69_ = week_end_date;
			if (g_date_get_month (_tmp68_) != g_date_get_month (_tmp69_)) {
				const gchar* _tmp70_;
				gchar* _tmp71_;
				_tmp70_ = week_start_format;
				_tmp71_ = g_strconcat (_tmp70_, " %B", NULL);
				_g_free0 (week_start_format);
				week_start_format = _tmp71_;
			}
			_tmp72_ = week_end_date;
			if (g_date_get_year (_tmp72_) != g_date_get_year (&today)) {
				const gchar* _tmp73_;
				gchar* _tmp74_;
				_tmp73_ = week_end_format;
				_tmp74_ = g_strconcat (_tmp73_, " %Y", NULL);
				_g_free0 (week_end_format);
				week_end_format = _tmp74_;
			}
			_tmp75_ = week_start_date;
			_tmp76_ = week_start_format;
			_tmp77_ = *_tmp75_;
			_tmp78_ = ft_date_utils_format_date (&_tmp77_, _tmp76_);
			_tmp79_ = _tmp78_;
			_tmp80_ = string_replace (_tmp79_, " ", "");
			_tmp81_ = _tmp80_;
			_tmp82_ = week_end_date;
			_tmp83_ = week_end_format;
			_tmp84_ = *_tmp82_;
			_tmp85_ = ft_date_utils_format_date (&_tmp84_, _tmp83_);
			_tmp86_ = _tmp85_;
			_tmp87_ = string_replace (_tmp86_, " ", "");
			_tmp88_ = _tmp87_;
			_tmp89_ = g_strdup_printf ("%s – %s", _tmp81_, _tmp88_);
			_tmp90_ = _tmp89_;
			_tmp91_ = ft_capitalize_words (_tmp90_);
			_g_free0 (subtitle);
			subtitle = _tmp91_;
			_g_free0 (_tmp90_);
			_g_free0 (_tmp88_);
			_g_free0 (_tmp86_);
			_g_free0 (_tmp81_);
			_g_free0 (_tmp79_);
			_g_free0 (week_end_format);
			_g_free0 (week_start_format);
			_g_free0 (week_end_date);
			_g_free0 (week_start_date);
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gchar* _tmp92_;
			gchar* _tmp93_;
			gchar* _tmp94_;
			gchar* _tmp100_;
			_tmp92_ = ft_date_utils_get_month_name (g_date_get_month (&date));
			_tmp93_ = _tmp92_;
			_tmp94_ = ft_capitalize_words (_tmp93_);
			_g_free0 (title);
			title = _tmp94_;
			_g_free0 (_tmp93_);
			if (g_date_get_year (&date) != g_date_get_year (&today)) {
				const gchar* _tmp95_;
				GDate _tmp96_;
				gchar* _tmp97_;
				gchar* _tmp98_;
				gchar* _tmp99_;
				_tmp95_ = title;
				_tmp96_ = date;
				_tmp97_ = ft_date_utils_format_date (&_tmp96_, " %Y");
				_tmp98_ = _tmp97_;
				_tmp99_ = g_strconcat (_tmp95_, _tmp98_, NULL);
				_g_free0 (title);
				title = _tmp99_;
				_g_free0 (_tmp98_);
			}
			_tmp100_ = g_strdup ("");
			_g_free0 (subtitle);
			subtitle = _tmp100_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp101_ = self->priv->title_label;
	_tmp102_ = title;
	gtk_label_set_label (_tmp101_, _tmp102_);
	_tmp103_ = self->priv->subtitle_label;
	_tmp104_ = subtitle;
	gtk_label_set_label (_tmp103_, _tmp104_);
	_tmp105_ = self->priv->subtitle_label;
	_tmp106_ = subtitle;
	gtk_widget_set_visible ((GtkWidget*) _tmp105_, g_strcmp0 (_tmp106_, "") != 0);
	_g_free0 (subtitle);
	_g_free0 (title);
}

static void
ft_stats_view_update_actions (FtStatsView* self)
{
	FtTimeframe timeframe = 0;
	FtStatsViewModel* _tmp0_;
	FtTimeframe _tmp1_;
	FtTimeframe _tmp2_;
	GDate date = {0};
	FtStatsViewModel* _tmp3_;
	GDate _tmp4_ = {0};
	GDate _tmp5_;
	GDate min_date = {0};
	FtStatsViewModel* _tmp6_;
	GDate _tmp7_ = {0};
	GDate _tmp8_;
	GDate _tmp9_ = {0};
	GDate max_date = {0};
	FtStatsViewModel* _tmp10_;
	GDate _tmp11_ = {0};
	GDate _tmp12_;
	GDate _tmp13_ = {0};
	gboolean _tmp14_ = FALSE;
	GSimpleAction* _tmp16_;
	gboolean _tmp17_ = FALSE;
	GSimpleAction* _tmp19_;
	GSimpleAction* _tmp20_;
	GSimpleAction* _tmp21_;
	GSimpleAction* _tmp22_;
	GSimpleAction* _tmp23_;
	gchar* _tmp24_;
	gchar* _tmp25_;
	GVariant* _tmp26_;
	GVariant* _tmp27_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = ft_stats_view_model_get_timeframe (_tmp0_);
	_tmp2_ = _tmp1_;
	timeframe = _tmp2_;
	_tmp3_ = self->priv->model;
	ft_stats_view_model_get_date (_tmp3_, &_tmp4_);
	_tmp5_ = _tmp4_;
	date = _tmp5_;
	_tmp6_ = self->priv->model;
	ft_stats_view_model_get_min_date (_tmp6_, &_tmp7_);
	_tmp8_ = _tmp7_;
	ft_timeframe_normalize_date (timeframe, &_tmp8_, &_tmp9_);
	min_date = _tmp9_;
	_tmp10_ = self->priv->model;
	ft_stats_view_model_get_max_date (_tmp10_, &_tmp11_);
	_tmp12_ = _tmp11_;
	ft_timeframe_normalize_date (timeframe, &_tmp12_, &_tmp13_);
	max_date = _tmp13_;
	if (g_date_valid (&min_date)) {
		GDate _tmp15_;
		_tmp15_ = min_date;
		_tmp14_ = g_date_compare (&date, &_tmp15_) > 0;
	} else {
		_tmp14_ = FALSE;
	}
	_tmp16_ = self->priv->previous_action;
	g_simple_action_set_enabled (_tmp16_, _tmp14_);
	if (g_date_valid (&max_date)) {
		GDate _tmp18_;
		_tmp18_ = max_date;
		_tmp17_ = g_date_compare (&date, &_tmp18_) < 0;
	} else {
		_tmp17_ = FALSE;
	}
	_tmp19_ = self->priv->next_action;
	g_simple_action_set_enabled (_tmp19_, _tmp17_);
	_tmp20_ = self->priv->today_action;
	_tmp21_ = self->priv->next_action;
	g_simple_action_set_enabled (_tmp20_, g_action_get_enabled ((GAction*) _tmp21_));
	_tmp22_ = self->priv->up_action;
	g_simple_action_set_enabled (_tmp22_, timeframe != FT_TIMEFRAME_MONTH);
	_tmp23_ = self->priv->timeframe_action;
	_tmp24_ = ft_timeframe_to_string (timeframe);
	_tmp25_ = _tmp24_;
	_tmp26_ = g_variant_new_string (_tmp25_);
	g_variant_ref_sink (_tmp26_);
	_tmp27_ = _tmp26_;
	g_simple_action_set_state (_tmp23_, _tmp27_);
	_g_variant_unref0 (_tmp27_);
	_g_free0 (_tmp25_);
}

static gboolean
__lambda55_ (FtStatsView* self)
{
	FtStatsViewModel* _tmp0_;
	gboolean result;
	self->priv->timeout_id = (guint) 0;
	_tmp0_ = self->priv->model;
	ft_stats_view_model_update_date_range (_tmp0_);
	ft_stats_view_schedule_navigate_to_today (self);
	if (ft_stats_view_is_user_idle (self)) {
		ft_stats_view_navigate_to_today (self);
	}
	result = G_SOURCE_REMOVE;
	return result;
}

static gboolean
___lambda55__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda55_ ((FtStatsView*) self);
	return result;
}

static void
ft_stats_view_schedule_navigate_to_today (FtStatsView* self)
{
	GDateTime* now = NULL;
	GDateTime* _tmp0_;
	gint seconds = 0;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	g_return_if_fail (self != NULL);
	if (self->priv->timeout_id != ((guint) 0)) {
		return;
	}
	_tmp0_ = g_date_time_new_now_local ();
	now = _tmp0_;
	_tmp1_ = now;
	_tmp2_ = now;
	seconds = 3600 - ((g_date_time_get_minute (_tmp1_) * 60) + g_date_time_get_second (_tmp2_));
	self->priv->timeout_id = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) (seconds + 1), ___lambda55__gsource_func, g_object_ref (self), g_object_unref);
	g_source_set_name_by_id (self->priv->timeout_id, "Ft.StatsView.navigate_to_today");
	_g_date_time_unref0 (now);
}

static void
ft_stats_view_update_placeholder (FtStatsView* self)
{
	FtStatsViewModel* _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->model;
	ft_stats_view_model_get_min_date (_tmp0_, &_tmp1_);
	_tmp2_ = _tmp1_;
	if (g_date_valid (&_tmp2_)) {
		GtkStack* _tmp3_;
		_tmp3_ = self->priv->stack;
		gtk_stack_set_visible_child_full (_tmp3_, "content", GTK_STACK_TRANSITION_TYPE_NONE);
		ft_stats_view_update_page (self, GTK_STACK_TRANSITION_TYPE_NONE);
	} else {
		GtkStack* _tmp4_;
		_tmp4_ = self->priv->stack;
		gtk_stack_set_visible_child_full (_tmp4_, "placeholder", GTK_STACK_TRANSITION_TYPE_NONE);
		ft_stats_view_clear_pages (self);
	}
}

static void
ft_stats_view_on_timeframe_selected (FtStatsView* self,
                                     FtStatsDatePopover* date_popover,
                                     FtTimeframe timeframe)
{
	FtStatsViewModel* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date_popover != NULL);
	_tmp0_ = self->priv->model;
	ft_stats_view_model_select_timeframe (_tmp0_, timeframe);
	g_signal_stop_emission_by_name (date_popover, "timeframe-selected");
}

static void
_ft_stats_view_on_timeframe_selected_ft_stats_date_popover_timeframe_selected (FtStatsDatePopover* _sender,
                                                                               FtTimeframe timeframe,
                                                                               gpointer self)
{
	ft_stats_view_on_timeframe_selected ((FtStatsView*) self, _sender, timeframe);
}

static void
ft_stats_view_on_date_selected (FtStatsView* self,
                                FtStatsDatePopover* date_popover,
                                GDate* date)
{
	FtStatsViewModel* _tmp0_;
	GDate _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date_popover != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = self->priv->model;
	_tmp1_ = *date;
	ft_stats_view_model_select_date (_tmp0_, &_tmp1_);
	g_signal_stop_emission_by_name (date_popover, "date-selected");
}

static void
_ft_stats_view_on_date_selected_ft_stats_date_popover_date_selected (FtStatsDatePopover* _sender,
                                                                     GDate* date,
                                                                     gpointer self)
{
	ft_stats_view_on_date_selected ((FtStatsView*) self, _sender, date);
}

static void
ft_stats_view_real_map (GtkWidget* base)
{
	FtStatsView * self;
	FtStatsViewModel* _tmp0_;
	FtStatsViewModel* _tmp1_;
	GDate _tmp2_ = {0};
	GDate _tmp3_;
	self = (FtStatsView*) base;
	_tmp0_ = self->priv->model;
	ft_stats_view_model_update_date_range (_tmp0_);
	GTK_WIDGET_CLASS (ft_stats_view_parent_class)->map ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_breakpoint_bin_get_type (), AdwBreakpointBin));
	_tmp1_ = self->priv->model;
	ft_stats_view_model_get_min_date (_tmp1_, &_tmp2_);
	_tmp3_ = _tmp2_;
	if (g_date_valid (&_tmp3_)) {
		ft_stats_view_update_placeholder (self);
		if (ft_stats_view_is_user_idle (self)) {
			ft_stats_view_navigate_to_today (self);
		} else {
			ft_stats_view_mark_user_active (self);
		}
	}
	ft_stats_view_schedule_navigate_to_today (self);
}

static void
ft_stats_view_real_unmap (GtkWidget* base)
{
	FtStatsView * self;
	self = (FtStatsView*) base;
	GTK_WIDGET_CLASS (ft_stats_view_parent_class)->unmap ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_breakpoint_bin_get_type (), AdwBreakpointBin));
	if (self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
}

static void
ft_stats_view_real_dispose (GObject* base)
{
	FtStatsView * self;
	self = (FtStatsView*) base;
	if (self->priv->update_page_idle_id != ((guint) 0)) {
		gtk_widget_remove_tick_callback ((GtkWidget*) self, self->priv->update_page_idle_id);
		self->priv->update_page_idle_id = (guint) 0;
	}
	if (self->priv->timeout_id != ((guint) 0)) {
		g_source_remove (self->priv->timeout_id);
		self->priv->timeout_id = (guint) 0;
	}
	ft_stats_view_clear_pages (self);
	_g_object_unref0 (self->priv->previous_action);
	self->priv->previous_action = NULL;
	_g_object_unref0 (self->priv->next_action);
	self->priv->next_action = NULL;
	_g_object_unref0 (self->priv->today_action);
	self->priv->today_action = NULL;
	_g_object_unref0 (self->priv->up_action);
	self->priv->up_action = NULL;
	_g_object_unref0 (self->priv->timeframe_action);
	self->priv->timeframe_action = NULL;
	(self->priv->pages_history == NULL) ? NULL : (self->priv->pages_history = (g_queue_free (self->priv->pages_history), NULL));
	self->priv->pages_history = NULL;
	_g_object_unref0 (self->priv->navigation_cancellable);
	self->priv->navigation_cancellable = NULL;
	_g_object_unref0 (self->priv->last_toast);
	self->priv->last_toast = NULL;
	G_OBJECT_CLASS (ft_stats_view_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_breakpoint_bin_get_type (), AdwBreakpointBin));
}

FtStatsView*
ft_stats_view_construct (GType object_type)
{
	FtStatsView * self = NULL;
	self = (FtStatsView*) g_object_new (object_type, NULL);
	return self;
}

FtStatsView*
ft_stats_view_new (void)
{
	return ft_stats_view_construct (FT_TYPE_STATS_VIEW);
}

gint64
ft_stats_view_get_daily_interval (FtStatsView* self)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = self->priv->_daily_interval;
	return result;
}

void
ft_stats_view_set_daily_interval (FtStatsView* self,
                                  gint64 value)
{
	gint64 old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_stats_view_get_daily_interval (self);
	if (old_value != value) {
		self->priv->_daily_interval = value;
		g_object_notify_by_pspec ((GObject *) self, ft_stats_view_properties[FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY]);
	}
}

static void
_ft_stats_view___lambda56_ (FtStatsView* self,
                            GParamSpec* pspec)
{
	g_return_if_fail (pspec != NULL);
	ft_stats_view_queue_update_page (self);
}

static void
__ft_stats_view___lambda56__g_object_notify (GObject* _sender,
                                             GParamSpec* pspec,
                                             gpointer self)
{
	_ft_stats_view___lambda56_ ((FtStatsView*) self, pspec);
}

static void
_ft_stats_view___lambda57_ (FtStatsView* self,
                            GParamSpec* pspec)
{
	g_return_if_fail (pspec != NULL);
	ft_stats_view_queue_update_page (self);
}

static void
__ft_stats_view___lambda57__g_object_notify (GObject* _sender,
                                             GParamSpec* pspec,
                                             gpointer self)
{
	_ft_stats_view___lambda57_ ((FtStatsView*) self, pspec);
}

static void
_ft_stats_view___lambda58_ (FtStatsView* self,
                            GParamSpec* pspec)
{
	GtkStack* _tmp0_;
	g_return_if_fail (pspec != NULL);
	ft_stats_view_update_actions (self);
	ft_stats_view_update_placeholder (self);
	_tmp0_ = self->priv->stack;
	gtk_widget_set_visible ((GtkWidget*) _tmp0_, TRUE);
}

static void
__ft_stats_view___lambda58__g_object_notify (GObject* _sender,
                                             GParamSpec* pspec,
                                             gpointer self)
{
	_ft_stats_view___lambda58_ ((FtStatsView*) self, pspec);
}

static void
_ft_stats_view___lambda59_ (FtStatsView* self,
                            GParamSpec* pspec)
{
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (pspec != NULL);
	ft_stats_view_update_actions (self);
	ft_stats_view_update_title (self);
	if (gtk_widget_get_mapped ((GtkWidget*) self)) {
		_tmp0_ = ft_stats_view_is_user_idle (self);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ft_stats_view_navigate_to_today (self);
	}
}

static void
__ft_stats_view___lambda59__g_object_notify (GObject* _sender,
                                             GParamSpec* pspec,
                                             gpointer self)
{
	_ft_stats_view___lambda59_ ((FtStatsView*) self, pspec);
}

static void
_ft_stats_view___lambda60_ (FtStatsView* self,
                            FtNavigationDirection direction,
                            GDate* date,
                            guint skipped)
{
	FtStatsPage* last_page = NULL;
	GQueue* _tmp0_;
	gconstpointer _tmp1_;
	FtStatsPage* _tmp2_;
	GtkStackTransitionType _tmp3_ = 0;
	GtkStackTransitionType transition_type = 0;
	gboolean _tmp4_ = FALSE;
	FtStatsPage* _tmp5_;
	g_return_if_fail (date != NULL);
	_tmp0_ = self->priv->pages_history;
	_tmp1_ = g_queue_peek_nth (_tmp0_, 1U);
	_tmp2_ = _g_object_ref0 ((FtStatsPage*) _tmp1_);
	last_page = _tmp2_;
	if (direction == FT_NAVIGATION_DIRECTION_FORWARD) {
		_tmp3_ = GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT;
	} else {
		_tmp3_ = GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT;
	}
	transition_type = _tmp3_;
	_tmp5_ = last_page;
	if (_tmp5_ == NULL) {
		_tmp4_ = TRUE;
	} else {
		FtStatsPage* _tmp6_;
		GDate _tmp7_ = {0};
		GDate _tmp8_;
		GDate _tmp9_;
		_tmp6_ = last_page;
		ft_stats_page_get_date (_tmp6_, &_tmp7_);
		_tmp8_ = _tmp7_;
		_tmp9_ = *date;
		_tmp4_ = g_date_compare (&_tmp8_, &_tmp9_) != 0;
	}
	if (_tmp4_) {
		AdwToast* _tmp10_;
		_tmp10_ = self->priv->last_toast;
		if (_tmp10_ != NULL) {
			AdwToast* _tmp11_;
			_tmp11_ = self->priv->last_toast;
			adw_toast_dismiss (_tmp11_);
		}
		if (skipped > 0U) {
			ft_stats_view_notify_skipped_pages (self, skipped);
		}
	}
	if (self->priv->update_page_idle_id != ((guint) 0)) {
		gtk_widget_remove_tick_callback ((GtkWidget*) self, self->priv->update_page_idle_id);
		self->priv->update_page_idle_id = (guint) 0;
	}
	ft_stats_view_update_page (self, transition_type);
	_g_object_unref0 (last_page);
}

static void
__ft_stats_view___lambda60__ft_stats_view_model_navigated (FtStatsViewModel* _sender,
                                                           FtNavigationDirection direction,
                                                           GDate* date,
                                                           guint skipped,
                                                           gpointer self)
{
	_ft_stats_view___lambda60_ ((FtStatsView*) self, direction, date, skipped);
}

static GObject *
ft_stats_view_constructor (GType type,
                           guint n_construct_properties,
                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtStatsView * self;
	FtStatsViewModel* _tmp0_;
	GQueue* _tmp1_;
	FtStatsViewModel* _tmp2_;
	FtStatsDatePopover* _tmp3_;
	FtStatsViewModel* _tmp4_;
	FtStatsDatePopover* _tmp5_;
	FtStatsViewModel* _tmp6_;
	FtStatsDatePopover* _tmp7_;
	FtStatsViewModel* _tmp8_;
	FtStatsDatePopover* _tmp9_;
	GtkStack* _tmp10_;
	FtStatsViewModel* _tmp11_;
	FtStatsViewModel* _tmp12_;
	FtStatsViewModel* _tmp13_;
	FtStatsViewModel* _tmp14_;
	FtStatsViewModel* _tmp15_;
	parent_class = G_OBJECT_CLASS (ft_stats_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_VIEW, FtStatsView);
	_tmp0_ = ft_stats_view_model_new ();
	_g_object_unref0 (self->priv->model);
	self->priv->model = _tmp0_;
	_tmp1_ = g_queue_new ();
	(self->priv->pages_history == NULL) ? NULL : (self->priv->pages_history = (g_queue_free (self->priv->pages_history), NULL));
	self->priv->pages_history = _tmp1_;
	ft_stats_view_initialize_action_group (self);
	_tmp2_ = self->priv->model;
	_tmp3_ = self->priv->date_popover;
	g_object_bind_property_with_closures ((GObject*) _tmp2_, "timeframe", (GObject*) _tmp3_, "timeframe", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp4_ = self->priv->model;
	_tmp5_ = self->priv->date_popover;
	g_object_bind_property_with_closures ((GObject*) _tmp4_, "date", (GObject*) _tmp5_, "date", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp6_ = self->priv->model;
	_tmp7_ = self->priv->date_popover;
	g_object_bind_property_with_closures ((GObject*) _tmp6_, "min-date", (GObject*) _tmp7_, "min-date", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp8_ = self->priv->model;
	_tmp9_ = self->priv->date_popover;
	g_object_bind_property_with_closures ((GObject*) _tmp8_, "max-date", (GObject*) _tmp9_, "max-date", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp10_ = self->priv->stack;
	gtk_widget_set_visible ((GtkWidget*) _tmp10_, FALSE);
	_tmp11_ = self->priv->model;
	g_signal_connect_object ((GObject*) _tmp11_, "notify::timeframe", (GCallback) __ft_stats_view___lambda56__g_object_notify, self, 0);
	_tmp12_ = self->priv->model;
	g_signal_connect_object ((GObject*) _tmp12_, "notify::date", (GCallback) __ft_stats_view___lambda57__g_object_notify, self, 0);
	_tmp13_ = self->priv->model;
	g_signal_connect_object ((GObject*) _tmp13_, "notify::min-date", (GCallback) __ft_stats_view___lambda58__g_object_notify, self, 0);
	_tmp14_ = self->priv->model;
	g_signal_connect_object ((GObject*) _tmp14_, "notify::max-date", (GCallback) __ft_stats_view___lambda59__g_object_notify, self, 0);
	_tmp15_ = self->priv->model;
	g_signal_connect_object (_tmp15_, "navigated", (GCallback) __ft_stats_view___lambda60__ft_stats_view_model_navigated, self, 0);
	return obj;
}

static void
ft_stats_view_class_init (FtStatsViewClass * klass,
                          gpointer klass_data)
{
	ft_stats_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsView_private_offset);
	((GtkWidgetClass *) klass)->map = (void (*) (GtkWidget*)) ft_stats_view_real_map;
	((GtkWidgetClass *) klass)->unmap = (void (*) (GtkWidget*)) ft_stats_view_real_unmap;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_stats_view_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_view_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_view_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_stats_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_view_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY, ft_stats_view_properties[FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY] = g_param_spec_int64 ("daily-interval", "daily-interval", "daily-interval", G_MININT64, G_MAXINT64, FT_INTERVAL_HOUR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/stats-view.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "stack", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, stack));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "title_label", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, title_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "subtitle_label", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, subtitle_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "date_popover", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, date_popover));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "up_button", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, up_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "pages", FALSE, FtStatsView_private_offset + G_STRUCT_OFFSET (FtStatsViewPrivate, pages));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_timeframe_selected", G_CALLBACK(_ft_stats_view_on_timeframe_selected_ft_stats_date_popover_timeframe_selected));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_date_selected", G_CALLBACK(_ft_stats_view_on_date_selected_ft_stats_date_popover_date_selected));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "statsview");
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_Left, GDK_NO_MODIFIER_MASK, "stats.previous", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_Right, GDK_NO_MODIFIER_MASK, "stats.next", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_Page_Down, GDK_NO_MODIFIER_MASK, "stats.previous", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_Page_Up, GDK_NO_MODIFIER_MASK, "stats.next", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_Home, GDK_NO_MODIFIER_MASK, "stats.today", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_t, GDK_NO_MODIFIER_MASK, "stats.today", NULL, NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_d, GDK_NO_MODIFIER_MASK, "stats.set-timeframe", "s", "day", NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_w, GDK_NO_MODIFIER_MASK, "stats.set-timeframe", "s", "week", NULL);
	gtk_widget_class_add_binding_action (GTK_WIDGET_CLASS (klass), GDK_KEY_m, GDK_NO_MODIFIER_MASK, "stats.set-timeframe", "s", "month", NULL);
}

static void
ft_stats_view_instance_init (FtStatsView * self,
                             gpointer klass)
{
	self->priv = ft_stats_view_get_instance_private (self);
	self->priv->_daily_interval = FT_INTERVAL_HOUR;
	self->priv->model = NULL;
	self->priv->previous_action = NULL;
	self->priv->next_action = NULL;
	self->priv->today_action = NULL;
	self->priv->up_action = NULL;
	self->priv->timeframe_action = NULL;
	self->priv->pages_history = NULL;
	self->priv->navigation_cancellable = NULL;
	self->priv->last_toast = NULL;
	self->priv->last_user_active_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->update_page_idle_id = 0U;
	self->priv->timeout_id = 0U;
	g_type_ensure (FT_TYPE_STATS_DATE_POPOVER);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_stats_view_finalize (GObject * obj)
{
	FtStatsView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_VIEW, FtStatsView);
	_g_object_unref0 (self->priv->model);
	_g_object_unref0 (self->priv->previous_action);
	_g_object_unref0 (self->priv->next_action);
	_g_object_unref0 (self->priv->today_action);
	_g_object_unref0 (self->priv->up_action);
	_g_object_unref0 (self->priv->timeframe_action);
	(self->priv->pages_history == NULL) ? NULL : (self->priv->pages_history = (g_queue_free (self->priv->pages_history), NULL));
	_g_object_unref0 (self->priv->navigation_cancellable);
	_g_object_unref0 (self->priv->last_toast);
	G_OBJECT_CLASS (ft_stats_view_parent_class)->finalize (obj);
}

static GType
ft_stats_view_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsView), 0, (GInstanceInitFunc) ft_stats_view_instance_init, NULL };
	GType ft_stats_view_type_id;
	ft_stats_view_type_id = g_type_register_static (adw_breakpoint_bin_get_type (), "FtStatsView", &g_define_type_info, 0);
	FtStatsView_private_offset = g_type_add_instance_private (ft_stats_view_type_id, sizeof (FtStatsViewPrivate));
	return ft_stats_view_type_id;
}

GType
ft_stats_view_get_type (void)
{
	static volatile gsize ft_stats_view_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_view_type_id__once)) {
		GType ft_stats_view_type_id;
		ft_stats_view_type_id = ft_stats_view_get_type_once ();
		g_once_init_leave (&ft_stats_view_type_id__once, ft_stats_view_type_id);
	}
	return ft_stats_view_type_id__once;
}

static void
_vala_ft_stats_view_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	FtStatsView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_VIEW, FtStatsView);
	switch (property_id) {
		case FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY:
		g_value_set_int64 (value, ft_stats_view_get_daily_interval (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_stats_view_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	FtStatsView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_VIEW, FtStatsView);
	switch (property_id) {
		case FT_STATS_VIEW_DAILY_INTERVAL_PROPERTY:
		ft_stats_view_set_daily_interval (self, g_value_get_int64 (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;
}

