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

/*
 * Copyright © 2023 Alain M. (https://github.com/alainm23/planify)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 *
 * Authored by: Alain M. <alainmh23@gmail.com>
 */

#include "planify.h"
#include <gtk/gtk.h>
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <adwaita.h>
#include <glib/gi18n-lib.h>
#include <float.h>
#include <math.h>

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

enum  {
	WIDGETS_CALENDAR_CALENDAR_MONTH_0_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_MONTH_CURRENT_DATE_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_MONTH_NUM_PROPERTIES
};
static GParamSpec* widgets_calendar_calendar_month_properties[WIDGETS_CALENDAR_CALENDAR_MONTH_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
typedef struct _Block22Data Block22Data;
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	WIDGETS_CALENDAR_CALENDAR_MONTH_DAY_SELECTED_SIGNAL,
	WIDGETS_CALENDAR_CALENDAR_MONTH_CHOOSE_DATE_CLICKED_SIGNAL,
	WIDGETS_CALENDAR_CALENDAR_MONTH_NUM_SIGNALS
};
static guint widgets_calendar_calendar_month_signals[WIDGETS_CALENDAR_CALENDAR_MONTH_NUM_SIGNALS] = {0};

struct _WidgetsCalendarCalendarMonthPrivate {
	WidgetsCalendarCalendarWeek* calendar_week;
	GtkGrid* days_grid;
	GeeArrayList* days_arraylist;
	WidgetsContextMenuMenuItem* date_item;
	GDateTime* _current_date;
	GDateTime* _date;
	GeeHashMap* signals_map;
};

struct _Block22Data {
	int _ref_count_;
	WidgetsCalendarCalendarMonth* self;
	WidgetsCalendarCalendarDay* calendar_day;
};

static gint WidgetsCalendarCalendarMonth_private_offset;
static gpointer widgets_calendar_calendar_month_parent_class = NULL;

static void widgets_calendar_calendar_month_fill_days (WidgetsCalendarCalendarMonth* self);
static Block22Data* block22_data_ref (Block22Data* _data22_);
static void block22_data_unref (void * _userdata_);
static void _____lambda141_ (Block22Data* _data22_);
static void widgets_calendar_calendar_month_day_selected_style (WidgetsCalendarCalendarMonth* self,
                                                         WidgetsCalendarCalendarDay* selected_day);
static void ______lambda141__widgets_calendar_calendar_day_day_selected (WidgetsCalendarCalendarDay* _sender,
                                                                  gpointer self);
static void widgets_calendar_calendar_month_select_date (WidgetsCalendarCalendarMonth* self,
                                                  GDateTime* date);
static GObject * widgets_calendar_calendar_month_constructor (GType type,
                                                       guint n_construct_properties,
                                                       GObjectConstructParam * construct_properties);
static void _widgets_calendar_calendar_month___lambda142_ (WidgetsCalendarCalendarMonth* self);
static void __widgets_calendar_calendar_month___lambda142__services_event_bus_day_changed (ServicesEventBus* _sender,
                                                                                    gpointer self);
static void _widgets_calendar_calendar_month___lambda143_ (WidgetsCalendarCalendarMonth* self);
static void __widgets_calendar_calendar_month___lambda143__g_settings_changed (GSettings* _sender,
                                                                        const gchar* key,
                                                                        gpointer self);
static void _widgets_calendar_calendar_month___lambda144_ (WidgetsCalendarCalendarMonth* self);
static void __widgets_calendar_calendar_month___lambda144__gtk_widget_destroy (GtkWidget* _sender,
                                                                        gpointer self);
static void _widgets_calendar_calendar_month___lambda145_ (WidgetsCalendarCalendarMonth* self);
static void __widgets_calendar_calendar_month___lambda145__gtk_button_clicked (GtkButton* _sender,
                                                                        gpointer self);
static void widgets_calendar_calendar_month_finalize (GObject * obj);
static GType widgets_calendar_calendar_month_get_type_once (void);
static void _vala_widgets_calendar_calendar_month_get_property (GObject * object,
                                                         guint property_id,
                                                         GValue * value,
                                                         GParamSpec * pspec);
static void _vala_widgets_calendar_calendar_month_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
widgets_calendar_calendar_month_get_instance_private (WidgetsCalendarCalendarMonth* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsCalendarCalendarMonth_private_offset);
}

