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

/*
 * Copyright (c) 2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

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

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

typedef struct _FtWeekChooser FtWeekChooser;
typedef struct _FtWeekChooserClass FtWeekChooserClass;
typedef struct _FtWeekChooserPrivate FtWeekChooserPrivate;
enum  {
	FT_WEEK_CHOOSER_0_PROPERTY,
	FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY,
	FT_WEEK_CHOOSER_MIN_DATE_PROPERTY,
	FT_WEEK_CHOOSER_MAX_DATE_PROPERTY,
	FT_WEEK_CHOOSER_DISPLAY_MONTH_PROPERTY,
	FT_WEEK_CHOOSER_DISPLAY_YEAR_PROPERTY,
	FT_WEEK_CHOOSER_NUM_PROPERTIES
};
static GParamSpec* ft_week_chooser_properties[FT_WEEK_CHOOSER_NUM_PROPERTIES];
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
typedef struct _Block11Data Block11Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	FT_WEEK_CHOOSER_SELECTED_SIGNAL,
	FT_WEEK_CHOOSER_DISPLAY_CHANGED_SIGNAL,
	FT_WEEK_CHOOSER_NUM_SIGNALS
};
static guint ft_week_chooser_signals[FT_WEEK_CHOOSER_NUM_SIGNALS] = {0};

struct _FtWeekChooser {
	AdwBin parent_instance;
	FtWeekChooserPrivate * priv;
};

struct _FtWeekChooserClass {
	AdwBinClass parent_class;
};

struct _FtWeekChooserPrivate {
	GtkLabel* header_label;
	GtkButton* previous_button;
	GtkButton* next_button;
	GtkBox* weekdays_box;
	GtkGrid* grid;
	GDate _selected_date;
	GDate _min_date;
	GDate _max_date;
	GDateMonth _display_month;
	GDateYear _display_year;
	GtkWidget* selected_button;
	GDate display_start_date;
	GDate display_end_date;
};

struct _Block11Data {
	int _ref_count_;
	FtWeekChooser* self;
	FtWeekChooser* _self_;
	GDate* date_copy;
};

static gint FtWeekChooser_private_offset;
static gpointer ft_week_chooser_parent_class = NULL;

static void ft_week_chooser_set_display_month_year (FtWeekChooser* self,
                                             GDateMonth month,
                                             GDateYear year);
static void ft_week_chooser_update (FtWeekChooser* self);
VALA_EXTERN void ft_week_chooser_set_selected_date_full (FtWeekChooser* self,
                                             GDate* value,
                                             GDateMonth display_month,
                                             GDateYear display_year);
static void ft_week_chooser_update_selection (FtWeekChooser* self);
static GtkButton* ft_week_chooser_create_week_button (FtWeekChooser* self,
                                               GDate* date,
                                               guint week_number);
static Block11Data* block11_data_ref (Block11Data* _data11_);
static void block11_data_unref (void * _userdata_);
static void __lambda22_ (Block11Data* _data11_);
static gboolean ft_week_chooser_select (FtWeekChooser* self,
                                 GDate* date);
static void ___lambda22__gtk_button_clicked (GtkButton* _sender,
                                      gpointer self);
static void ft_week_chooser_clear_weekdays (FtWeekChooser* self);
static void ft_week_chooser_clear_weeks (FtWeekChooser* self);
static void ft_week_chooser_update_weekday_labels (FtWeekChooser* self);
static void ft_week_chooser_update_previous_button (FtWeekChooser* self);
static void ft_week_chooser_update_next_button (FtWeekChooser* self);
static void ft_week_chooser_update_header (FtWeekChooser* self);
VALA_EXTERN gchar* ft_capitalize_words (const gchar* text);
static void ft_week_chooser_create_weeks (FtWeekChooser* self);
static void ft_week_chooser_update_weeks (FtWeekChooser* self);
static void ft_week_chooser_on_previous_button_clicked (FtWeekChooser* self);
static void _ft_week_chooser_on_previous_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                     gpointer self);
static void ft_week_chooser_on_next_button_clicked (FtWeekChooser* self);
static void _ft_week_chooser_on_next_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                 gpointer self);
static void ft_week_chooser_real_map (GtkWidget* base);
static void ft_week_chooser_real_unmap (GtkWidget* base);
static void ft_week_chooser_real_dispose (GObject* base);
static void g_cclosure_user_marshal_VOID__INT_UINT (GClosure * closure,
                                             GValue * return_value,
                                             guint n_param_values,
                                             const GValue * param_values,
                                             gpointer invocation_hint,
                                             gpointer marshal_data);
static void ft_week_chooser_finalize (GObject * obj);
static GType ft_week_chooser_get_type_once (void);
static void _vala_ft_week_chooser_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec);
static void _vala_ft_week_chooser_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_week_chooser_get_instance_private (FtWeekChooser* self)
{
	return G_STRUCT_MEMBER_P (self, FtWeekChooser_private_offset);
}

static void
ft_week_chooser_set_display_month_year (FtWeekChooser* self,
                                        GDateMonth month,
                                        GDateYear year)
{
	gboolean _tmp0_ = FALSE;
	GDate display_date = {0};
	GDate _tmp1_;
	GDate _tmp2_ = {0};
	GDate* _tmp3_;
	GDate* _tmp4_;
	GDate _tmp5_;
	GDate _tmp6_ = {0};
	g_return_if_fail (self != NULL);
	if (self->priv->_display_month == month) {
		_tmp0_ = self->priv->_display_year == year;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	self->priv->_display_month = month;
	self->priv->_display_year = year;
	memset (&display_date, 0, sizeof (GDate));
	g_date_set_dmy (&display_date, (GDateDay) 1, (gint) month, year);
	_tmp1_ = display_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp1_, &_tmp2_);
	self->priv->display_start_date = _tmp2_;
	_tmp3_ = g_date_copy (&display_date);
	_tmp4_ = _tmp3_;
	self->priv->display_end_date = *_tmp4_;
	_g_free0 (_tmp4_);
	g_date_add_months (&self->priv->display_end_date, 1U);
	_tmp5_ = self->priv->display_end_date;
	ft_timeframe_normalize_date (FT_TIMEFRAME_WEEK, &_tmp5_, &_tmp6_);
	self->priv->display_end_date = _tmp6_;
	if (g_date_get_month (&self->priv->display_end_date) == g_date_get_month (&display_date)) {
		g_date_add_days (&self->priv->display_end_date, 7U);
	}
	g_date_subtract_days (&self->priv->display_end_date, 1U);
	ft_week_chooser_update (self);
	if (gtk_widget_get_mapped ((GtkWidget*) self)) {
		g_signal_emit (self, ft_week_chooser_signals[FT_WEEK_CHOOSER_DISPLAY_CHANGED_SIGNAL], 0, self->priv->_display_month, self->priv->_display_year);
	}
}

void
ft_week_chooser_set_selected_date_full (FtWeekChooser* self,
                                        GDate* value,
                                        GDateMonth display_month,
                                        GDateYear display_year)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = g_date_copy (value);
	_tmp1_ = _tmp0_;
	self->priv->_selected_date = *_tmp1_;
	_g_free0 (_tmp1_);
	if (!g_date_valid (&self->priv->_selected_date)) {
		ft_week_chooser_update_selection (self);
		return;
	}
	if (self->priv->_display_month != display_month) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = self->priv->_display_year != display_year;
	}
	if (_tmp2_) {
		ft_week_chooser_set_display_month_year (self, display_month, display_year);
	} else {
		ft_week_chooser_update_selection (self);
	}
}

static Block11Data*
block11_data_ref (Block11Data* _data11_)
{
	g_atomic_int_inc (&_data11_->_ref_count_);
	return _data11_;
}

static void
block11_data_unref (void * _userdata_)
{
	Block11Data* _data11_;
	_data11_ = (Block11Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data11_->_ref_count_)) {
		FtWeekChooser* self;
		self = _data11_->self;
		_g_free0 (_data11_->date_copy);
		_g_object_unref0 (self);
		g_slice_free (Block11Data, _data11_);
	}
}

static void
__lambda22_ (Block11Data* _data11_)
{
	FtWeekChooser* self;
	GDate _tmp0_;
	self = _data11_->self;
	_tmp0_ = *_data11_->date_copy;
	ft_week_chooser_select (_data11_->_self_, &_tmp0_);
}

static void
___lambda22__gtk_button_clicked (GtkButton* _sender,
                                 gpointer self)
{
	__lambda22_ (self);
}

static GtkButton*
ft_week_chooser_create_week_button (FtWeekChooser* self,
                                    GDate* date,
                                    guint week_number)
{
	Block11Data* _data11_;
	GtkBox* box = NULL;
	GtkBox* _tmp0_;
	GtkBox* _tmp1_;
	GtkLabel* week_label = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GtkLabel* _tmp4_;
	GtkLabel* _tmp5_;
	GtkLabel* _tmp6_;
	GtkBox* _tmp7_;
	GtkLabel* _tmp8_;
	GDate* day_date = NULL;
	GDate* _tmp9_;
	GtkButton* button = NULL;
	GtkButton* _tmp23_;
	GtkBox* _tmp24_;
	GDate* _tmp25_;
	GtkButton* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_data11_ = g_slice_new0 (Block11Data);
	_data11_->_ref_count_ = 1;
	_data11_->self = g_object_ref (self);
	_tmp0_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
	g_object_ref_sink (_tmp0_);
	box = _tmp0_;
	_tmp1_ = box;
	gtk_box_set_homogeneous (_tmp1_, TRUE);
	_tmp2_ = g_strdup_printf ("%u", week_number);
	_tmp3_ = _tmp2_;
	_tmp4_ = (GtkLabel*) gtk_label_new (_tmp3_);
	g_object_ref_sink (_tmp4_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	week_label = _tmp5_;
	_tmp6_ = week_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp6_, "week-number");
	_tmp7_ = box;
	_tmp8_ = week_label;
	gtk_box_append (_tmp7_, (GtkWidget*) _tmp8_);
	_tmp9_ = g_date_copy (date);
	day_date = _tmp9_;
	{
		gint day = 0;
		day = 1;
		{
			gboolean _tmp10_ = FALSE;
			_tmp10_ = TRUE;
			while (TRUE) {
				GtkLabel* day_label = NULL;
				GDate* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				GtkLabel* _tmp15_;
				GtkLabel* _tmp16_;
				GtkLabel* _tmp17_;
				GDate* _tmp18_;
				GtkBox* _tmp20_;
				GtkLabel* _tmp21_;
				GDate* _tmp22_;
				if (!_tmp10_) {
					gint _tmp11_;
					_tmp11_ = day;
					day = _tmp11_ + 1;
				}
				_tmp10_ = FALSE;
				if (!(day <= FT_WEEK_CHOOSER_DAYS_PER_WEEK)) {
					break;
				}
				_tmp12_ = day_date;
				_tmp13_ = g_strdup_printf ("%hhu", (guchar) g_date_get_day (_tmp12_));
				_tmp14_ = _tmp13_;
				_tmp15_ = (GtkLabel*) gtk_label_new (_tmp14_);
				g_object_ref_sink (_tmp15_);
				_tmp16_ = _tmp15_;
				_g_free0 (_tmp14_);
				day_label = _tmp16_;
				_tmp17_ = day_label;
				gtk_widget_add_css_class ((GtkWidget*) _tmp17_, "day-number");
				_tmp18_ = day_date;
				if (g_date_get_month (_tmp18_) != self->priv->_display_month) {
					GtkLabel* _tmp19_;
					_tmp19_ = day_label;
					gtk_widget_add_css_class ((GtkWidget*) _tmp19_, "dim-label");
				}
				_tmp20_ = box;
				_tmp21_ = day_label;
				gtk_box_append (_tmp20_, (GtkWidget*) _tmp21_);
				_tmp22_ = day_date;
				g_date_add_days (_tmp22_, 1U);
				_g_object_unref0 (day_label);
			}
		}
	}
	_tmp23_ = (GtkButton*) gtk_button_new ();
	g_object_ref_sink (_tmp23_);
	button = _tmp23_;
	gtk_widget_set_halign ((GtkWidget*) button, GTK_ALIGN_FILL);
	gtk_widget_set_valign ((GtkWidget*) button, GTK_ALIGN_FILL);
	g_object_set ((GtkWidget*) button, "height-request", 32, NULL);
	_tmp24_ = box;
	gtk_button_set_child (button, (GtkWidget*) _tmp24_);
	gtk_widget_add_css_class ((GtkWidget*) button, "week");
	gtk_widget_add_css_class ((GtkWidget*) button, "pill");
	gtk_widget_add_css_class ((GtkWidget*) button, "flat");
	_data11_->_self_ = self;
	_tmp25_ = g_date_copy (date);
	_data11_->date_copy = _tmp25_;
	g_signal_connect_data (button, "clicked", (GCallback) ___lambda22__gtk_button_clicked, block11_data_ref (_data11_), (GClosureNotify) block11_data_unref, 0);
	result = button;
	_g_free0 (day_date);
	_g_object_unref0 (week_label);
	_g_object_unref0 (box);
	block11_data_unref (_data11_);
	_data11_ = NULL;
	return result;
}

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

static void
ft_week_chooser_clear_weekdays (FtWeekChooser* self)
{
	GtkWidget* child = NULL;
	GtkBox* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->weekdays_box;
	_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	child = _tmp2_;
	while (TRUE) {
		GtkWidget* _tmp3_;
		GtkWidget* next_child = NULL;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkBox* _tmp7_;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		_tmp3_ = child;
		if (!(_tmp3_ != NULL)) {
			break;
		}
		_tmp4_ = child;
		_tmp5_ = gtk_widget_get_next_sibling (_tmp4_);
		_tmp6_ = _g_object_ref0 (_tmp5_);
		next_child = _tmp6_;
		_tmp7_ = self->priv->weekdays_box;
		_tmp8_ = child;
		gtk_box_remove (_tmp7_, _tmp8_);
		_tmp9_ = next_child;
		_tmp10_ = _g_object_ref0 (_tmp9_);
		_g_object_unref0 (child);
		child = _tmp10_;
		_g_object_unref0 (next_child);
	}
	_g_object_unref0 (child);
}

static void
ft_week_chooser_clear_weeks (FtWeekChooser* self)
{
	GtkWidget* child = NULL;
	GtkGrid* _tmp0_;
	GtkWidget* _tmp1_;
	GtkWidget* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->grid;
	_tmp1_ = gtk_widget_get_first_child ((GtkWidget*) _tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	child = _tmp2_;
	while (TRUE) {
		GtkWidget* _tmp3_;
		GtkWidget* next_child = NULL;
		GtkWidget* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_;
		GtkGrid* _tmp7_;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		GtkWidget* _tmp10_;
		_tmp3_ = child;
		if (!(_tmp3_ != NULL)) {
			break;
		}
		_tmp4_ = child;
		_tmp5_ = gtk_widget_get_next_sibling (_tmp4_);
		_tmp6_ = _g_object_ref0 (_tmp5_);
		next_child = _tmp6_;
		_tmp7_ = self->priv->grid;
		_tmp8_ = child;
		gtk_grid_remove (_tmp7_, _tmp8_);
		_tmp9_ = next_child;
		_tmp10_ = _g_object_ref0 (_tmp9_);
		_g_object_unref0 (child);
		child = _tmp10_;
		_g_object_unref0 (next_child);
	}
	self->priv->selected_button = NULL;
	_g_object_unref0 (child);
}

/**
         * We place weekday labels as first row of the grid.
         */
