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

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

#include "ft_ui.h"
#include <adwaita.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "ft_core.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef struct _FtDayChooser FtDayChooser;
typedef struct _FtDayChooserClass FtDayChooserClass;
typedef struct _FtWeekChooser FtWeekChooser;
typedef struct _FtWeekChooserClass FtWeekChooserClass;
typedef struct _FtMonthChooser FtMonthChooser;
typedef struct _FtMonthChooserClass FtMonthChooserClass;
enum  {
	FT_STATS_DATE_POPOVER_0_PROPERTY,
	FT_STATS_DATE_POPOVER_TIMEFRAME_PROPERTY,
	FT_STATS_DATE_POPOVER_DATE_PROPERTY,
	FT_STATS_DATE_POPOVER_MIN_DATE_PROPERTY,
	FT_STATS_DATE_POPOVER_MAX_DATE_PROPERTY,
	FT_STATS_DATE_POPOVER_NUM_PROPERTIES
};
static GParamSpec* ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	FT_STATS_DATE_POPOVER_TIMEFRAME_SELECTED_SIGNAL,
	FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL,
	FT_STATS_DATE_POPOVER_NUM_SIGNALS
};
static guint ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_NUM_SIGNALS] = {0};

struct _FtStatsDatePopoverPrivate {
	AdwToggleGroup* timeframe_toggle_group;
	FtDayChooser* day_chooser;
	FtWeekChooser* week_chooser;
	FtMonthChooser* month_chooser;
	FtTimeframe _timeframe;
	GDate _date;
	GDate _min_date;
	GDate _max_date;
	GDate user_selected_date;
};

static gint FtStatsDatePopover_private_offset;
static gpointer ft_stats_date_popover_parent_class = NULL;

static void ft_stats_date_popover_timeframe_selected (FtStatsDatePopover* self,
                                               FtTimeframe timeframe);
static void ft_stats_date_popover_date_selected (FtStatsDatePopover* self,
                                          GDate* date);
static gboolean ft_stats_date_popover_transform_from_timeframe (GBinding* binding,
                                                         GValue* source_value,
                                                         GValue* target_value);
static gboolean ft_stats_date_popover_transform_to_timeframe (GBinding* binding,
                                                       GValue* source_value,
                                                       GValue* target_value);
static void ft_stats_date_popover_get_display_month_year (FtStatsDatePopover* self,
                                                   GDateMonth* display_month,
                                                   GDateYear* display_year);
static void ft_stats_date_popover_update_selection (FtStatsDatePopover* self,
                                             GDateMonth display_month,
                                             GDateYear display_year);
VALA_EXTERN void ft_week_chooser_set_selected_date_full (FtWeekChooser* self,
                                             GDate* value,
                                             GDateMonth display_month,
                                             GDateYear display_year);
static void ft_stats_date_popover_update_date_range (FtStatsDatePopover* self);
static void ft_stats_date_popover_set_date_timeframe (FtStatsDatePopover* self,
                                               GDate* date,
                                               FtTimeframe timeframe);
static void ft_stats_date_popover_refine_date (FtStatsDatePopover* self,
                                        GDate* date,
                                        FtTimeframe date_timeframe,
                                        GDateMonth display_month,
                                        GDateYear display_year,
                                        GDate* result);
static void ft_stats_date_popover_on_notify_active_name (FtStatsDatePopover* self,
                                                  GObject* object,
                                                  GParamSpec* pspec);
static void _ft_stats_date_popover_on_notify_active_name_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void ft_stats_date_popover_on_day_selected (FtStatsDatePopover* self,
                                            GDate* date);
static void _ft_stats_date_popover_on_day_selected_ft_day_chooser_selected (FtDayChooser* _sender,
                                                                     GDate* date,
                                                                     gpointer self);
static void ft_stats_date_popover_on_week_selected (FtStatsDatePopover* self,
                                             GDate* date);
static void _ft_stats_date_popover_on_week_selected_ft_week_chooser_selected (FtWeekChooser* _sender,
                                                                       GDate* date,
                                                                       gpointer self);
static void ft_stats_date_popover_on_month_selected (FtStatsDatePopover* self,
                                              GDate* date);
static void _ft_stats_date_popover_on_month_selected_ft_month_chooser_selected (FtMonthChooser* _sender,
                                                                         GDate* date,
                                                                         gpointer self);
static void ft_stats_date_popover_on_week_display_changed (FtStatsDatePopover* self,
                                                    GDateMonth display_month,
                                                    GDateYear display_year);
static void _ft_stats_date_popover_on_week_display_changed_ft_week_chooser_display_changed (FtWeekChooser* _sender,
                                                                                     GDateMonth display_month,
                                                                                     GDateYear display_year,
                                                                                     gpointer self);
static void ft_stats_date_popover_real_unmap (GtkWidget* base);
static GObject * ft_stats_date_popover_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties);
static gboolean _ft_stats_date_popover_transform_from_timeframe_gbinding_transform_func (GBinding* binding,
                                                                                  GValue* from_value,
                                                                                  GValue* to_value,
                                                                                  gpointer self);