WidgetsCalendarCalendarMonth*
widgets_calendar_calendar_month_construct (GType object_type)
{
	WidgetsCalendarCalendarMonth * self = NULL;
	self = (WidgetsCalendarCalendarMonth*) g_object_new (object_type, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
	return self;
}

WidgetsCalendarCalendarMonth*
widgets_calendar_calendar_month_new (void)
{
	return widgets_calendar_calendar_month_construct (WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH);
}

static gpointer
_g_date_time_ref0 (gpointer self)
{
	return self ? g_date_time_ref (self) : NULL;
}

static Block22Data*
block22_data_ref (Block22Data* _data22_)
{
	g_atomic_int_inc (&_data22_->_ref_count_);
	return _data22_;
}

static void
block22_data_unref (void * _userdata_)
{
	Block22Data* _data22_;
	_data22_ = (Block22Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data22_->_ref_count_)) {
		WidgetsCalendarCalendarMonth* self;
		self = _data22_->self;
		_g_object_unref0 (_data22_->calendar_day);
		_g_object_unref0 (self);
		g_slice_free (Block22Data, _data22_);
	}
}

static void
_____lambda141_ (Block22Data* _data22_)
{
	WidgetsCalendarCalendarMonth* self;
	WidgetsCalendarCalendarDay* _tmp0_;
	self = _data22_->self;
	_tmp0_ = _data22_->calendar_day;
	widgets_calendar_calendar_month_day_selected_style (self, _tmp0_);
}

static void
______lambda141__widgets_calendar_calendar_day_day_selected (WidgetsCalendarCalendarDay* _sender,
                                                             gpointer self)
{
	_____lambda141_ (self);
}