static gunichar
string_get_char (const gchar* self,
                 glong index)
{
	gunichar result;
	g_return_val_if_fail (self != NULL, 0U);
	result = g_utf8_get_char (((gchar*) self) + index);
	return result;
}

static gchar*
g_unichar_to_string (gunichar self)
{
	gchar* str = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, 7);
	str = (gchar*) _tmp0_;
	g_unichar_to_utf8 (self, str);
	result = str;
	return result;
}

static void
ft_week_chooser_update_weekday_labels (FtWeekChooser* self)
{
	GDate* date = NULL;
	GDate* _tmp0_;
	GtkLabel* hash_label = NULL;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkBox* _tmp4_;
	GtkLabel* _tmp5_;
	g_return_if_fail (self != NULL);
	ft_week_chooser_clear_weekdays (self);
	_tmp0_ = g_date_copy (&self->priv->display_start_date);
	date = _tmp0_;
	_tmp1_ = (GtkLabel*) gtk_label_new ("");
	g_object_ref_sink (_tmp1_);
	hash_label = _tmp1_;
	_tmp2_ = hash_label;
	gtk_label_set_xalign (_tmp2_, 0.5f);
	_tmp3_ = hash_label;
	gtk_label_set_yalign (_tmp3_, 0.5f);
	_tmp4_ = self->priv->weekdays_box;
	_tmp5_ = hash_label;
	gtk_box_append (_tmp4_, (GtkWidget*) _tmp5_);
	{
		gint column = 0;
		column = 0;
		{
			gboolean _tmp6_ = FALSE;
			_tmp6_ = TRUE;
			while (TRUE) {
				gchar* day_name = NULL;
				GDate* _tmp8_;
				GDate _tmp9_;
				gchar* _tmp10_;
				gchar* day_letter = NULL;
				const gchar* _tmp11_;
				gchar* _tmp12_;
				GtkLabel* label = NULL;
				const gchar* _tmp13_;
				GtkLabel* _tmp14_;
				GtkLabel* _tmp15_;
				GtkLabel* _tmp16_;
				GtkBox* _tmp17_;
				GtkLabel* _tmp18_;
				GDate* _tmp19_;
				if (!_tmp6_) {
					gint _tmp7_;
					_tmp7_ = column;
					column = _tmp7_ + 1;
				}
				_tmp6_ = FALSE;
				if (!(column < FT_WEEK_CHOOSER_DAYS_PER_WEEK)) {
					break;
				}
				_tmp8_ = date;
				_tmp9_ = *_tmp8_;
				_tmp10_ = ft_date_utils_format_date (&_tmp9_, "%a");
				day_name = _tmp10_;
				_tmp11_ = day_name;
				_tmp12_ = g_unichar_to_string (g_unichar_toupper (string_get_char (_tmp11_, (glong) 0)));
				day_letter = _tmp12_;
				_tmp13_ = day_letter;
				_tmp14_ = (GtkLabel*) gtk_label_new (_tmp13_);
				g_object_ref_sink (_tmp14_);
				label = _tmp14_;
				_tmp15_ = label;
				gtk_label_set_xalign (_tmp15_, 0.5f);
				_tmp16_ = label;
				gtk_label_set_yalign (_tmp16_, 0.5f);
				_tmp17_ = self->priv->weekdays_box;
				_tmp18_ = label;
				gtk_box_append (_tmp17_, (GtkWidget*) _tmp18_);
				_tmp19_ = date;
				g_date_add_days (_tmp19_, 1U);
				_g_object_unref0 (label);
				_g_free0 (day_letter);
				_g_free0 (day_name);
			}
		}
	}
	_g_object_unref0 (hash_label);
	_g_free0 (date);
}