static gboolean _ft_stats_date_popover_transform_to_timeframe_gbinding_transform_func (GBinding* binding,
                                                                                GValue* from_value,
                                                                                GValue* to_value,
                                                                                gpointer self);
static void ft_stats_date_popover_finalize (GObject * obj);
static GType ft_stats_date_popover_get_type_once (void);
static void _vala_ft_stats_date_popover_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void _vala_ft_stats_date_popover_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
ft_stats_date_popover_get_instance_private (FtStatsDatePopover* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsDatePopover_private_offset);
}

static gboolean
ft_stats_date_popover_transform_from_timeframe (GBinding* binding,
                                                GValue* source_value,
                                                GValue* target_value)
{
	FtTimeframe timeframe = 0;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (binding != NULL, FALSE);
	g_return_val_if_fail (source_value != NULL, FALSE);
	g_return_val_if_fail (target_value != NULL, FALSE);
	timeframe = (FtTimeframe) g_value_get_enum (source_value);
	_tmp0_ = ft_timeframe_to_string (timeframe);
	_tmp1_ = _tmp0_;
	g_value_set_string (target_value, _tmp1_);
	_g_free0 (_tmp1_);
	result = TRUE;
	return result;
}

static gboolean
ft_stats_date_popover_transform_to_timeframe (GBinding* binding,
                                              GValue* source_value,
                                              GValue* target_value)
{
	FtTimeframe timeframe = 0;
	const gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (binding != NULL, FALSE);
	g_return_val_if_fail (source_value != NULL, FALSE);
	g_return_val_if_fail (target_value != NULL, FALSE);
	_tmp0_ = g_value_get_string (source_value);
	timeframe = ft_timeframe_from_string (_tmp0_);
	g_value_set_enum (target_value, (gint) timeframe);
	result = TRUE;
	return result;
}