static void
widgets_calendar_calendar_month_fill_days (WidgetsCalendarCalendarMonth* self)
{
	GeeArrayList* _tmp12_;
	GDateTime* today = NULL;
	GDateTime* _tmp13_;
	GDateTime* _tmp14_;
	GDateTime* _tmp15_;
	gint start_week = 0;
	ServicesSettings* _tmp16_;
	ServicesSettings* _tmp17_;
	GSettings* _tmp18_;
	gint _tmp19_;
	gint today_dow = 0;
	GDateTime* _tmp20_;
	gint col = 0;
	gint row = 0;
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		GeeArrayList* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		_tmp0_ = self->priv->days_arraylist;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		i = _tmp2_ - 1;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				GtkGrid* _tmp5_;
				GeeArrayList* _tmp6_;
				gpointer _tmp7_;
				WidgetsCalendarCalendarDay* _tmp8_;
				GeeArrayList* _tmp9_;
				gpointer _tmp10_;
				WidgetsCalendarCalendarDay* _tmp11_;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ - 1;
				}
				_tmp3_ = FALSE;
				if (!(i >= 0)) {
					break;
				}
				_tmp5_ = self->priv->days_grid;
				_tmp6_ = self->priv->days_arraylist;
				_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, i);
				_tmp8_ = (WidgetsCalendarCalendarDay*) _tmp7_;
				gtk_grid_remove (_tmp5_, (GtkWidget*) _tmp8_);
				_g_object_unref0 (_tmp8_);
				_tmp9_ = self->priv->days_arraylist;
				_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, i);
				_tmp11_ = (WidgetsCalendarCalendarDay*) _tmp10_;
				widgets_calendar_calendar_day_clean_up (_tmp11_);
				_g_object_unref0 (_tmp11_);
			}
		}
	}
	_tmp12_ = self->priv->days_arraylist;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp12_);
	_tmp13_ = widgets_calendar_calendar_month_get_current_date (self);
	_tmp14_ = _tmp13_;
	_tmp15_ = _g_date_time_ref0 (_tmp14_);
	today = _tmp15_;
	_tmp16_ = services_settings_get_default ();
	_tmp17_ = _tmp16_;
	_tmp18_ = _tmp17_->settings;
	_tmp19_ = g_settings_get_enum (_tmp18_, "start-week");
	_g_object_unref0 (_tmp17_);
	start_week = _tmp19_;
	_tmp20_ = today;
	today_dow = g_date_time_get_day_of_week (_tmp20_) % 7;
	col = ((today_dow - start_week) + 7) % 7;
	row = 0;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp21_ = FALSE;
			_tmp21_ = TRUE;
			while (TRUE) {
				Block22Data* _data22_;
				GDateTime* day_datetime = NULL;
				GDateTime* _tmp23_;
				GDateTime* _tmp24_;
				WidgetsCalendarCalendarDay* _tmp25_;
				WidgetsCalendarCalendarDay* _tmp26_;
				GDateTime* _tmp27_;
				WidgetsCalendarCalendarDay* _tmp28_;
				GDateTime* _tmp29_;
				WidgetsCalendarCalendarDay* _tmp30_;
				GDateTime* _tmp31_;
				gchar* _tmp32_;
				gchar* _tmp33_;
				gboolean _tmp37_ = FALSE;
				GDateTime* _tmp38_;
				GeeHashMap* _tmp43_;
				WidgetsCalendarCalendarDay* _tmp44_;
				gulong _tmp45_;
				WidgetsCalendarCalendarDay* _tmp46_;
				GtkGrid* _tmp47_;
				WidgetsCalendarCalendarDay* _tmp48_;
				GeeArrayList* _tmp49_;
				WidgetsCalendarCalendarDay* _tmp50_;
				gint _tmp51_;
				_data22_ = g_slice_new0 (Block22Data);
				_data22_->_ref_count_ = 1;
				_data22_->self = g_object_ref (self);
				if (!_tmp21_) {
					gint _tmp22_;
					_tmp22_ = i;
					i = _tmp22_ + 1;
				}
				_tmp21_ = FALSE;
				if (!(i < WIDGETS_CALENDAR_CALENDAR_MONTH_TOTAL_DAYS)) {
					block22_data_unref (_data22_);
					_data22_ = NULL;
					break;
				}
				_tmp23_ = today;
				_tmp24_ = g_date_time_add_days (_tmp23_, i);
				day_datetime = _tmp24_;
				_tmp25_ = widgets_calendar_calendar_day_new ();
				g_object_ref_sink (_tmp25_);
				_data22_->calendar_day = _tmp25_;
				_tmp26_ = _data22_->calendar_day;
				_tmp27_ = day_datetime;
				widgets_calendar_calendar_day_set_day (_tmp26_, g_date_time_get_day_of_month (_tmp27_));
				_tmp28_ = _data22_->calendar_day;
				_tmp29_ = day_datetime;
				widgets_calendar_calendar_day_set_date (_tmp28_, _tmp29_);
				_tmp30_ = _data22_->calendar_day;
				_tmp31_ = day_datetime;
				_tmp32_ = utils_datetime_get_relative_date_from_date (_tmp31_);
				_tmp33_ = _tmp32_;
				gtk_widget_set_tooltip_text ((GtkWidget*) _tmp30_, _tmp33_);
				_g_free0 (_tmp33_);
				if (i == 0) {
					WidgetsCalendarCalendarDay* _tmp34_;
					GtkWidget* _tmp35_;
					GtkWidget* _tmp36_;
					_tmp34_ = _data22_->calendar_day;
					_tmp35_ = adw_bin_get_child ((AdwBin*) _tmp34_);
					_tmp36_ = _tmp35_;
					gtk_widget_add_css_class (_tmp36_, "today");
				}
				_tmp38_ = day_datetime;
				if (g_date_time_get_day_of_month (_tmp38_) == 1) {
					GDateTime* _tmp39_;
					GDateTime* _tmp40_;
					_tmp39_ = day_datetime;
					_tmp40_ = today;
					_tmp37_ = g_date_time_get_month (_tmp39_) != g_date_time_get_month (_tmp40_);
				} else {
					_tmp37_ = FALSE;
				}
				if (_tmp37_) {
					WidgetsCalendarCalendarDay* _tmp41_;
					WidgetsCalendarCalendarDay* _tmp42_;
					_tmp41_ = _data22_->calendar_day;
					widgets_calendar_calendar_day_set_show_month (_tmp41_, TRUE);
					_tmp42_ = _data22_->calendar_day;
					widgets_calendar_calendar_day_add_day_css_class (_tmp42_, "caption");
				}
				_tmp43_ = self->priv->signals_map;
				_tmp44_ = _data22_->calendar_day;
				_tmp45_ = g_signal_connect_data (_tmp44_, "day-selected", (GCallback) ______lambda141__widgets_calendar_calendar_day_day_selected, block22_data_ref (_data22_), (GClosureNotify) block22_data_unref, 0);
				_tmp46_ = _data22_->calendar_day;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp43_, (gpointer) ((guintptr) _tmp45_), (GObject*) _tmp46_);
				_tmp47_ = self->priv->days_grid;
				_tmp48_ = _data22_->calendar_day;
				gtk_grid_attach (_tmp47_, (GtkWidget*) _tmp48_, col, row, 1, 1);
				_tmp49_ = self->priv->days_arraylist;
				_tmp50_ = _data22_->calendar_day;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp49_, _tmp50_);
				_tmp51_ = col;
				col = _tmp51_ + 1;
				if (col >= 7) {
					gint _tmp52_;
					col = 0;
					_tmp52_ = row;
					row = _tmp52_ + 1;
				}
				_g_date_time_unref0 (day_datetime);
				block22_data_unref (_data22_);
				_data22_ = NULL;
			}
		}
	}
	_g_date_time_unref0 (today);
}