static void
ft_week_chooser_update_previous_button (FtWeekChooser* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GtkButton* _tmp2_;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (&self->priv->_min_date)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self->priv->_display_month > g_date_get_month (&self->priv->_min_date);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_display_year > g_date_get_year (&self->priv->_min_date);
	}
	_tmp2_ = self->priv->previous_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp2_, _tmp0_);
}

static void
ft_week_chooser_update_next_button (FtWeekChooser* self)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	GtkButton* _tmp2_;
	g_return_if_fail (self != NULL);
	if (!g_date_valid (&self->priv->_max_date)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = self->priv->_display_month < g_date_get_month (&self->priv->_max_date);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = self->priv->_display_year < g_date_get_year (&self->priv->_max_date);
	}
	_tmp2_ = self->priv->next_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp2_, _tmp0_);
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
ft_week_chooser_update_header (FtWeekChooser* self)
{
	gchar* month_name = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gint year = 0;
	GtkLabel* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ft_date_utils_get_month_name (self->priv->_display_month);
	_tmp1_ = _tmp0_;
	_tmp2_ = ft_capitalize_words (_tmp1_);
	_tmp3_ = _tmp2_;
	_g_free0 (_tmp1_);
	month_name = _tmp3_;
	year = (gint) self->priv->_display_year;
	_tmp4_ = self->priv->header_label;
	_tmp5_ = string_to_string (month_name);
	_tmp6_ = g_strdup_printf ("%i", year);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strconcat (_tmp5_, " ", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	gtk_label_set_label (_tmp4_, _tmp9_);
	_g_free0 (_tmp9_);
	_g_free0 (_tmp7_);
	ft_week_chooser_update_previous_button (self);
	ft_week_chooser_update_next_button (self);
	_g_free0 (month_name);
}

static void
ft_week_chooser_create_weeks (FtWeekChooser* self)
{
	GDate* week_start_date = NULL;
	GDate* _tmp0_;
	GDate* week_end_date = NULL;
	GDate* _tmp1_;
	GDate* _tmp2_;
	GDate* _tmp3_;
	GDate year_start_date = {0};
	gboolean is_min_date_valid = FALSE;
	gboolean is_max_date_valid = FALSE;
	GDateWeekday first_day_of_week = 0;
	guint _tmp4_ = 0U;
	guint week_number_offset = 0U;
	gint row = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_copy (&self->priv->display_start_date);
	week_start_date = _tmp0_;
	_tmp1_ = week_start_date;
	_tmp2_ = g_date_copy (_tmp1_);
	week_end_date = _tmp2_;
	_tmp3_ = week_end_date;
	g_date_add_days (_tmp3_, 6U);
	memset (&year_start_date, 0, sizeof (GDate));
	g_date_set_dmy (&year_start_date, (GDateDay) 1, 1, self->priv->_display_year);
	is_min_date_valid = g_date_valid (&self->priv->_min_date);
	is_max_date_valid = g_date_valid (&self->priv->_max_date);
	first_day_of_week = ft_locale_get_first_day_of_week ();
	if (first_day_of_week == G_DATE_MONDAY) {
		_tmp4_ = g_date_get_monday_week_of_year (&year_start_date);
	} else {
		_tmp4_ = g_date_get_sunday_week_of_year (&year_start_date);
	}
	week_number_offset = 1U - _tmp4_;
	row = 0;
	while (TRUE) {
		GDate* _tmp5_;
		GDate _tmp6_;
		guint _tmp7_ = 0U;
		guint week_number = 0U;
		GtkButton* button = NULL;
		GDate* _tmp10_;
		GDate _tmp11_;
		GtkButton* _tmp12_;
		gboolean _tmp13_ = FALSE;
		gboolean _tmp14_ = FALSE;
		GtkButton* _tmp20_;
		GtkGrid* _tmp21_;
		GtkButton* _tmp22_;
		GDate* _tmp23_;
		GDate* _tmp24_;
		gint _tmp25_;
		_tmp5_ = week_start_date;
		_tmp6_ = self->priv->display_end_date;
		if (!(g_date_compare (_tmp5_, &_tmp6_) <= 0)) {
			break;
		}
		if (first_day_of_week == G_DATE_MONDAY) {
			GDate* _tmp8_;
			_tmp8_ = week_end_date;
			_tmp7_ = g_date_get_monday_week_of_year (_tmp8_);
		} else {
			GDate* _tmp9_;
			_tmp9_ = week_end_date;
			_tmp7_ = g_date_get_sunday_week_of_year (_tmp9_);
		}
		week_number = _tmp7_ + week_number_offset;
		_tmp10_ = week_start_date;
		_tmp11_ = *_tmp10_;
		_tmp12_ = ft_week_chooser_create_week_button (self, &_tmp11_, week_number);
		button = _tmp12_;
		if (!is_min_date_valid) {
			_tmp14_ = TRUE;
		} else {
			GDate* _tmp15_;
			GDate _tmp16_;
			_tmp15_ = week_end_date;
			_tmp16_ = *_tmp15_;
			_tmp14_ = g_date_compare (&self->priv->_min_date, &_tmp16_) <= 0;
		}
		if (_tmp14_) {
			gboolean _tmp17_ = FALSE;
			if (!is_max_date_valid) {
				_tmp17_ = TRUE;
			} else {
				GDate* _tmp18_;
				GDate _tmp19_;
				_tmp18_ = week_start_date;
				_tmp19_ = *_tmp18_;
				_tmp17_ = g_date_compare (&self->priv->_max_date, &_tmp19_) >= 0;
			}
			_tmp13_ = _tmp17_;
		} else {
			_tmp13_ = FALSE;
		}
		_tmp20_ = button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp20_, _tmp13_);
		_tmp21_ = self->priv->grid;
		_tmp22_ = button;
		gtk_grid_attach (_tmp21_, (GtkWidget*) _tmp22_, 0, row, 1, 1);
		_tmp23_ = week_start_date;
		g_date_add_days (_tmp23_, 7U);
		_tmp24_ = week_end_date;
		g_date_add_days (_tmp24_, 7U);
		_tmp25_ = row;
		row = _tmp25_ + 1;
		_g_object_unref0 (button);
	}
	_g_free0 (week_end_date);
	_g_free0 (week_start_date);
}