static void
ft_stats_date_popover_get_display_month_year (FtStatsDatePopover* self,
                                              GDateMonth* display_month,
                                              GDateYear* display_year)
{
	GDateMonth _vala_display_month = 0;
	GDateYear _vala_display_year = (GDateYear) 0U;
	gboolean _tmp16_ = FALSE;
	g_return_if_fail (self != NULL);
	switch (self->priv->_timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			FtDayChooser* _tmp0_;
			GDateMonth _tmp1_;
			GDateMonth _tmp2_;
			FtDayChooser* _tmp3_;
			GDateYear _tmp4_;
			GDateYear _tmp5_;
			_tmp0_ = self->priv->day_chooser;
			_tmp1_ = ft_day_chooser_get_display_month (_tmp0_);
			_tmp2_ = _tmp1_;
			_vala_display_month = _tmp2_;
			_tmp3_ = self->priv->day_chooser;
			_tmp4_ = ft_day_chooser_get_display_year (_tmp3_);
			_tmp5_ = _tmp4_;
			_vala_display_year = _tmp5_;
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			FtWeekChooser* _tmp6_;
			GDateMonth _tmp7_;
			GDateMonth _tmp8_;
			FtWeekChooser* _tmp9_;
			GDateYear _tmp10_;
			GDateYear _tmp11_;
			_tmp6_ = self->priv->week_chooser;
			_tmp7_ = ft_week_chooser_get_display_month (_tmp6_);
			_tmp8_ = _tmp7_;
			_vala_display_month = _tmp8_;
			_tmp9_ = self->priv->week_chooser;
			_tmp10_ = ft_week_chooser_get_display_year (_tmp9_);
			_tmp11_ = _tmp10_;
			_vala_display_year = _tmp11_;
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			GDateMonth _tmp12_ = 0;
			FtMonthChooser* _tmp13_;
			GDateYear _tmp14_;
			GDateYear _tmp15_;
			if (g_date_valid (&self->priv->_date)) {
				_tmp12_ = g_date_get_month (&self->priv->_date);
			} else {
				_tmp12_ = G_DATE_BAD_MONTH;
			}
			_vala_display_month = _tmp12_;
			_tmp13_ = self->priv->month_chooser;
			_tmp14_ = ft_month_chooser_get_display_year (_tmp13_);
			_tmp15_ = _tmp14_;
			_vala_display_year = _tmp15_;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	if (!g_date_valid_month (_vala_display_month)) {
		_tmp16_ = TRUE;
	} else {
		_tmp16_ = !g_date_valid_year (_vala_display_year);
	}
	if (_tmp16_) {
		GDate today = {0};
		GDate _tmp17_ = {0};
		ft_date_utils_get_today (&_tmp17_);
		today = _tmp17_;
		_vala_display_month = g_date_get_month (&today);
		_vala_display_year = g_date_get_year (&today);
	}
	if (display_month) {
		*display_month = _vala_display_month;
	}
	if (display_year) {
		*display_year = _vala_display_year;
	}
}

static void
ft_stats_date_popover_update_selection (FtStatsDatePopover* self,
                                        GDateMonth display_month,
                                        GDateYear display_year)
{
	GDate _tmp6_ = {0};
	FtDayChooser* _tmp9_;
	GDate _tmp10_ = {0};
	FtMonthChooser* _tmp13_;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (&self->priv->_date)) {
		FtDayChooser* _tmp0_;
		GDate _tmp1_ = {0};
		FtWeekChooser* _tmp2_;
		GDate _tmp3_ = {0};
		FtMonthChooser* _tmp4_;
		GDate _tmp5_ = {0};
		_tmp0_ = self->priv->day_chooser;
		memset (&_tmp1_, 0, sizeof (GDate));
		ft_day_chooser_set_selected_date (_tmp0_, &_tmp1_);
		_tmp2_ = self->priv->week_chooser;
		memset (&_tmp3_, 0, sizeof (GDate));
		ft_week_chooser_set_selected_date (_tmp2_, &_tmp3_);
		_tmp4_ = self->priv->month_chooser;
		memset (&_tmp5_, 0, sizeof (GDate));
		ft_month_chooser_set_selected_date (_tmp4_, &_tmp5_);
		return;
	}
	if (self->priv->_timeframe == FT_TIMEFRAME_DAY) {
		GDate _tmp7_;
		GDate _tmp8_ = {0};
		_tmp7_ = self->priv->_date;
		ft_timeframe_normalize_date (FT_TIMEFRAME_DAY, &_tmp7_, &_tmp8_);
		_tmp6_ = _tmp8_;
	} else {
		memset (&_tmp6_, 0, sizeof (GDate));
	}
	_tmp9_ = self->priv->day_chooser;
	ft_day_chooser_set_selected_date (_tmp9_, &_tmp6_);
	if (self->priv->_timeframe == FT_TIMEFRAME_MONTH) {
		GDate _tmp11_;
		GDate _tmp12_ = {0};
		_tmp11_ = self->priv->_date;
		ft_timeframe_normalize_date (FT_TIMEFRAME_MONTH, &_tmp11_, &_tmp12_);
		_tmp10_ = _tmp12_;
	} else {
		memset (&_tmp10_, 0, sizeof (GDate));
	}
	_tmp13_ = self->priv->month_chooser;
	ft_month_chooser_set_selected_date (_tmp13_, &_tmp10_);
	if (self->priv->_timeframe == FT_TIMEFRAME_WEEK) {
		GDate week_start_date = {0};
		GDate _tmp14_;
		GDate _tmp15_ = {0};
		GDate* week_end_date = NULL;
		GDate* _tmp16_;
		GDate* _tmp17_;
		GDate display_date = {0};
		GDate _tmp18_;
		_tmp14_ = self->priv->_date;
		ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp14_, &_tmp15_);
		week_start_date = _tmp15_;
		_tmp16_ = g_date_copy (&week_start_date);
		week_end_date = _tmp16_;
		_tmp17_ = week_end_date;
		g_date_add_days (_tmp17_, 6U);
		memset (&display_date, 0, sizeof (GDate));
		g_date_set_dmy (&display_date, (GDateDay) 1, (gint) display_month, display_year);
		_tmp18_ = display_date;
		if (g_date_compare (&week_start_date, &_tmp18_) >= 0) {
			FtWeekChooser* _tmp19_;
			GDate _tmp20_;
			GDate _tmp21_ = {0};
			_tmp19_ = self->priv->week_chooser;
			_tmp20_ = self->priv->_date;
			ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp20_, &_tmp21_);
			ft_week_chooser_set_selected_date_full (_tmp19_, &_tmp21_, g_date_get_month (&week_start_date), g_date_get_year (&week_start_date));
		} else {
			FtWeekChooser* _tmp22_;
			GDate _tmp23_;
			GDate _tmp24_ = {0};
			GDate* _tmp25_;
			GDate* _tmp26_;
			_tmp22_ = self->priv->week_chooser;
			_tmp23_ = self->priv->_date;
			ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp23_, &_tmp24_);
			_tmp25_ = week_end_date;
			_tmp26_ = week_end_date;
			ft_week_chooser_set_selected_date_full (_tmp22_, &_tmp24_, g_date_get_month (_tmp25_), g_date_get_year (_tmp26_));
		}
		_g_free0 (week_end_date);
	} else {
		FtWeekChooser* _tmp27_;
		GDate _tmp28_ = {0};
		_tmp27_ = self->priv->week_chooser;
		memset (&_tmp28_, 0, sizeof (GDate));
		ft_week_chooser_set_selected_date (_tmp27_, &_tmp28_);
	}
}