static void
widgets_calendar_calendar_month_day_selected_style (WidgetsCalendarCalendarMonth* self,
                                                    WidgetsCalendarCalendarDay* selected_day)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GtkWidget* _tmp14_;
	GtkWidget* _tmp15_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (selected_day != NULL);
	_tmp0_ = widgets_calendar_calendar_day_get_date (selected_day);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_date_time_ref0 (_tmp1_);
	_g_date_time_unref0 (self->priv->_date);
	self->priv->_date = _tmp2_;
	g_signal_emit (self, widgets_calendar_calendar_month_signals[WIDGETS_CALENDAR_CALENDAR_MONTH_DAY_SELECTED_SIGNAL], 0);
	{
		GeeArrayList* _day_item_list = NULL;
		GeeArrayList* _tmp3_;
		gint _day_item_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _day_item_index = 0;
		_tmp3_ = self->priv->days_arraylist;
		_day_item_list = _tmp3_;
		_tmp4_ = _day_item_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_day_item_size = _tmp6_;
		_day_item_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			WidgetsCalendarCalendarDay* day_item = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			WidgetsCalendarCalendarDay* _tmp11_;
			GtkWidget* _tmp12_;
			GtkWidget* _tmp13_;
			_day_item_index = _day_item_index + 1;
			_tmp7_ = _day_item_index;
			_tmp8_ = _day_item_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _day_item_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _day_item_index);
			day_item = (WidgetsCalendarCalendarDay*) _tmp10_;
			_tmp11_ = day_item;
			_tmp12_ = adw_bin_get_child ((AdwBin*) _tmp11_);
			_tmp13_ = _tmp12_;
			gtk_widget_remove_css_class (_tmp13_, "selected");
			_g_object_unref0 (day_item);
		}
	}
	_tmp14_ = adw_bin_get_child ((AdwBin*) selected_day);
	_tmp15_ = _tmp14_;
	gtk_widget_add_css_class (_tmp15_, "selected");
}

static void
widgets_calendar_calendar_month_select_date (WidgetsCalendarCalendarMonth* self,
                                             GDateTime* date)
{
	GDateTime* today = NULL;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* max_date = NULL;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	gboolean _tmp5_ = FALSE;
	GDateTime* _tmp6_;
	gboolean is_in_range = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = widgets_calendar_calendar_month_get_current_date (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_date_time_ref0 (_tmp1_);
	today = _tmp2_;
	_tmp3_ = today;
	_tmp4_ = g_date_time_add_days (_tmp3_, WIDGETS_CALENDAR_CALENDAR_MONTH_TOTAL_DAYS - 1);
	max_date = _tmp4_;
	_tmp6_ = today;
	if (g_date_time_compare (date, _tmp6_) >= 0) {
		GDateTime* _tmp7_;
		_tmp7_ = max_date;
		_tmp5_ = g_date_time_compare (date, _tmp7_) <= 0;
	} else {
		_tmp5_ = FALSE;
	}
	is_in_range = _tmp5_;
	if (is_in_range) {
		WidgetsContextMenuMenuItem* _tmp8_;
		_tmp8_ = self->priv->date_item;
		widgets_context_menu_menu_item_set_title (_tmp8_, _ ("Choose a date"));
		{
			GeeArrayList* _day_item_list = NULL;
			GeeArrayList* _tmp9_;
			gint _day_item_size = 0;
			GeeArrayList* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			gint _day_item_index = 0;
			_tmp9_ = self->priv->days_arraylist;
			_day_item_list = _tmp9_;
			_tmp10_ = _day_item_list;
			_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
			_tmp12_ = _tmp11_;
			_day_item_size = _tmp12_;
			_day_item_index = -1;
			while (TRUE) {
				gint _tmp13_;
				gint _tmp14_;
				WidgetsCalendarCalendarDay* day_item = NULL;
				GeeArrayList* _tmp15_;
				gpointer _tmp16_;
				WidgetsCalendarCalendarDay* _tmp17_;
				GtkWidget* _tmp18_;
				GtkWidget* _tmp19_;
				gboolean _tmp20_ = FALSE;
				gboolean _tmp21_ = FALSE;
				WidgetsCalendarCalendarDay* _tmp22_;
				GDateTime* _tmp23_;
				GDateTime* _tmp24_;
				_day_item_index = _day_item_index + 1;
				_tmp13_ = _day_item_index;
				_tmp14_ = _day_item_size;
				if (!(_tmp13_ < _tmp14_)) {
					break;
				}
				_tmp15_ = _day_item_list;
				_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, _day_item_index);
				day_item = (WidgetsCalendarCalendarDay*) _tmp16_;
				_tmp17_ = day_item;
				_tmp18_ = adw_bin_get_child ((AdwBin*) _tmp17_);
				_tmp19_ = _tmp18_;
				gtk_widget_remove_css_class (_tmp19_, "selected");
				_tmp22_ = day_item;
				_tmp23_ = widgets_calendar_calendar_day_get_date (_tmp22_);
				_tmp24_ = _tmp23_;
				if (g_date_time_get_year (_tmp24_) == g_date_time_get_year (date)) {
					WidgetsCalendarCalendarDay* _tmp25_;
					GDateTime* _tmp26_;
					GDateTime* _tmp27_;
					_tmp25_ = day_item;
					_tmp26_ = widgets_calendar_calendar_day_get_date (_tmp25_);
					_tmp27_ = _tmp26_;
					_tmp21_ = g_date_time_get_month (_tmp27_) == g_date_time_get_month (date);
				} else {
					_tmp21_ = FALSE;
				}
				if (_tmp21_) {
					WidgetsCalendarCalendarDay* _tmp28_;
					GDateTime* _tmp29_;
					GDateTime* _tmp30_;
					_tmp28_ = day_item;
					_tmp29_ = widgets_calendar_calendar_day_get_date (_tmp28_);
					_tmp30_ = _tmp29_;
					_tmp20_ = g_date_time_get_day_of_month (_tmp30_) == g_date_time_get_day_of_month (date);
				} else {
					_tmp20_ = FALSE;
				}
				if (_tmp20_) {
					WidgetsCalendarCalendarDay* _tmp31_;
					GtkWidget* _tmp32_;
					GtkWidget* _tmp33_;
					_tmp31_ = day_item;
					_tmp32_ = adw_bin_get_child ((AdwBin*) _tmp31_);
					_tmp33_ = _tmp32_;
					gtk_widget_add_css_class (_tmp33_, "selected");
				}
				_g_object_unref0 (day_item);
			}
		}
	} else {
		WidgetsContextMenuMenuItem* _tmp34_;
		gchar* _tmp35_;
		gchar* _tmp36_;
		_tmp34_ = self->priv->date_item;
		_tmp35_ = utils_datetime_get_default_date_format_from_date (date);
		_tmp36_ = _tmp35_;
		widgets_context_menu_menu_item_set_title (_tmp34_, _tmp36_);
		_g_free0 (_tmp36_);
		{
			GeeArrayList* _day_item_list = NULL;
			GeeArrayList* _tmp37_;
			gint _day_item_size = 0;
			GeeArrayList* _tmp38_;
			gint _tmp39_;
			gint _tmp40_;
			gint _day_item_index = 0;
			_tmp37_ = self->priv->days_arraylist;
			_day_item_list = _tmp37_;
			_tmp38_ = _day_item_list;
			_tmp39_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp38_);
			_tmp40_ = _tmp39_;
			_day_item_size = _tmp40_;
			_day_item_index = -1;
			while (TRUE) {
				gint _tmp41_;
				gint _tmp42_;
				WidgetsCalendarCalendarDay* day_item = NULL;
				GeeArrayList* _tmp43_;
				gpointer _tmp44_;
				WidgetsCalendarCalendarDay* _tmp45_;
				GtkWidget* _tmp46_;
				GtkWidget* _tmp47_;
				_day_item_index = _day_item_index + 1;
				_tmp41_ = _day_item_index;
				_tmp42_ = _day_item_size;
				if (!(_tmp41_ < _tmp42_)) {
					break;
				}
				_tmp43_ = _day_item_list;
				_tmp44_ = gee_abstract_list_get ((GeeAbstractList*) _tmp43_, _day_item_index);
				day_item = (WidgetsCalendarCalendarDay*) _tmp44_;
				_tmp45_ = day_item;
				_tmp46_ = adw_bin_get_child ((AdwBin*) _tmp45_);
				_tmp47_ = _tmp46_;
				gtk_widget_remove_css_class (_tmp47_, "selected");
				_g_object_unref0 (day_item);
			}
		}
	}
	_g_date_time_unref0 (max_date);
	_g_date_time_unref0 (today);
}