static void
ft_week_chooser_update_weeks (FtWeekChooser* self)
{
	g_return_if_fail (self != NULL);
	if (!gtk_widget_get_mapped ((GtkWidget*) self)) {
		return;
	}
	ft_week_chooser_clear_weeks (self);
	ft_week_chooser_create_weeks (self);
}

static void
ft_week_chooser_update_selection (FtWeekChooser* self)
{
	GtkWidget* _tmp0_;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->selected_button;
	if (_tmp0_ != NULL) {
		GtkWidget* _tmp1_;
		_tmp1_ = self->priv->selected_button;
		gtk_widget_unset_state_flags (_tmp1_, GTK_STATE_FLAG_SELECTED);
		self->priv->selected_button = NULL;
	}
	if (g_date_valid (&self->priv->display_start_date)) {
		_tmp2_ = g_date_valid (&self->priv->_selected_date);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		gint position = 0;
		GDate _tmp3_;
		gint row = 0;
		GtkGrid* _tmp4_;
		GtkWidget* _tmp5_;
		GtkWidget* _tmp6_ = NULL;
		GtkWidget* _tmp7_;
		_tmp3_ = self->priv->_selected_date;
		position = g_date_days_between (&self->priv->display_start_date, &_tmp3_);
		row = position / FT_WEEK_CHOOSER_DAYS_PER_WEEK;
		_tmp4_ = self->priv->grid;
		_tmp5_ = gtk_grid_get_child_at (_tmp4_, 0, row);
		self->priv->selected_button = _tmp5_;
		_tmp7_ = self->priv->selected_button;
		_tmp6_ = _tmp7_;
		if (_tmp6_ != NULL) {
			gtk_widget_set_state_flags (_tmp6_, GTK_STATE_FLAG_SELECTED, FALSE);
		}
	}
}