static void
ft_stats_date_popover_update_date_range (FtStatsDatePopover* self)
{
	FtDayChooser* _tmp0_;
	GDate _tmp1_;
	GDate _tmp2_ = {0};
	FtDayChooser* _tmp3_;
	GDate _tmp4_;
	GDate _tmp5_ = {0};
	FtWeekChooser* _tmp6_;
	GDate _tmp7_;
	GDate _tmp8_ = {0};
	FtWeekChooser* _tmp9_;
	GDate _tmp10_;
	GDate _tmp11_ = {0};
	FtMonthChooser* _tmp12_;
	GDate _tmp13_;
	GDate _tmp14_ = {0};
	FtMonthChooser* _tmp15_;
	GDate _tmp16_;
	GDate _tmp17_ = {0};
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->day_chooser;
	_tmp1_ = self->priv->_min_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_DAY, &_tmp1_, &_tmp2_);
	ft_day_chooser_set_min_date (_tmp0_, &_tmp2_);
	_tmp3_ = self->priv->day_chooser;
	_tmp4_ = self->priv->_max_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_DAY, &_tmp4_, &_tmp5_);
	ft_day_chooser_set_max_date (_tmp3_, &_tmp5_);
	_tmp6_ = self->priv->week_chooser;
	_tmp7_ = self->priv->_min_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp7_, &_tmp8_);
	ft_week_chooser_set_min_date (_tmp6_, &_tmp8_);
	_tmp9_ = self->priv->week_chooser;
	_tmp10_ = self->priv->_max_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp10_, &_tmp11_);
	ft_week_chooser_set_max_date (_tmp9_, &_tmp11_);
	_tmp12_ = self->priv->month_chooser;
	_tmp13_ = self->priv->_min_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_MONTH, &_tmp13_, &_tmp14_);
	ft_month_chooser_set_min_date (_tmp12_, &_tmp14_);
	_tmp15_ = self->priv->month_chooser;
	_tmp16_ = self->priv->_max_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_MONTH, &_tmp16_, &_tmp17_);
	ft_month_chooser_set_max_date (_tmp15_, &_tmp17_);
}

static void
ft_stats_date_popover_set_date_timeframe (FtStatsDatePopover* self,
                                          GDate* date,
                                          FtTimeframe timeframe)
{
	GDateMonth display_month = 0;
	GDateYear display_year = (GDateYear) 0U;
	GDateMonth _tmp0_ = 0;
	GDateYear _tmp1_ = (GDateYear) 0U;
	GDate _tmp2_;
	GDate _tmp3_ = {0};
	gboolean _tmp4_ = FALSE;
	gboolean date_changed = FALSE;
	gboolean timeframe_changed = FALSE;
	GDate _tmp6_;
	gboolean _tmp7_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	ft_stats_date_popover_get_display_month_year (self, &_tmp0_, &_tmp1_);
	display_month = _tmp0_;
	display_year = _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) {
		_tmp7_ = TRUE;
	} else {
		_tmp7_ = date_changed;
	}
	if (_tmp7_) {
		ft_stats_date_popover_update_selection (self, display_month, display_year);
	}
	if (timeframe_changed) {
		g_object_notify ((GObject*) self, "timeframe");
	}
	if (date_changed) {
		g_object_notify ((GObject*) self, "date");
	}
}

/**
         * Refinement tries to recover lost resolution at higher timeframes.
         *
         * When selecting a higher timeframes we may loose user intent. We want to transition
         * between "this month", "this week" and "today" while switching timeframes.
         */