void
widgets_calendar_calendar_month_reset (WidgetsCalendarCalendarMonth* self)
{
	WidgetsContextMenuMenuItem* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->date_item;
	widgets_context_menu_menu_item_set_title (_tmp0_, _ ("Choose a date"));
	{
		GeeArrayList* _day_item_list = NULL;
		GeeArrayList* _tmp1_;
		gint _day_item_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _day_item_index = 0;
		_tmp1_ = self->priv->days_arraylist;
		_day_item_list = _tmp1_;
		_tmp2_ = _day_item_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_day_item_size = _tmp4_;
		_day_item_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			WidgetsCalendarCalendarDay* day_item = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			WidgetsCalendarCalendarDay* _tmp9_;
			GtkWidget* _tmp10_;
			GtkWidget* _tmp11_;
			_day_item_index = _day_item_index + 1;
			_tmp5_ = _day_item_index;
			_tmp6_ = _day_item_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _day_item_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _day_item_index);
			day_item = (WidgetsCalendarCalendarDay*) _tmp8_;
			_tmp9_ = day_item;
			_tmp10_ = adw_bin_get_child ((AdwBin*) _tmp9_);
			_tmp11_ = _tmp10_;
			gtk_widget_remove_css_class (_tmp11_, "selected");
			_g_object_unref0 (day_item);
		}
	}
}