static void
ft_week_chooser_update (FtWeekChooser* self)
{
	g_return_if_fail (self != NULL);
	ft_week_chooser_update_header (self);
	ft_week_chooser_update_weekday_labels (self);
	ft_week_chooser_update_weeks (self);
	ft_week_chooser_update_selection (self);
}

static void
ft_week_chooser_on_previous_button_clicked (FtWeekChooser* self)
{
	GDateMonth month = 0;
	GDateYear year = (GDateYear) 0U;
	g_return_if_fail (self != NULL);
	month = self->priv->_display_month;
	year = self->priv->_display_year;
	if (month == G_DATE_JANUARY) {
		GDateYear _tmp0_;
		_tmp0_ = year;
		year = _tmp0_ - 1;
		month = G_DATE_DECEMBER;
	} else {
		month = (GDateMonth) (ft_date_utils_get_month_number (month) - 1U);
	}
	ft_week_chooser_set_display_month_year (self, month, year);
}

static void
_ft_week_chooser_on_previous_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self)
{
	ft_week_chooser_on_previous_button_clicked ((FtWeekChooser*) self);
}

static void
ft_week_chooser_on_next_button_clicked (FtWeekChooser* self)
{
	GDateMonth month = 0;
	GDateYear year = (GDateYear) 0U;
	g_return_if_fail (self != NULL);
	month = self->priv->_display_month;
	year = self->priv->_display_year;
	if (month == G_DATE_DECEMBER) {
		GDateYear _tmp0_;
		_tmp0_ = year;
		year = _tmp0_ + 1;
		month = G_DATE_JANUARY;
	} else {
		month = (GDateMonth) (ft_date_utils_get_month_number (month) + 1U);
	}
	ft_week_chooser_set_display_month_year (self, month, year);
}