static void
ft_stats_date_popover_refine_date (FtStatsDatePopover* self,
                                   GDate* date,
                                   FtTimeframe date_timeframe,
                                   GDateMonth display_month,
                                   GDateYear display_year,
                                   GDate* result)
{
	GDate today = {0};
	GDate _tmp0_ = {0};
	GDate* refined_date = NULL;
	GDate* _tmp1_;
	gboolean _tmp46_ = FALSE;
	gboolean _tmp50_ = FALSE;
	GDate* _tmp54_;
	GDate _tmp55_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	ft_date_utils_get_today (&_tmp0_);
	today = _tmp0_;
	_tmp1_ = g_date_copy (date);
	refined_date = _tmp1_;
	if (!g_date_valid (date)) {
		GDate _tmp2_ = {0};
		if (g_date_valid (&self->priv->user_selected_date)) {
			GDate _tmp3_;
			_tmp3_ = self->priv->user_selected_date;
			_tmp2_ = _tmp3_;
		} else {
			GDate _tmp4_;
			_tmp4_ = today;
			_tmp2_ = _tmp4_;
		}
		*result = _tmp2_;
		_g_free0 (refined_date);
		return;
	}
	switch (date_timeframe) {
		case FT_TIMEFRAME_DAY:
		{
			break;
		}
		case FT_TIMEFRAME_WEEK:
		{
			GDate* week_start_date = NULL;
			GDate* _tmp5_;
			GDate* week_end_date = NULL;
			GDate* _tmp6_;
			GDate* _tmp7_;
			GDate display_date = {0};
			gboolean _tmp8_ = FALSE;
			gboolean _tmp9_ = FALSE;
			gboolean _tmp20_ = FALSE;
			gboolean _tmp21_ = FALSE;
			_tmp5_ = g_date_copy (date);
			week_start_date = _tmp5_;
			_tmp6_ = g_date_copy (date);
			week_end_date = _tmp6_;
			_tmp7_ = week_end_date;
			g_date_add_days (_tmp7_, 6U);
			memset (&display_date, 0, sizeof (GDate));
			if (g_date_valid_month (display_month)) {
				_tmp8_ = g_date_valid_year (display_year);
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				g_date_set_dmy (&display_date, (GDateDay) 1, (gint) display_month, display_year);
			}
			if (g_date_valid (&display_date)) {
				GDate* _tmp10_;
				GDate* _tmp11_;
				_tmp10_ = week_start_date;
				_tmp11_ = week_end_date;
				_tmp9_ = g_date_get_month (_tmp10_) != g_date_get_month (_tmp11_);
			} else {
				_tmp9_ = FALSE;
			}
			if (_tmp9_) {
				GDate* _tmp12_;
				GDate _tmp13_;
				_tmp12_ = week_start_date;
				_tmp13_ = *_tmp12_;
				if (g_date_compare (&display_date, &_tmp13_) <= 0) {
					GDateMonth month = 0;
					GDate* _tmp14_;
					GDateYear year = (GDateYear) 0U;
					GDate* _tmp15_;
					GDate* _tmp16_;
					_tmp14_ = week_start_date;
					month = g_date_get_month (_tmp14_);
					_tmp15_ = week_start_date;
					year = g_date_get_year (_tmp15_);
					_tmp16_ = week_end_date;
					g_date_set_dmy (_tmp16_, (GDateDay) g_date_get_days_in_month (month, year), (gint) month, year);
				} else {
					GDate* _tmp17_;
					GDate* _tmp18_;
					GDate* _tmp19_;
					_tmp17_ = week_start_date;
					_tmp18_ = week_end_date;
					_tmp19_ = week_end_date;
					g_date_set_dmy (_tmp17_, (GDateDay) 1, (gint) g_date_get_month (_tmp18_), g_date_get_year (_tmp19_));
				}
			}
			if (g_date_valid (&self->priv->user_selected_date)) {
				GDate* _tmp22_;
				GDate _tmp23_;
				_tmp22_ = week_start_date;
				_tmp23_ = *_tmp22_;
				_tmp21_ = g_date_compare (&self->priv->user_selected_date, &_tmp23_) >= 0;
			} else {
				_tmp21_ = FALSE;
			}
			if (_tmp21_) {
				GDate* _tmp24_;
				GDate _tmp25_;
				_tmp24_ = week_end_date;
				_tmp25_ = *_tmp24_;
				_tmp20_ = g_date_compare (&self->priv->user_selected_date, &_tmp25_) <= 0;
			} else {
				_tmp20_ = FALSE;
			}
			if (_tmp20_) {
				GDate* _tmp26_;
				_tmp26_ = g_date_copy (&self->priv->user_selected_date);
				_g_free0 (refined_date);
				refined_date = _tmp26_;
			} else {
				gboolean _tmp27_ = FALSE;
				GDate* _tmp28_;
				GDate _tmp29_;
				_tmp28_ = week_start_date;
				_tmp29_ = *_tmp28_;
				if (g_date_compare (&today, &_tmp29_) >= 0) {
					GDate* _tmp30_;
					GDate _tmp31_;
					_tmp30_ = week_end_date;
					_tmp31_ = *_tmp30_;
					_tmp27_ = g_date_compare (&today, &_tmp31_) <= 0;
				} else {
					_tmp27_ = FALSE;
				}
				if (_tmp27_) {
					GDate* _tmp32_;
					_tmp32_ = g_date_copy (&today);
					_g_free0 (refined_date);
					refined_date = _tmp32_;
				} else {
					GDate* _tmp33_;
					GDate _tmp34_;
					_tmp33_ = week_start_date;
					_tmp34_ = *_tmp33_;
					if (g_date_compare (date, &_tmp34_) < 0) {
						GDate* _tmp35_;
						GDate* _tmp36_;
						_tmp35_ = week_start_date;
						_tmp36_ = g_date_copy (_tmp35_);
						_g_free0 (refined_date);
						refined_date = _tmp36_;
					} else {
						GDate* _tmp37_;
						GDate _tmp38_;
						_tmp37_ = week_end_date;
						_tmp38_ = *_tmp37_;
						if (g_date_compare (date, &_tmp38_) > 0) {
							GDate* _tmp39_;
							GDate* _tmp40_;
							_tmp39_ = week_end_date;
							_tmp40_ = g_date_copy (_tmp39_);
							_g_free0 (refined_date);
							refined_date = _tmp40_;
						}
					}
				}
			}
			_g_free0 (week_end_date);
			_g_free0 (week_start_date);
			break;
		}
		case FT_TIMEFRAME_MONTH:
		{
			gboolean _tmp41_ = FALSE;
			gboolean _tmp42_ = FALSE;
			if (g_date_valid (&self->priv->user_selected_date)) {
				_tmp42_ = g_date_get_month (&self->priv->user_selected_date) == g_date_get_month (date);
			} else {
				_tmp42_ = FALSE;
			}
			if (_tmp42_) {
				_tmp41_ = g_date_get_year (&self->priv->user_selected_date) == g_date_get_year (date);
			} else {
				_tmp41_ = FALSE;
			}
			if (_tmp41_) {
				GDate* _tmp43_;
				_tmp43_ = g_date_copy (&self->priv->user_selected_date);
				_g_free0 (refined_date);
				refined_date = _tmp43_;
			} else {
				gboolean _tmp44_ = FALSE;
				if (g_date_get_month (date) == g_date_get_month (&today)) {
					_tmp44_ = g_date_get_year (date) == g_date_get_year (&today);
				} else {
					_tmp44_ = FALSE;
				}
				if (_tmp44_) {
					GDate* _tmp45_;
					_tmp45_ = g_date_copy (&today);
					_g_free0 (refined_date);
					refined_date = _tmp45_;
				}
			}
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	if (g_date_valid (&self->priv->_min_date)) {
		GDate* _tmp47_;
		GDate _tmp48_;
		_tmp47_ = refined_date;
		_tmp48_ = *_tmp47_;
		_tmp46_ = g_date_compare (&self->priv->_min_date, &_tmp48_) > 0;
	} else {
		_tmp46_ = FALSE;
	}
	if (_tmp46_) {
		GDate* _tmp49_;
		_tmp49_ = g_date_copy (&self->priv->_min_date);
		_g_free0 (refined_date);
		refined_date = _tmp49_;
	}
	if (g_date_valid (&self->priv->_max_date)) {
		GDate* _tmp51_;
		GDate _tmp52_;
		_tmp51_ = refined_date;
		_tmp52_ = *_tmp51_;
		_tmp50_ = g_date_compare (&self->priv->_max_date, &_tmp52_) < 0;
	} else {
		_tmp50_ = FALSE;
	}
	if (_tmp50_) {
		GDate* _tmp53_;
		_tmp53_ = g_date_copy (&self->priv->_max_date);
		_g_free0 (refined_date);
		refined_date = _tmp53_;
	}
	_tmp54_ = refined_date;
	_tmp55_ = *_tmp54_;
	_g_free0 (_tmp54_);
	*result = _tmp55_;
	return;
}

static void
ft_stats_date_popover_on_notify_active_name (FtStatsDatePopover* self,
                                             GObject* object,
                                             GParamSpec* pspec)
{
	FtTimeframe timeframe = 0;
	AdwToggleGroup* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (pspec != NULL);
	_tmp0_ = self->priv->timeframe_toggle_group;
	_tmp1_ = adw_toggle_group_get_active_name (_tmp0_);
	_tmp2_ = _tmp1_;
	timeframe = ft_timeframe_from_string (_tmp2_);
	if (timeframe != self->priv->_timeframe) {
		g_signal_emit (self, ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_TIMEFRAME_SELECTED_SIGNAL], 0, timeframe);
	}
}

static void
_ft_stats_date_popover_on_notify_active_name_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	ft_stats_date_popover_on_notify_active_name ((FtStatsDatePopover*) self, _sender, pspec);
}