void
widgets_calendar_calendar_month_clean_up (WidgetsCalendarCalendarMonth* self)
{
	GeeHashMap* _tmp30_;
	g_return_if_fail (self != NULL);
	{
		GeeArrayList* _item_list = NULL;
		GeeArrayList* _tmp0_;
		gint _item_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _item_index = 0;
		_tmp0_ = self->priv->days_arraylist;
		_item_list = _tmp0_;
		_tmp1_ = _item_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_item_size = _tmp3_;
		_item_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			WidgetsCalendarCalendarDay* item = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			WidgetsCalendarCalendarDay* _tmp8_;
			_item_index = _item_index + 1;
			_tmp4_ = _item_index;
			_tmp5_ = _item_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _item_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _item_index);
			item = (WidgetsCalendarCalendarDay*) _tmp7_;
			_tmp8_ = item;
			widgets_calendar_calendar_day_clean_up (_tmp8_);
			_g_object_unref0 (item);
		}
	}
	{
		GeeIterator* _entry_it = NULL;
		GeeHashMap* _tmp9_;
		GeeSet* _tmp10_;
		GeeSet* _tmp11_;
		GeeSet* _tmp12_;
		GeeIterator* _tmp13_;
		GeeIterator* _tmp14_;
		_tmp9_ = self->priv->signals_map;
		_tmp10_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = _tmp11_;
		_tmp13_ = gee_iterable_iterator ((GeeIterable*) _tmp12_);
		_tmp14_ = _tmp13_;
		_g_object_unref0 (_tmp12_);
		_entry_it = _tmp14_;
		while (TRUE) {
			GeeIterator* _tmp15_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp16_;
			gpointer _tmp17_;
			GeeMapEntry* _tmp18_;
			gconstpointer _tmp19_;
			gconstpointer _tmp20_;
			GeeMapEntry* _tmp21_;
			gconstpointer _tmp22_;
			gconstpointer _tmp23_;
			_tmp15_ = _entry_it;
			if (!gee_iterator_next (_tmp15_)) {
				break;
			}
			_tmp16_ = _entry_it;
			_tmp17_ = gee_iterator_get (_tmp16_);
			entry = (GeeMapEntry*) _tmp17_;
			_tmp18_ = entry;
			_tmp19_ = gee_map_entry_get_value (_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = entry;
			_tmp22_ = gee_map_entry_get_key (_tmp21_);
			_tmp23_ = _tmp22_;
			if (g_signal_handler_is_connected ((GObject*) _tmp20_, (gulong) ((guintptr) _tmp23_))) {
				GeeMapEntry* _tmp24_;
				gconstpointer _tmp25_;
				gconstpointer _tmp26_;
				GeeMapEntry* _tmp27_;
				gconstpointer _tmp28_;
				gconstpointer _tmp29_;
				_tmp24_ = entry;
				_tmp25_ = gee_map_entry_get_value (_tmp24_);
				_tmp26_ = _tmp25_;
				_tmp27_ = entry;
				_tmp28_ = gee_map_entry_get_key (_tmp27_);
				_tmp29_ = _tmp28_;
				g_signal_handler_disconnect ((GObject*) _tmp26_, (gulong) ((guintptr) _tmp29_));
			}
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
	_tmp30_ = self->priv->signals_map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp30_);
}

GDateTime*
widgets_calendar_calendar_month_get_current_date (WidgetsCalendarCalendarMonth* self)
{
	GDateTime* result;
	GDateTime* today = NULL;
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_date_time_new_now_local ();
	today = _tmp0_;
	_tmp1_ = g_date_time_new_local (g_date_time_get_year (today), g_date_time_get_month (today), g_date_time_get_day_of_month (today), 0, 0, (gdouble) 0);
	_g_date_time_unref0 (self->priv->_current_date);
	self->priv->_current_date = _tmp1_;
	_tmp2_ = self->priv->_current_date;
	result = _tmp2_;
	_g_date_time_unref0 (today);
	return result;
}

GDateTime*
widgets_calendar_calendar_month_get_date (WidgetsCalendarCalendarMonth* self)
{
	GDateTime* result;
	GDateTime* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_date;
	result = _tmp0_;
	return result;
}

void
widgets_calendar_calendar_month_set_date (WidgetsCalendarCalendarMonth* self,
                                          GDateTime* value)
{
	GDateTime* _tmp0_;
	GDateTime* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_date_time_ref0 (value);
	_g_date_time_unref0 (self->priv->_date);
	self->priv->_date = _tmp0_;
	_tmp1_ = self->priv->_date;
	if (_tmp1_ != NULL) {
		GDateTime* _tmp2_;
		_tmp2_ = self->priv->_date;
		widgets_calendar_calendar_month_select_date (self, _tmp2_);
	}
	g_object_notify_by_pspec ((GObject *) self, widgets_calendar_calendar_month_properties[WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY]);
}

static void
_widgets_calendar_calendar_month___lambda142_ (WidgetsCalendarCalendarMonth* self)
{
	GDateTime* _tmp0_;
	widgets_calendar_calendar_month_fill_days (self);
	_tmp0_ = self->priv->_date;
	if (_tmp0_ != NULL) {
		GDateTime* _tmp1_;
		_tmp1_ = self->priv->_date;
		widgets_calendar_calendar_month_select_date (self, _tmp1_);
	}
}

static void
__widgets_calendar_calendar_month___lambda142__services_event_bus_day_changed (ServicesEventBus* _sender,
                                                                               gpointer self)
{
	_widgets_calendar_calendar_month___lambda142_ ((WidgetsCalendarCalendarMonth*) self);
}

static void
_widgets_calendar_calendar_month___lambda143_ (WidgetsCalendarCalendarMonth* self)
{
	WidgetsCalendarCalendarWeek* _tmp0_;
	_tmp0_ = self->priv->calendar_week;
	widgets_calendar_calendar_week_update (_tmp0_);
	widgets_calendar_calendar_month_fill_days (self);
}

static void
__widgets_calendar_calendar_month___lambda143__g_settings_changed (GSettings* _sender,
                                                                   const gchar* key,
                                                                   gpointer self)
{
	_widgets_calendar_calendar_month___lambda143_ ((WidgetsCalendarCalendarMonth*) self);
}

static void
_widgets_calendar_calendar_month___lambda144_ (WidgetsCalendarCalendarMonth* self)
{
	widgets_calendar_calendar_month_clean_up (self);
}

static void
__widgets_calendar_calendar_month___lambda144__gtk_widget_destroy (GtkWidget* _sender,
                                                                   gpointer self)
{
	_widgets_calendar_calendar_month___lambda144_ ((WidgetsCalendarCalendarMonth*) self);
}

static void
_widgets_calendar_calendar_month___lambda145_ (WidgetsCalendarCalendarMonth* self)
{
	g_signal_emit (self, widgets_calendar_calendar_month_signals[WIDGETS_CALENDAR_CALENDAR_MONTH_CHOOSE_DATE_CLICKED_SIGNAL], 0);
}

static void
__widgets_calendar_calendar_month___lambda145__gtk_button_clicked (GtkButton* _sender,
                                                                   gpointer self)
{
	_widgets_calendar_calendar_month___lambda145_ ((WidgetsCalendarCalendarMonth*) self);
}

static GObject *
widgets_calendar_calendar_month_constructor (GType type,
                                             guint n_construct_properties,
                                             GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsCalendarCalendarMonth * self;
	WidgetsCalendarCalendarWeek* _tmp0_;
	GeeArrayList* _tmp1_;
	GtkGrid* _tmp2_ = NULL;
	WidgetsContextMenuMenuItem* _tmp3_ = NULL;
	WidgetsCalendarCalendarWeek* _tmp4_;
	GtkGrid* _tmp5_;
	WidgetsContextMenuMenuItem* _tmp6_;
	ServicesEventBus* _tmp7_;
	ServicesEventBus* _tmp8_;
	ServicesSettings* _tmp9_;
	ServicesSettings* _tmp10_;
	GSettings* _tmp11_;
	WidgetsContextMenuMenuItem* _tmp12_;
	parent_class = G_OBJECT_CLASS (widgets_calendar_calendar_month_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, WidgetsCalendarCalendarMonth);
	_tmp0_ = widgets_calendar_calendar_week_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->calendar_week);
	self->priv->calendar_week = _tmp0_;
	_tmp1_ = gee_array_list_new (WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->days_arraylist);
	self->priv->days_arraylist = _tmp1_;
	_tmp2_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_homogeneous (_tmp2_, TRUE);
	gtk_grid_set_row_homogeneous (_tmp2_, TRUE);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp2_, 6);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp2_, 6);
	g_object_ref_sink (_tmp2_);
	_g_object_unref0 (self->priv->days_grid);
	self->priv->days_grid = _tmp2_;
	_tmp3_ = widgets_context_menu_menu_item_new (_ ("Choose a date"), "month-symbolic");
	widgets_context_menu_menu_item_set_arrow (_tmp3_, TRUE);
	widgets_context_menu_menu_item_set_autohide_popover (_tmp3_, FALSE);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp3_, 3);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->date_item);
	self->priv->date_item = _tmp3_;
	_tmp4_ = self->priv->calendar_week;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp4_);
	_tmp5_ = self->priv->days_grid;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->date_item;
	gtk_box_append ((GtkBox*) self, (GtkWidget*) _tmp6_);
	widgets_calendar_calendar_month_fill_days (self);
	_tmp7_ = services_event_bus_get_default ();
	_tmp8_ = _tmp7_;
	g_signal_connect_object (_tmp8_, "day-changed", (GCallback) __widgets_calendar_calendar_month___lambda142__services_event_bus_day_changed, self, 0);
	_g_object_unref0 (_tmp8_);
	_tmp9_ = services_settings_get_default ();
	_tmp10_ = _tmp9_;
	_tmp11_ = _tmp10_->settings;
	g_signal_connect_object (_tmp11_, "changed::start-week", (GCallback) __widgets_calendar_calendar_month___lambda143__g_settings_changed, self, 0);
	_g_object_unref0 (_tmp10_);
	g_signal_connect_object ((GtkWidget*) self, "destroy", (GCallback) __widgets_calendar_calendar_month___lambda144__gtk_widget_destroy, self, 0);
	_tmp12_ = self->priv->date_item;
	g_signal_connect_object ((GtkButton*) _tmp12_, "clicked", (GCallback) __widgets_calendar_calendar_month___lambda145__gtk_button_clicked, self, 0);
	return obj;
}