static void
_ft_week_chooser_on_next_button_clicked_gtk_button_clicked (GtkButton* _sender,
                                                            gpointer self)
{
	ft_week_chooser_on_next_button_clicked ((FtWeekChooser*) self);
}

static gboolean
ft_week_chooser_select (FtWeekChooser* self,
                        GDate* date)
{
	gboolean _tmp0_ = FALSE;
	GDate _tmp2_;
	GDate _tmp3_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (date != NULL, FALSE);
	if (!g_date_valid (date)) {
		result = FALSE;
		return result;
	}
	if (g_date_valid (&self->priv->_selected_date)) {
		GDate _tmp1_;
		_tmp1_ = *date;
		_tmp0_ = g_date_compare (&self->priv->_selected_date, &_tmp1_) == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	_tmp2_ = *date;
	ft_week_chooser_set_selected_date (self, &_tmp2_);
	_tmp3_ = self->priv->_selected_date;
	g_signal_emit (self, ft_week_chooser_signals[FT_WEEK_CHOOSER_SELECTED_SIGNAL], 0, &_tmp3_);
	result = TRUE;
	return result;
}

void
ft_week_chooser_reset (FtWeekChooser* self)
{
	g_return_if_fail (self != NULL);
	if (g_date_valid (&self->priv->_selected_date)) {
		ft_week_chooser_set_display_month_year (self, g_date_get_month (&self->priv->_selected_date), g_date_get_year (&self->priv->_selected_date));
	} else {
		GDate today = {0};
		GDate _tmp0_ = {0};
		ft_date_utils_get_today (&_tmp0_);
		today = _tmp0_;
		ft_week_chooser_set_display_month_year (self, g_date_get_month (&today), g_date_get_year (&today));
	}
}

static void
ft_week_chooser_real_map (GtkWidget* base)
{
	FtWeekChooser * self;
	self = (FtWeekChooser*) base;
	ft_week_chooser_reset (self);
	ft_week_chooser_create_weeks (self);
	ft_week_chooser_update_selection (self);
	GTK_WIDGET_CLASS (ft_week_chooser_parent_class)->map ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
}

static void
ft_week_chooser_real_unmap (GtkWidget* base)
{
	FtWeekChooser * self;
	self = (FtWeekChooser*) base;
	GTK_WIDGET_CLASS (ft_week_chooser_parent_class)->unmap ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
	ft_week_chooser_clear_weeks (self);
}

static void
ft_week_chooser_real_dispose (GObject* base)
{
	FtWeekChooser * self;
	self = (FtWeekChooser*) base;
	self->priv->selected_button = NULL;
	G_OBJECT_CLASS (ft_week_chooser_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, adw_bin_get_type (), AdwBin));
}