static void
ft_stats_date_popover_on_day_selected (FtStatsDatePopover* self,
                                       GDate* date)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDate _tmp2_;
	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_ = self->priv->user_selected_date;
	g_signal_emit (self, ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL], 0, &_tmp2_);
}

static void
_ft_stats_date_popover_on_day_selected_ft_day_chooser_selected (FtDayChooser* _sender,
                                                                GDate* date,
                                                                gpointer self)
{
	ft_stats_date_popover_on_day_selected ((FtStatsDatePopover*) self, date);
}

static void
ft_stats_date_popover_on_week_selected (FtStatsDatePopover* self,
                                        GDate* date)
{
	GDate _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = *date;
	ft_stats_date_popover_refine_date (self, &_tmp0_, FT_TIMEFRAME_WEEK, G_DATE_BAD_MONTH, (GDateYear) G_DATE_BAD_YEAR, &_tmp1_);
	self->priv->user_selected_date = _tmp1_;
	_tmp2_ = self->priv->user_selected_date;
	g_signal_emit (self, ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL], 0, &_tmp2_);
}

static void
_ft_stats_date_popover_on_week_selected_ft_week_chooser_selected (FtWeekChooser* _sender,
                                                                  GDate* date,
                                                                  gpointer self)
{
	ft_stats_date_popover_on_week_selected ((FtStatsDatePopover*) self, date);
}

static void
ft_stats_date_popover_on_month_selected (FtStatsDatePopover* self,
                                         GDate* date)
{
	GDate _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = *date;
	ft_stats_date_popover_refine_date (self, &_tmp0_, FT_TIMEFRAME_MONTH, G_DATE_BAD_MONTH, (GDateYear) G_DATE_BAD_YEAR, &_tmp1_);
	self->priv->user_selected_date = _tmp1_;
	_tmp2_ = self->priv->user_selected_date;
	g_signal_emit (self, ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL], 0, &_tmp2_);
}

static void
_ft_stats_date_popover_on_month_selected_ft_month_chooser_selected (FtMonthChooser* _sender,
                                                                    GDate* date,
                                                                    gpointer self)
{
	ft_stats_date_popover_on_month_selected ((FtStatsDatePopover*) self, date);
}

static void
ft_stats_date_popover_on_week_display_changed (FtStatsDatePopover* self,
                                               GDateMonth display_month,
                                               GDateYear display_year)
{
	GDate _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_date;
	ft_stats_date_popover_refine_date (self, &_tmp0_, FT_TIMEFRAME_WEEK, display_month, display_year, &_tmp1_);
	self->priv->user_selected_date = _tmp1_;
	_tmp2_ = self->priv->user_selected_date;
	g_signal_emit (self, ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL], 0, &_tmp2_);
}

static void
_ft_stats_date_popover_on_week_display_changed_ft_week_chooser_display_changed (FtWeekChooser* _sender,
                                                                                GDateMonth display_month,
                                                                                GDateYear display_year,
                                                                                gpointer self)
{
	ft_stats_date_popover_on_week_display_changed ((FtStatsDatePopover*) self, display_month, display_year);
}

