/* CalendarDay.c generated by valac 0.56.19, the Vala compiler
 * generated from CalendarDay.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 <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.h>
#include <adwaita.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

enum  {
	WIDGETS_CALENDAR_CALENDAR_DAY_0_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_DAY_SHOW_MONTH_PROPERTY,
	WIDGETS_CALENDAR_CALENDAR_DAY_NUM_PROPERTIES
};
static GParamSpec* widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	WIDGETS_CALENDAR_CALENDAR_DAY_DAY_SELECTED_SIGNAL,
	WIDGETS_CALENDAR_CALENDAR_DAY_NUM_SIGNALS
};
static guint widgets_calendar_calendar_day_signals[WIDGETS_CALENDAR_CALENDAR_DAY_NUM_SIGNALS] = {0};

struct _WidgetsCalendarCalendarDayPrivate {
	GtkLabel* day_label;
	GtkLabel* month_label;
	GtkButton* button;
	gulong button_clicked_id;
	gint _day;
	GDateTime* _date;
};

static gint WidgetsCalendarCalendarDay_private_offset;
static gpointer widgets_calendar_calendar_day_parent_class = NULL;

static void widgets_calendar_calendar_day_update_accessible_label (WidgetsCalendarCalendarDay* self);
static GObject * widgets_calendar_calendar_day_constructor (GType type,
                                                     guint n_construct_properties,
                                                     GObjectConstructParam * construct_properties);
static void _widgets_calendar_calendar_day___lambda138_ (WidgetsCalendarCalendarDay* self);
static void __widgets_calendar_calendar_day___lambda138__gtk_button_clicked (GtkButton* _sender,
                                                                      gpointer self);
static void widgets_calendar_calendar_day_finalize (GObject * obj);
static GType widgets_calendar_calendar_day_get_type_once (void);
static void _vala_widgets_calendar_calendar_day_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static void _vala_widgets_calendar_calendar_day_set_property (GObject * object,
                                                       guint property_id,
                                                       const GValue * value,
                                                       GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
widgets_calendar_calendar_day_get_instance_private (WidgetsCalendarCalendarDay* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsCalendarCalendarDay_private_offset);
}

WidgetsCalendarCalendarDay*
widgets_calendar_calendar_day_construct (GType object_type)
{
	WidgetsCalendarCalendarDay * self = NULL;
	self = (WidgetsCalendarCalendarDay*) g_object_new (object_type, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, NULL);
	return self;
}

WidgetsCalendarCalendarDay*
widgets_calendar_calendar_day_new (void)
{
	return widgets_calendar_calendar_day_construct (WIDGETS_CALENDAR_TYPE_CALENDAR_DAY);
}

void
widgets_calendar_calendar_day_add_day_css_class (WidgetsCalendarCalendarDay* self,
                                                 const gchar* css_class)
{
	GtkLabel* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (css_class != NULL);
	_tmp0_ = self->priv->day_label;
	gtk_widget_add_css_class ((GtkWidget*) _tmp0_, css_class);
}

static void
widgets_calendar_calendar_day_update_accessible_label (WidgetsCalendarCalendarDay* self)
{
	gboolean _tmp0_ = FALSE;
	GDateTime* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_date;
	if (_tmp1_ != NULL) {
		_tmp0_ = self->priv->_day > 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* accessible_text = NULL;
		GDateTime* _tmp2_;
		gchar* _tmp3_;
		GtkButton* _tmp4_;
		const gchar* _tmp5_;
		_tmp2_ = self->priv->_date;
		_tmp3_ = g_date_time_format (_tmp2_, _ ("%A, %B %e, %Y"));
		accessible_text = _tmp3_;
		_tmp4_ = self->priv->button;
		_tmp5_ = accessible_text;
		gtk_accessible_update_property ((GtkAccessible*) _tmp4_, GTK_ACCESSIBLE_PROPERTY_LABEL, _tmp5_, -1, -1);
		_g_free0 (accessible_text);
	}
}

void
widgets_calendar_calendar_day_clean_up (WidgetsCalendarCalendarDay* self)
{
	g_return_if_fail (self != NULL);
	if (self->priv->button_clicked_id != ((gulong) 0)) {
		GtkButton* _tmp0_;
		_tmp0_ = self->priv->button;
		g_signal_handler_disconnect ((GObject*) _tmp0_, self->priv->button_clicked_id);
		self->priv->button_clicked_id = (gulong) 0;
	}
}

gint
widgets_calendar_calendar_day_get_day (WidgetsCalendarCalendarDay* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_day;
	return result;
}

void
widgets_calendar_calendar_day_set_day (WidgetsCalendarCalendarDay* self,
                                       gint value)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	self->priv->_day = value;
	_tmp0_ = self->priv->day_label;
	_tmp1_ = g_strdup_printf ("%i", self->priv->_day);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
	widgets_calendar_calendar_day_update_accessible_label (self);
	g_object_notify_by_pspec ((GObject *) self, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY]);
}

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

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

void
widgets_calendar_calendar_day_set_date (WidgetsCalendarCalendarDay* self,
                                        GDateTime* value)
{
	GDateTime* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_date_time_ref0 (value);
	_g_date_time_unref0 (self->priv->_date);
	self->priv->_date = _tmp0_;
	widgets_calendar_calendar_day_update_accessible_label (self);
	g_object_notify_by_pspec ((GObject *) self, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY]);
}

void
widgets_calendar_calendar_day_set_show_month (WidgetsCalendarCalendarDay* self,
                                              gboolean value)
{
	GtkLabel* _tmp0_;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->month_label;
	gtk_widget_set_visible ((GtkWidget*) _tmp0_, value);
	if (value) {
		GDateTime* _tmp2_;
		_tmp2_ = self->priv->_date;
		_tmp1_ = _tmp2_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GtkLabel* _tmp3_;
		GDateTime* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp3_ = self->priv->month_label;
		_tmp4_ = self->priv->_date;
		_tmp5_ = g_date_time_format (_tmp4_, "%b");
		_tmp6_ = _tmp5_;
		gtk_label_set_label (_tmp3_, _tmp6_);
		_g_free0 (_tmp6_);
	}
	g_object_notify_by_pspec ((GObject *) self, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_SHOW_MONTH_PROPERTY]);
}

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

static void
_widgets_calendar_calendar_day___lambda138_ (WidgetsCalendarCalendarDay* self)
{
	GtkButton* _tmp0_;
	g_signal_emit (self, widgets_calendar_calendar_day_signals[WIDGETS_CALENDAR_CALENDAR_DAY_DAY_SELECTED_SIGNAL], 0);
	_tmp0_ = self->priv->button;
	gtk_widget_add_css_class ((GtkWidget*) _tmp0_, "selected");
}

static void
__widgets_calendar_calendar_day___lambda138__gtk_button_clicked (GtkButton* _sender,
                                                                 gpointer self)
{
	_widgets_calendar_calendar_day___lambda138_ ((WidgetsCalendarCalendarDay*) self);
}

static GObject *
widgets_calendar_calendar_day_constructor (GType type,
                                           guint n_construct_properties,
                                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsCalendarCalendarDay * self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar** _tmp2_;
	GtkLabel* _tmp3_ = NULL;
	GtkLabel* _tmp4_;
	GtkBox* box = NULL;
	GtkBox* _tmp5_ = NULL;
	GtkBox* _tmp6_;
	GtkLabel* _tmp7_;
	GtkBox* _tmp8_;
	GtkLabel* _tmp9_;
	GtkBox* _tmp10_;
	GtkWidget* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar** _tmp14_;
	GtkButton* _tmp15_ = NULL;
	GtkButton* _tmp16_;
	GtkButton* _tmp17_;
	gulong _tmp18_;
	parent_class = G_OBJECT_CLASS (widgets_calendar_calendar_day_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, WidgetsCalendarCalendarDay);
	_tmp0_ = g_strdup ("caption");
	_tmp1_ = g_strdup ("dimmed");
	_tmp2_ = g_new0 (gchar*, 2 + 1);
	_tmp2_[0] = _tmp0_;
	_tmp2_[1] = _tmp1_;
	_tmp3_ = (GtkLabel*) gtk_label_new (NULL);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp3_, _tmp2_);
	_tmp2_ = (_vala_array_free (_tmp2_, 2, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_visible ((GtkWidget*) _tmp3_, FALSE);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->month_label);
	self->priv->month_label = _tmp3_;
	_tmp4_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->day_label);
	self->priv->day_label = _tmp4_;
	_tmp5_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_CENTER);
	gtk_widget_set_valign ((GtkWidget*) _tmp5_, GTK_ALIGN_CENTER);
	g_object_ref_sink (_tmp5_);
	box = _tmp5_;
	_tmp6_ = box;
	_tmp7_ = self->priv->month_label;
	gtk_box_append (_tmp6_, (GtkWidget*) _tmp7_);
	_tmp8_ = box;
	_tmp9_ = self->priv->day_label;
	gtk_box_append (_tmp8_, (GtkWidget*) _tmp9_);
	_tmp10_ = box;
	_tmp11_ = _g_object_ref0 ((GtkWidget*) _tmp10_);
	_tmp12_ = g_strdup ("flat");
	_tmp13_ = g_strdup ("calendar-day");
	_tmp14_ = g_new0 (gchar*, 2 + 1);
	_tmp14_[0] = _tmp12_;
	_tmp14_[1] = _tmp13_;
	_tmp15_ = (GtkButton*) gtk_button_new ();
	gtk_button_set_child (_tmp15_, _tmp11_);
	_g_object_unref0 (_tmp11_);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp15_, _tmp14_);
	_tmp14_ = (_vala_array_free (_tmp14_, 2, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp15_);
	_g_object_unref0 (self->priv->button);
	self->priv->button = _tmp15_;
	_tmp16_ = self->priv->button;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp16_);
	_tmp17_ = self->priv->button;
	_tmp18_ = g_signal_connect_object (_tmp17_, "clicked", (GCallback) __widgets_calendar_calendar_day___lambda138__gtk_button_clicked, self, 0);
	self->priv->button_clicked_id = _tmp18_;
	_g_object_unref0 (box);
	return obj;
}

static void
widgets_calendar_calendar_day_class_init (WidgetsCalendarCalendarDayClass * klass,
                                          gpointer klass_data)
{
	widgets_calendar_calendar_day_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsCalendarCalendarDay_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_calendar_calendar_day_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_calendar_calendar_day_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_calendar_calendar_day_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_calendar_calendar_day_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY] = g_param_spec_int ("day", "day", "day", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY] = g_param_spec_boxed ("date", "date", "date", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_CALENDAR_CALENDAR_DAY_SHOW_MONTH_PROPERTY, widgets_calendar_calendar_day_properties[WIDGETS_CALENDAR_CALENDAR_DAY_SHOW_MONTH_PROPERTY] = g_param_spec_boolean ("show-month", "show-month", "show-month", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	widgets_calendar_calendar_day_signals[WIDGETS_CALENDAR_CALENDAR_DAY_DAY_SELECTED_SIGNAL] = g_signal_new ("day-selected", WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
widgets_calendar_calendar_day_instance_init (WidgetsCalendarCalendarDay * self,
                                             gpointer klass)
{
	self->priv = widgets_calendar_calendar_day_get_instance_private (self);
	self->priv->button_clicked_id = (gulong) 0;
}

static void
widgets_calendar_calendar_day_finalize (GObject * obj)
{
	WidgetsCalendarCalendarDay * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, WidgetsCalendarCalendarDay);
	_g_object_unref0 (self->priv->day_label);
	_g_object_unref0 (self->priv->month_label);
	_g_object_unref0 (self->priv->button);
	_g_date_time_unref0 (self->priv->_date);
	G_OBJECT_CLASS (widgets_calendar_calendar_day_parent_class)->finalize (obj);
}

static GType
widgets_calendar_calendar_day_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsCalendarCalendarDayClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_calendar_calendar_day_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsCalendarCalendarDay), 0, (GInstanceInitFunc) widgets_calendar_calendar_day_instance_init, NULL };
	GType widgets_calendar_calendar_day_type_id;
	widgets_calendar_calendar_day_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsCalendarCalendarDay", &g_define_type_info, 0);
	WidgetsCalendarCalendarDay_private_offset = g_type_add_instance_private (widgets_calendar_calendar_day_type_id, sizeof (WidgetsCalendarCalendarDayPrivate));
	return widgets_calendar_calendar_day_type_id;
}

GType
widgets_calendar_calendar_day_get_type (void)
{
	static volatile gsize widgets_calendar_calendar_day_type_id__once = 0;
	if (g_once_init_enter (&widgets_calendar_calendar_day_type_id__once)) {
		GType widgets_calendar_calendar_day_type_id;
		widgets_calendar_calendar_day_type_id = widgets_calendar_calendar_day_get_type_once ();
		g_once_init_leave (&widgets_calendar_calendar_day_type_id__once, widgets_calendar_calendar_day_type_id);
	}
	return widgets_calendar_calendar_day_type_id__once;
}

static void
_vala_widgets_calendar_calendar_day_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	WidgetsCalendarCalendarDay * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, WidgetsCalendarCalendarDay);
	switch (property_id) {
		case WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY:
		g_value_set_int (value, widgets_calendar_calendar_day_get_day (self));
		break;
		case WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY:
		g_value_set_boxed (value, widgets_calendar_calendar_day_get_date (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_calendar_calendar_day_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec)
{
	WidgetsCalendarCalendarDay * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_CALENDAR_TYPE_CALENDAR_DAY, WidgetsCalendarCalendarDay);
	switch (property_id) {
		case WIDGETS_CALENDAR_CALENDAR_DAY_DAY_PROPERTY:
		widgets_calendar_calendar_day_set_day (self, g_value_get_int (value));
		break;
		case WIDGETS_CALENDAR_CALENDAR_DAY_DATE_PROPERTY:
		widgets_calendar_calendar_day_set_date (self, g_value_get_boxed (value));
		break;
		case WIDGETS_CALENDAR_CALENDAR_DAY_SHOW_MONTH_PROPERTY:
		widgets_calendar_calendar_day_set_show_month (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