FtWeekChooser*
ft_week_chooser_construct (GType object_type)
{
	FtWeekChooser * self = NULL;
	self = (FtWeekChooser*) g_object_new (object_type, NULL);
	return self;
}

FtWeekChooser*
ft_week_chooser_new (void)
{
	return ft_week_chooser_construct (FT_TYPE_WEEK_CHOOSER);
}

void
ft_week_chooser_get_selected_date (FtWeekChooser* self,
                                   GDate * result)
{
	GDate _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_selected_date;
	*result = _tmp0_;
	return;
}

void
ft_week_chooser_set_selected_date (FtWeekChooser* self,
                                   GDate * value)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	GDateMonth display_month = 0;
	GDateYear display_year = (GDateYear) 0U;
	gboolean _tmp2_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_copy (value);
	_tmp1_ = _tmp0_;
	self->priv->_selected_date = *_tmp1_;
	_g_free0 (_tmp1_);
	if (!g_date_valid (&self->priv->_selected_date)) {
		ft_week_chooser_update_selection (self);
		return;
	}
	display_month = g_date_get_month (&self->priv->_selected_date);
	display_year = g_date_get_year (&self->priv->_selected_date);
	if (self->priv->_display_month != display_month) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = self->priv->_display_year != display_year;
	}
	if (_tmp2_) {
		ft_week_chooser_set_display_month_year (self, display_month, display_year);
	} else {
		ft_week_chooser_update_selection (self);
	}
	g_object_notify_by_pspec ((GObject *) self, ft_week_chooser_properties[FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY]);
}

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

void
ft_week_chooser_set_min_date (FtWeekChooser* self,
                              GDate * value)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_copy (value);
	_tmp1_ = _tmp0_;
	self->priv->_min_date = *_tmp1_;
	_g_free0 (_tmp1_);
	ft_week_chooser_update_previous_button (self);
	g_object_notify_by_pspec ((GObject *) self, ft_week_chooser_properties[FT_WEEK_CHOOSER_MIN_DATE_PROPERTY]);
}

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

void
ft_week_chooser_set_max_date (FtWeekChooser* self,
                              GDate * value)
{
	GDate* _tmp0_;
	GDate* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_date_copy (value);
	_tmp1_ = _tmp0_;
	self->priv->_max_date = *_tmp1_;
	_g_free0 (_tmp1_);
	ft_week_chooser_update_next_button (self);
	g_object_notify_by_pspec ((GObject *) self, ft_week_chooser_properties[FT_WEEK_CHOOSER_MAX_DATE_PROPERTY]);
}

GDateMonth
ft_week_chooser_get_display_month (FtWeekChooser* self)
{
	GDateMonth result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_display_month;
	return result;
}

GDateYear
ft_week_chooser_get_display_year (FtWeekChooser* self)
{
	GDateYear result;
	g_return_val_if_fail (self != NULL, (GDateYear) 0U);
	result = self->priv->_display_year;
	return result;
}

static void
g_cclosure_user_marshal_VOID__INT_UINT (GClosure * closure,
                                        GValue * return_value,
                                        guint n_param_values,
                                        const GValue * param_values,
                                        gpointer invocation_hint,
                                        gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__INT_UINT) (gpointer data1, gint arg_1, GDateYear arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_UINT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	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__INT_UINT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_uint (param_values + 2), data2);
}