static void
ft_stats_date_popover_real_unmap (GtkWidget* base)
{
	FtStatsDatePopover * self;
	self = (FtStatsDatePopover*) base;
	GTK_WIDGET_CLASS (ft_stats_date_popover_parent_class)->unmap ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_popover_get_type (), GtkPopover));
	memset (&self->priv->user_selected_date, 0, sizeof (GDate));
}

FtStatsDatePopover*
ft_stats_date_popover_construct (GType object_type)
{
	FtStatsDatePopover * self = NULL;
	self = (FtStatsDatePopover*) g_object_new (object_type, NULL);
	return self;
}

FtStatsDatePopover*
ft_stats_date_popover_new (void)
{
	return ft_stats_date_popover_construct (FT_TYPE_STATS_DATE_POPOVER);
}

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

void
ft_stats_date_popover_set_timeframe (FtStatsDatePopover* self,
                                     FtTimeframe value)
{
	GDate date = {0};
	GDate _tmp0_;
	GDate _tmp1_ = {0};
	GDate _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_date;
	ft_stats_date_popover_refine_date (self, &_tmp0_, self->priv->_timeframe, G_DATE_BAD_MONTH, (GDateYear) G_DATE_BAD_YEAR, &_tmp1_);
	date = _tmp1_;
	_tmp2_ = date;
	ft_stats_date_popover_set_date_timeframe (self, &_tmp2_, value);
}

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

void
ft_stats_date_popover_set_date (FtStatsDatePopover* self,
                                GDate * value)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (value)) {
		return;
	}
	_tmp0_ = *value;
	ft_stats_date_popover_set_date_timeframe (self, &_tmp0_, self->priv->_timeframe);
}

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

void
ft_stats_date_popover_set_min_date (FtStatsDatePopover* 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_;
	ft_stats_date_popover_update_date_range (self);
	g_object_notify_by_pspec ((GObject *) self, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_MIN_DATE_PROPERTY]);
}

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

void
ft_stats_date_popover_set_max_date (FtStatsDatePopover* 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_;
	ft_stats_date_popover_update_date_range (self);
	g_object_notify_by_pspec ((GObject *) self, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_MAX_DATE_PROPERTY]);
}

static void
ft_stats_date_popover_real_timeframe_selected (FtStatsDatePopover* self,
                                               FtTimeframe timeframe)
{
	g_return_if_fail (self != NULL);
	ft_stats_date_popover_set_timeframe (self, timeframe);
}

static void
ft_stats_date_popover_real_date_selected (FtStatsDatePopover* self,
                                          GDate* date)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = *date;
	ft_stats_date_popover_set_date (self, &_tmp0_);
}

static gboolean
_ft_stats_date_popover_transform_from_timeframe_gbinding_transform_func (GBinding* binding,
                                                                         GValue* from_value,
                                                                         GValue* to_value,
                                                                         gpointer self)
{
	gboolean result;
	result = ft_stats_date_popover_transform_from_timeframe (binding, from_value, to_value);
	return result;
}

static gboolean
_ft_stats_date_popover_transform_to_timeframe_gbinding_transform_func (GBinding* binding,
                                                                       GValue* from_value,
                                                                       GValue* to_value,
                                                                       gpointer self)
{
	gboolean result;
	result = ft_stats_date_popover_transform_to_timeframe (binding, from_value, to_value);
	return result;
}

static GObject *
ft_stats_date_popover_constructor (GType type,
                                   guint n_construct_properties,
                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtStatsDatePopover * self;
	AdwToggleGroup* _tmp0_;
	parent_class = G_OBJECT_CLASS (ft_stats_date_popover_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_DATE_POPOVER, FtStatsDatePopover);
	_tmp0_ = self->priv->timeframe_toggle_group;
	g_object_bind_property_with_closures ((GObject*) self, "timeframe", (GObject*) _tmp0_, "active-name", G_BINDING_SYNC_CREATE, (GClosure*) g_cclosure_new ((GCallback) _ft_stats_date_popover_transform_from_timeframe_gbinding_transform_func, NULL, (GClosureNotify) NULL), (GClosure*) g_cclosure_new ((GCallback) _ft_stats_date_popover_transform_to_timeframe_gbinding_transform_func, NULL, (GClosureNotify) NULL));
	return obj;
}