static void
widgets_calendar_calendar_month_class_init (WidgetsCalendarCalendarMonthClass * klass,
                                            gpointer klass_data)
{
	widgets_calendar_calendar_month_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsCalendarCalendarMonth_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_calendar_calendar_month_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_calendar_calendar_month_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_calendar_calendar_month_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_calendar_calendar_month_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_CALENDAR_CALENDAR_MONTH_CURRENT_DATE_PROPERTY, widgets_calendar_calendar_month_properties[WIDGETS_CALENDAR_CALENDAR_MONTH_CURRENT_DATE_PROPERTY] = g_param_spec_boxed ("current-date", "current-date", "current-date", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY, widgets_calendar_calendar_month_properties[WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY] = g_param_spec_boxed ("date", "date", "date", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	widgets_calendar_calendar_month_signals[WIDGETS_CALENDAR_CALENDAR_MONTH_DAY_SELECTED_SIGNAL] = g_signal_new ("day-selected", WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	widgets_calendar_calendar_month_signals[WIDGETS_CALENDAR_CALENDAR_MONTH_CHOOSE_DATE_CLICKED_SIGNAL] = g_signal_new ("choose-date-clicked", WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_calendar_calendar_month_instance_init (WidgetsCalendarCalendarMonth * self,
                                               gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = widgets_calendar_calendar_month_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_ULONG, NULL, NULL, G_TYPE_OBJECT, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->signals_map = _tmp0_;
}

static void
widgets_calendar_calendar_month_finalize (GObject * obj)
{
	WidgetsCalendarCalendarMonth * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, WidgetsCalendarCalendarMonth);
	g_debug ("CalendarMonth.vala:68: Destroying - Widgets.Calendar.CalendarMonth\n");
	_g_object_unref0 (self->priv->calendar_week);
	_g_object_unref0 (self->priv->days_grid);
	_g_object_unref0 (self->priv->days_arraylist);
	_g_object_unref0 (self->priv->date_item);
	_g_date_time_unref0 (self->priv->_current_date);
	_g_date_time_unref0 (self->priv->_date);
	_g_object_unref0 (self->priv->signals_map);
	G_OBJECT_CLASS (widgets_calendar_calendar_month_parent_class)->finalize (obj);
}

static GType
widgets_calendar_calendar_month_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsCalendarCalendarMonthClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_calendar_calendar_month_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsCalendarCalendarMonth), 0, (GInstanceInitFunc) widgets_calendar_calendar_month_instance_init, NULL };
	GType widgets_calendar_calendar_month_type_id;
	widgets_calendar_calendar_month_type_id = g_type_register_static (gtk_box_get_type (), "WidgetsCalendarCalendarMonth", &g_define_type_info, 0);
	WidgetsCalendarCalendarMonth_private_offset = g_type_add_instance_private (widgets_calendar_calendar_month_type_id, sizeof (WidgetsCalendarCalendarMonthPrivate));
	return widgets_calendar_calendar_month_type_id;
}

GType
widgets_calendar_calendar_month_get_type (void)
{
	static volatile gsize widgets_calendar_calendar_month_type_id__once = 0;
	if (g_once_init_enter (&widgets_calendar_calendar_month_type_id__once)) {
		GType widgets_calendar_calendar_month_type_id;
		widgets_calendar_calendar_month_type_id = widgets_calendar_calendar_month_get_type_once ();
		g_once_init_leave (&widgets_calendar_calendar_month_type_id__once, widgets_calendar_calendar_month_type_id);
	}
	return widgets_calendar_calendar_month_type_id__once;
}

static void
_vala_widgets_calendar_calendar_month_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec)
{
	WidgetsCalendarCalendarMonth * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, WidgetsCalendarCalendarMonth);
	switch (property_id) {
		case WIDGETS_CALENDAR_CALENDAR_MONTH_CURRENT_DATE_PROPERTY:
		g_value_set_boxed (value, widgets_calendar_calendar_month_get_current_date (self));
		break;
		case WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY:
		g_value_set_boxed (value, widgets_calendar_calendar_month_get_date (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_calendar_calendar_month_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec)
{
	WidgetsCalendarCalendarMonth * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_CALENDAR_TYPE_CALENDAR_MONTH, WidgetsCalendarCalendarMonth);
	switch (property_id) {
		case WIDGETS_CALENDAR_CALENDAR_MONTH_DATE_PROPERTY:
		widgets_calendar_calendar_month_set_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;
}