static void
ft_week_chooser_class_init (FtWeekChooserClass * klass,
                            gpointer klass_data)
{
	ft_week_chooser_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtWeekChooser_private_offset);
	((GtkWidgetClass *) klass)->map = (void (*) (GtkWidget*)) ft_week_chooser_real_map;
	((GtkWidgetClass *) klass)->unmap = (void (*) (GtkWidget*)) ft_week_chooser_real_unmap;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_week_chooser_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_week_chooser_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_week_chooser_set_property;
	G_OBJECT_CLASS (klass)->finalize = ft_week_chooser_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY, ft_week_chooser_properties[FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY] = g_param_spec_boxed ("selected-date", "selected-date", "selected-date", G_TYPE_DATE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_WEEK_CHOOSER_MIN_DATE_PROPERTY, ft_week_chooser_properties[FT_WEEK_CHOOSER_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_WEEK_CHOOSER_MAX_DATE_PROPERTY, ft_week_chooser_properties[FT_WEEK_CHOOSER_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));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_WEEK_CHOOSER_DISPLAY_MONTH_PROPERTY, ft_week_chooser_properties[FT_WEEK_CHOOSER_DISPLAY_MONTH_PROPERTY] = g_param_spec_int ("display-month", "display-month", "display-month", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_WEEK_CHOOSER_DISPLAY_YEAR_PROPERTY, ft_week_chooser_properties[FT_WEEK_CHOOSER_DISPLAY_YEAR_PROPERTY] = g_param_spec_uint ("display-year", "display-year", "display-year", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/widgets/week-chooser.ui");
	ft_week_chooser_signals[FT_WEEK_CHOOSER_SELECTED_SIGNAL] = g_signal_new ("selected", FT_TYPE_WEEK_CHOOSER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_DATE);
	ft_week_chooser_signals[FT_WEEK_CHOOSER_DISPLAY_CHANGED_SIGNAL] = g_signal_new ("display-changed", FT_TYPE_WEEK_CHOOSER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_UINT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_UINT);
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "header_label", FALSE, FtWeekChooser_private_offset + G_STRUCT_OFFSET (FtWeekChooserPrivate, header_label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "previous_button", FALSE, FtWeekChooser_private_offset + G_STRUCT_OFFSET (FtWeekChooserPrivate, previous_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "next_button", FALSE, FtWeekChooser_private_offset + G_STRUCT_OFFSET (FtWeekChooserPrivate, next_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "weekdays_box", FALSE, FtWeekChooser_private_offset + G_STRUCT_OFFSET (FtWeekChooserPrivate, weekdays_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "grid", FALSE, FtWeekChooser_private_offset + G_STRUCT_OFFSET (FtWeekChooserPrivate, grid));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_previous_button_clicked", G_CALLBACK(_ft_week_chooser_on_previous_button_clicked_gtk_button_clicked));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_next_button_clicked", G_CALLBACK(_ft_week_chooser_on_next_button_clicked_gtk_button_clicked));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "calendar");
}

static void
ft_week_chooser_instance_init (FtWeekChooser * self,
                               gpointer klass)
{
	self->priv = ft_week_chooser_get_instance_private (self);
	self->priv->selected_button = NULL;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_week_chooser_finalize (GObject * obj)
{
	FtWeekChooser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_WEEK_CHOOSER, FtWeekChooser);
	G_OBJECT_CLASS (ft_week_chooser_parent_class)->finalize (obj);
}

static GType
ft_week_chooser_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtWeekChooserClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_week_chooser_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtWeekChooser), 0, (GInstanceInitFunc) ft_week_chooser_instance_init, NULL };
	GType ft_week_chooser_type_id;
	ft_week_chooser_type_id = g_type_register_static (adw_bin_get_type (), "FtWeekChooser", &g_define_type_info, 0);
	FtWeekChooser_private_offset = g_type_add_instance_private (ft_week_chooser_type_id, sizeof (FtWeekChooserPrivate));
	return ft_week_chooser_type_id;
}

GType
ft_week_chooser_get_type (void)
{
	static volatile gsize ft_week_chooser_type_id__once = 0;
	if (g_once_init_enter (&ft_week_chooser_type_id__once)) {
		GType ft_week_chooser_type_id;
		ft_week_chooser_type_id = ft_week_chooser_get_type_once ();
		g_once_init_leave (&ft_week_chooser_type_id__once, ft_week_chooser_type_id);
	}
	return ft_week_chooser_type_id__once;
}

static void
_vala_ft_week_chooser_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec)
{
	FtWeekChooser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_WEEK_CHOOSER, FtWeekChooser);
	switch (property_id) {
		case FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY:
		{
			GDate boxed;
			ft_week_chooser_get_selected_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_WEEK_CHOOSER_MIN_DATE_PROPERTY:
		{
			GDate boxed;
			ft_week_chooser_get_min_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_WEEK_CHOOSER_MAX_DATE_PROPERTY:
		{
			GDate boxed;
			ft_week_chooser_get_max_date (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case FT_WEEK_CHOOSER_DISPLAY_MONTH_PROPERTY:
		g_value_set_int (value, ft_week_chooser_get_display_month (self));
		break;
		case FT_WEEK_CHOOSER_DISPLAY_YEAR_PROPERTY:
		g_value_set_uint (value, ft_week_chooser_get_display_year (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_week_chooser_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec)
{
	FtWeekChooser * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_WEEK_CHOOSER, FtWeekChooser);
	switch (property_id) {
		case FT_WEEK_CHOOSER_SELECTED_DATE_PROPERTY:
		ft_week_chooser_set_selected_date (self, g_value_get_boxed (value));
		break;
		case FT_WEEK_CHOOSER_MIN_DATE_PROPERTY:
		ft_week_chooser_set_min_date (self, g_value_get_boxed (value));
		break;
		case FT_WEEK_CHOOSER_MAX_DATE_PROPERTY:
		ft_week_chooser_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;
}