static void
ft_stats_date_popover_class_init (FtStatsDatePopoverClass * klass,
                                  gpointer klass_data)
{
	ft_stats_date_popover_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsDatePopover_private_offset);
	((GtkWidgetClass *) klass)->unmap = (void (*) (GtkWidget*)) ft_stats_date_popover_real_unmap;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_date_popover_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_date_popover_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_stats_date_popover_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_date_popover_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_DATE_POPOVER_TIMEFRAME_PROPERTY, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_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_DATE_POPOVER_DATE_PROPERTY, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_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_DATE_POPOVER_MIN_DATE_PROPERTY, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_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_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_DATE_POPOVER_MAX_DATE_PROPERTY, ft_stats_date_popover_properties[FT_STATS_DATE_POPOVER_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_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/widgets/stats-date-popover.ui");
	ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_TIMEFRAME_SELECTED_SIGNAL] = g_signal_new_class_handler ("timeframe-selected", FT_TYPE_STATS_DATE_POPOVER, G_SIGNAL_RUN_LAST, (GCallback) ft_stats_date_popover_real_timeframe_selected, NULL, NULL, g_cclosure_marshal_VOID__ENUM, G_TYPE_NONE, 1, FT_TYPE_TIMEFRAME);
	ft_stats_date_popover_signals[FT_STATS_DATE_POPOVER_DATE_SELECTED_SIGNAL] = g_signal_new_class_handler ("date-selected", FT_TYPE_STATS_DATE_POPOVER, G_SIGNAL_RUN_LAST, (GCallback) ft_stats_date_popover_real_date_selected, NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_DATE);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "timeframe_toggle_group", FALSE, FtStatsDatePopover_private_offset + G_STRUCT_OFFSET (FtStatsDatePopoverPrivate, timeframe_toggle_group));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "day_chooser", FALSE, FtStatsDatePopover_private_offset + G_STRUCT_OFFSET (FtStatsDatePopoverPrivate, day_chooser));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "week_chooser", FALSE, FtStatsDatePopover_private_offset + G_STRUCT_OFFSET (FtStatsDatePopoverPrivate, week_chooser));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "month_chooser", FALSE, FtStatsDatePopover_private_offset + G_STRUCT_OFFSET (FtStatsDatePopoverPrivate, month_chooser));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_notify_active_name", G_CALLBACK(_ft_stats_date_popover_on_notify_active_name_g_object_notify));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_day_selected", G_CALLBACK(_ft_stats_date_popover_on_day_selected_ft_day_chooser_selected));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_week_selected", G_CALLBACK(_ft_stats_date_popover_on_week_selected_ft_week_chooser_selected));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_month_selected", G_CALLBACK(_ft_stats_date_popover_on_month_selected_ft_month_chooser_selected));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_week_display_changed", G_CALLBACK(_ft_stats_date_popover_on_week_display_changed_ft_week_chooser_display_changed));
}

static void
ft_stats_date_popover_instance_init (FtStatsDatePopover * self,
                                     gpointer klass)
{
	self->priv = ft_stats_date_popover_get_instance_private (self);
	self->priv->_timeframe = FT_TIMEFRAME_DAY;
	g_type_ensure (FT_TYPE_DAY_CHOOSER);
	g_type_ensure (FT_TYPE_WEEK_CHOOSER);
	g_type_ensure (FT_TYPE_MONTH_CHOOSER);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_stats_date_popover_finalize (GObject * obj)
{
	FtStatsDatePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_DATE_POPOVER, FtStatsDatePopover);
	G_OBJECT_CLASS (ft_stats_date_popover_parent_class)->finalize (obj);
}

static GType
ft_stats_date_popover_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsDatePopoverClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_date_popover_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsDatePopover), 0, (GInstanceInitFunc) ft_stats_date_popover_instance_init, NULL };
	GType ft_stats_date_popover_type_id;
	ft_stats_date_popover_type_id = g_type_register_static (gtk_popover_get_type (), "FtStatsDatePopover", &g_define_type_info, 0);
	FtStatsDatePopover_private_offset = g_type_add_instance_private (ft_stats_date_popover_type_id, sizeof (FtStatsDatePopoverPrivate));
	return ft_stats_date_popover_type_id;
}

GType
ft_stats_date_popover_get_type (void)
{
	static volatile gsize ft_stats_date_popover_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_date_popover_type_id__once)) {
		GType ft_stats_date_popover_type_id;
		ft_stats_date_popover_type_id = ft_stats_date_popover_get_type_once ();
		g_once_init_leave (&ft_stats_date_popover_type_id__once, ft_stats_date_popover_type_id);
	}
	return ft_stats_date_popover_type_id__once;
}

static void
_vala_ft_stats_date_popover_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	FtStatsDatePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_DATE_POPOVER, FtStatsDatePopover);
	switch (property_id) {
		case FT_STATS_DATE_POPOVER_TIMEFRAME_PROPERTY:
		g_value_set_enum (value, ft_stats_date_popover_get_timeframe (self));
		break;
		case FT_STATS_DATE_POPOVER_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_date_popover_get_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_STATS_DATE_POPOVER_MIN_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_date_popover_get_min_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_STATS_DATE_POPOVER_MAX_DATE_PROPERTY:
		{
			GDate boxed;
			ft_stats_date_popover_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_date_popover_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec)
{
	FtStatsDatePopover * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_DATE_POPOVER, FtStatsDatePopover);
	switch (property_id) {
		case FT_STATS_DATE_POPOVER_TIMEFRAME_PROPERTY:
		ft_stats_date_popover_set_timeframe (self, g_value_get_enum (value));
		break;
		case FT_STATS_DATE_POPOVER_DATE_PROPERTY:
		ft_stats_date_popover_set_date (self, g_value_get_boxed (value));
		break;
		case FT_STATS_DATE_POPOVER_MIN_DATE_PROPERTY:
		ft_stats_date_popover_set_min_date (self, g_value_get_boxed (value));
		break;
		case FT_STATS_DATE_POPOVER_MAX_DATE_PROPERTY:
		ft_stats_date_popover_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
_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;
}

