/* DeadlineButton.c generated by valac 0.56.19, the Vala compiler
 * generated from DeadlineButton.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 <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <pango/pango.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_DEADLINE_BUTTON_0_PROPERTY,
	WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY,
	WIDGETS_DEADLINE_BUTTON_DATETIME_PROPERTY,
	WIDGETS_DEADLINE_BUTTON_REVEAL_CONTENT_PROPERTY,
	WIDGETS_DEADLINE_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block20Data Block20Data;
#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_DEADLINE_BUTTON_DATE_SELECTED_SIGNAL,
	WIDGETS_DEADLINE_BUTTON_PICKER_OPENED_SIGNAL,
	WIDGETS_DEADLINE_BUTTON_NUM_SIGNALS
};
static guint widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_NUM_SIGNALS] = {0};

struct _WidgetsDeadlineButtonPrivate {
	DeadlineButtonType _button_type;
	WidgetsCalendarCalendar* calendar_view;
	GtkPopover* calendar_popover;
	GtkMenuButton* button;
	GtkRevealer* delete_revealer;
	GtkLabel* deadline_label;
	GtkLabel* deadline_date_label;
	GtkLabel* deadline_relative_label;
	GtkRevealer* main_revealer;
	GtkImage* deadline_icon;
};

struct _Block20Data {
	int _ref_count_;
	WidgetsDeadlineButton* self;
	GtkPopover* popover;
};

static gint WidgetsDeadlineButton_private_offset;
static gpointer widgets_deadline_button_parent_class = NULL;

static void widgets_deadline_button_build_button_content (WidgetsDeadlineButton* self);
static void widgets_deadline_button_build_ui (WidgetsDeadlineButton* self);
static Block20Data* block20_data_ref (Block20Data* _data20_);
static void block20_data_unref (void * _userdata_);
static void __lambda253_ (Block20Data* _data20_);
static void ___lambda253__widgets_calendar_calendar_day_selected (WidgetsCalendarCalendar* _sender,
                                                           gpointer self);
static void __lambda254_ (Block20Data* _data20_);
static void ___lambda254__gtk_button_clicked (GtkButton* _sender,
                                       gpointer self);
static gchar* widgets_deadline_button_get_date_format (WidgetsDeadlineButton* self,
                                                GDateTime* date);
static gchar* widgets_deadline_button_get_relative_date_format (WidgetsDeadlineButton* self,
                                                         GDateTime* date);
static void widgets_deadline_button_update_error_style (WidgetsDeadlineButton* self,
                                                 GDateTime* date);
static void widgets_deadline_button_update_card_error_style (WidgetsDeadlineButton* self,
                                                      GDateTime* date);
static GObject * widgets_deadline_button_constructor (GType type,
                                               guint n_construct_properties,
                                               GObjectConstructParam * construct_properties);
static void _widgets_deadline_button___lambda255_ (WidgetsDeadlineButton* self);
static void __widgets_deadline_button___lambda255__gtk_popover_closed (GtkPopover* _sender,
                                                                gpointer self);
static void _widgets_deadline_button___lambda256_ (WidgetsDeadlineButton* self);
static void __widgets_deadline_button___lambda256__gtk_widget_show (GtkWidget* _sender,
                                                             gpointer self);
static void widgets_deadline_button_finalize (GObject * obj);
static GType widgets_deadline_button_get_type_once (void);
static void _vala_widgets_deadline_button_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec);
static void _vala_widgets_deadline_button_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 GType
deadline_button_type_get_type_once (void)
{
	static const GEnumValue values[] = {{DEADLINE_BUTTON_TYPE_BUTTON, "DEADLINE_BUTTON_TYPE_BUTTON", "button"}, {DEADLINE_BUTTON_TYPE_BUTTON_DETAIL, "DEADLINE_BUTTON_TYPE_BUTTON_DETAIL", "button-detail"}, {DEADLINE_BUTTON_TYPE_CARD, "DEADLINE_BUTTON_TYPE_CARD", "card"}, {0, NULL, NULL}};
	GType deadline_button_type_type_id;
	deadline_button_type_type_id = g_enum_register_static ("DeadlineButtonType", values);
	return deadline_button_type_type_id;
}

GType
deadline_button_type_get_type (void)
{
	static volatile gsize deadline_button_type_type_id__once = 0;
	if (g_once_init_enter (&deadline_button_type_type_id__once)) {
		GType deadline_button_type_type_id;
		deadline_button_type_type_id = deadline_button_type_get_type_once ();
		g_once_init_leave (&deadline_button_type_type_id__once, deadline_button_type_type_id);
	}
	return deadline_button_type_type_id__once;
}

static inline gpointer
widgets_deadline_button_get_instance_private (WidgetsDeadlineButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsDeadlineButton_private_offset);
}

WidgetsDeadlineButton*
widgets_deadline_button_construct (GType object_type)
{
	WidgetsDeadlineButton * self = NULL;
	self = (WidgetsDeadlineButton*) g_object_new (object_type, "button-type", DEADLINE_BUTTON_TYPE_BUTTON, "tooltip-text", _ ("The latest date to complete this task"), NULL);
	return self;
}

WidgetsDeadlineButton*
widgets_deadline_button_new (void)
{
	return widgets_deadline_button_construct (WIDGETS_TYPE_DEADLINE_BUTTON);
}

WidgetsDeadlineButton*
widgets_deadline_button_construct_with_detail (GType object_type)
{
	WidgetsDeadlineButton * self = NULL;
	self = (WidgetsDeadlineButton*) g_object_new (object_type, "button-type", DEADLINE_BUTTON_TYPE_BUTTON_DETAIL, "tooltip-text", _ ("The latest date to complete this task"), NULL);
	return self;
}

WidgetsDeadlineButton*
widgets_deadline_button_new_with_detail (void)
{
	return widgets_deadline_button_construct_with_detail (WIDGETS_TYPE_DEADLINE_BUTTON);
}

WidgetsDeadlineButton*
widgets_deadline_button_construct_card (GType object_type)
{
	WidgetsDeadlineButton * self = NULL;
	self = (WidgetsDeadlineButton*) g_object_new (object_type, "button-type", DEADLINE_BUTTON_TYPE_CARD, "tooltip-text", _ ("The latest date to complete this task"), NULL);
	return self;
}

WidgetsDeadlineButton*
widgets_deadline_button_new_card (void)
{
	return widgets_deadline_button_construct_card (WIDGETS_TYPE_DEADLINE_BUTTON);
}

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

static void
widgets_deadline_button_build_button_content (WidgetsDeadlineButton* self)
{
	GtkImage* _tmp0_;
	GtkWidget* button_child = NULL;
	DeadlineButtonType _tmp1_;
	gchar* _tmp34_;
	gchar** _tmp35_;
	GtkWidget* _tmp36_;
	GtkWidget* _tmp37_;
	GtkPopover* _tmp38_;
	GtkPopover* _tmp39_;
	GtkMenuButton* _tmp40_ = NULL;
	DeadlineButtonType _tmp41_;
	g_return_if_fail (self != NULL);
	_tmp0_ = (GtkImage*) gtk_image_new_from_icon_name ("delay-long-small-symbolic");
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->deadline_icon);
	self->priv->deadline_icon = _tmp0_;
	_tmp1_ = self->priv->_button_type;
	if (_tmp1_ == DEADLINE_BUTTON_TYPE_BUTTON) {
		GtkImage* _tmp2_;
		GtkWidget* _tmp3_;
		_tmp2_ = self->priv->deadline_icon;
		_tmp3_ = _g_object_ref0 ((GtkWidget*) _tmp2_);
		_g_object_unref0 (button_child);
		button_child = _tmp3_;
	} else {
		DeadlineButtonType _tmp4_;
		_tmp4_ = self->priv->_button_type;
		if (_tmp4_ == DEADLINE_BUTTON_TYPE_BUTTON_DETAIL) {
			GtkLabel* _tmp5_ = NULL;
			GtkLabel* _tmp6_ = NULL;
			GtkLabel* _tmp7_;
			GtkBox* deadline_box = NULL;
			GtkBox* _tmp8_ = NULL;
			GtkBox* _tmp9_;
			GtkImage* _tmp10_;
			GtkBox* _tmp11_;
			GtkLabel* _tmp12_;
			GtkBox* _tmp13_;
			GtkLabel* _tmp14_;
			GtkBox* _tmp15_;
			GtkWidget* _tmp16_;
			_tmp5_ = (GtkLabel*) gtk_label_new (_ ("Set Deadline"));
			gtk_widget_set_halign ((GtkWidget*) _tmp5_, GTK_ALIGN_START);
			g_object_ref_sink (_tmp5_);
			_g_object_unref0 (self->priv->deadline_date_label);
			self->priv->deadline_date_label = _tmp5_;
			_tmp6_ = (GtkLabel*) gtk_label_new (_ ("The latest date to complete this task"));
			gtk_widget_set_halign ((GtkWidget*) _tmp6_, GTK_ALIGN_START);
			g_object_ref_sink (_tmp6_);
			_g_object_unref0 (self->priv->deadline_relative_label);
			self->priv->deadline_relative_label = _tmp6_;
			_tmp7_ = self->priv->deadline_relative_label;
			gtk_widget_add_css_class ((GtkWidget*) _tmp7_, "dimmed");
			_tmp8_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
			gtk_widget_set_halign ((GtkWidget*) _tmp8_, GTK_ALIGN_START);
			g_object_ref_sink (_tmp8_);
			deadline_box = _tmp8_;
			_tmp9_ = deadline_box;
			_tmp10_ = self->priv->deadline_icon;
			gtk_box_append (_tmp9_, (GtkWidget*) _tmp10_);
			_tmp11_ = deadline_box;
			_tmp12_ = self->priv->deadline_date_label;
			gtk_box_append (_tmp11_, (GtkWidget*) _tmp12_);
			_tmp13_ = deadline_box;
			_tmp14_ = self->priv->deadline_relative_label;
			gtk_box_append (_tmp13_, (GtkWidget*) _tmp14_);
			_tmp15_ = deadline_box;
			_tmp16_ = _g_object_ref0 ((GtkWidget*) _tmp15_);
			_g_object_unref0 (button_child);
			button_child = _tmp16_;
			_g_object_unref0 (deadline_box);
		} else {
			GtkLabel* title_label = NULL;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			gchar** _tmp20_;
			GtkLabel* _tmp21_ = NULL;
			gchar* _tmp22_;
			gchar** _tmp23_;
			GtkLabel* _tmp24_ = NULL;
			GtkGrid* card_grid = NULL;
			GtkGrid* _tmp25_ = NULL;
			GtkGrid* _tmp26_;
			GtkImage* _tmp27_;
			GtkGrid* _tmp28_;
			GtkLabel* _tmp29_;
			GtkGrid* _tmp30_;
			GtkLabel* _tmp31_;
			GtkGrid* _tmp32_;
			GtkWidget* _tmp33_;
			_tmp17_ = g_strdup ("title-4");
			_tmp18_ = g_strdup ("caption");
			_tmp19_ = g_strdup ("font-bold");
			_tmp20_ = g_new0 (gchar*, 3 + 1);
			_tmp20_[0] = _tmp17_;
			_tmp20_[1] = _tmp18_;
			_tmp20_[2] = _tmp19_;
			_tmp21_ = (GtkLabel*) gtk_label_new (_ ("Deadline"));
			gtk_widget_set_halign ((GtkWidget*) _tmp21_, GTK_ALIGN_START);
			gtk_widget_set_css_classes ((GtkWidget*) _tmp21_, _tmp20_);
			_tmp20_ = (_vala_array_free (_tmp20_, 3, (GDestroyNotify) g_free), NULL);
			g_object_ref_sink (_tmp21_);
			title_label = _tmp21_;
			_tmp22_ = g_strdup ("caption");
			_tmp23_ = g_new0 (gchar*, 1 + 1);
			_tmp23_[0] = _tmp22_;
			_tmp24_ = (GtkLabel*) gtk_label_new (_ ("What is the latest date to complete this?"));
			gtk_label_set_xalign (_tmp24_, (gfloat) 0);
			gtk_label_set_use_markup (_tmp24_, TRUE);
			gtk_widget_set_halign ((GtkWidget*) _tmp24_, GTK_ALIGN_START);
			gtk_label_set_ellipsize (_tmp24_, PANGO_ELLIPSIZE_END);
			gtk_widget_set_css_classes ((GtkWidget*) _tmp24_, _tmp23_);
			_tmp23_ = (_vala_array_free (_tmp23_, 1, (GDestroyNotify) g_free), NULL);
			g_object_ref_sink (_tmp24_);
			_g_object_unref0 (self->priv->deadline_label);
			self->priv->deadline_label = _tmp24_;
			_tmp25_ = (GtkGrid*) gtk_grid_new ();
			gtk_grid_set_column_spacing (_tmp25_, 12);
			gtk_widget_set_margin_start ((GtkWidget*) _tmp25_, 12);
			gtk_widget_set_margin_end ((GtkWidget*) _tmp25_, 6);
			gtk_widget_set_margin_top ((GtkWidget*) _tmp25_, 6);
			gtk_widget_set_margin_bottom ((GtkWidget*) _tmp25_, 6);
			gtk_widget_set_vexpand ((GtkWidget*) _tmp25_, TRUE);
			gtk_widget_set_hexpand ((GtkWidget*) _tmp25_, TRUE);
			g_object_ref_sink (_tmp25_);
			card_grid = _tmp25_;
			_tmp26_ = card_grid;
			_tmp27_ = self->priv->deadline_icon;
			gtk_grid_attach (_tmp26_, (GtkWidget*) _tmp27_, 0, 0, 1, 2);
			_tmp28_ = card_grid;
			_tmp29_ = title_label;
			gtk_grid_attach (_tmp28_, (GtkWidget*) _tmp29_, 1, 0, 1, 1);
			_tmp30_ = card_grid;
			_tmp31_ = self->priv->deadline_label;
			gtk_grid_attach (_tmp30_, (GtkWidget*) _tmp31_, 1, 1, 1, 1);
			_tmp32_ = card_grid;
			_tmp33_ = _g_object_ref0 ((GtkWidget*) _tmp32_);
			_g_object_unref0 (button_child);
			button_child = _tmp33_;
			_g_object_unref0 (card_grid);
			_g_object_unref0 (title_label);
		}
	}
	_tmp34_ = g_strdup ("flat");
	_tmp35_ = g_new0 (gchar*, 1 + 1);
	_tmp35_[0] = _tmp34_;
	_tmp36_ = button_child;
	_tmp37_ = _g_object_ref0 (_tmp36_);
	_tmp38_ = self->priv->calendar_popover;
	_tmp39_ = _g_object_ref0 (_tmp38_);
	_tmp40_ = (GtkMenuButton*) gtk_menu_button_new ();
	gtk_widget_set_css_classes ((GtkWidget*) _tmp40_, _tmp35_);
	_tmp35_ = (_vala_array_free (_tmp35_, 1, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_valign ((GtkWidget*) _tmp40_, GTK_ALIGN_CENTER);
	gtk_menu_button_set_child (_tmp40_, _tmp37_);
	_g_object_unref0 (_tmp37_);
	gtk_menu_button_set_popover (_tmp40_, _tmp39_);
	_g_object_unref0 (_tmp39_);
	g_object_ref_sink (_tmp40_);
	_g_object_unref0 (self->priv->button);
	self->priv->button = _tmp40_;
	_tmp41_ = self->priv->_button_type;
	if (_tmp41_ == DEADLINE_BUTTON_TYPE_CARD) {
		GtkMenuButton* _tmp42_;
		GtkMenuButton* _tmp43_;
		gtk_widget_add_css_class ((GtkWidget*) self, "card");
		gtk_widget_add_css_class ((GtkWidget*) self, "activatable");
		_tmp42_ = self->priv->button;
		gtk_widget_add_css_class ((GtkWidget*) _tmp42_, "menu-button-no-padding");
		_tmp43_ = self->priv->button;
		gtk_widget_set_hexpand ((GtkWidget*) _tmp43_, TRUE);
	}
	_g_object_unref0 (button_child);
}

static void
widgets_deadline_button_build_ui (WidgetsDeadlineButton* self)
{
	GtkRevealerTransitionType _tmp0_ = 0;
	DeadlineButtonType _tmp1_;
	GtkRevealerTransitionType transition_type = 0;
	GtkMenuButton* _tmp2_;
	GtkWidget* _tmp3_;
	GtkRevealer* _tmp4_ = NULL;
	GtkRevealer* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp1_ = self->priv->_button_type;
	if (_tmp1_ == DEADLINE_BUTTON_TYPE_BUTTON) {
		_tmp0_ = GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT;
	} else {
		_tmp0_ = GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN;
	}
	transition_type = _tmp0_;
	_tmp2_ = self->priv->button;
	_tmp3_ = _g_object_ref0 ((GtkWidget*) _tmp2_);
	_tmp4_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp4_, transition_type);
	gtk_revealer_set_child (_tmp4_, _tmp3_);
	_g_object_unref0 (_tmp3_);
	gtk_revealer_set_reveal_child (_tmp4_, TRUE);
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->main_revealer);
	self->priv->main_revealer = _tmp4_;
	_tmp5_ = self->priv->main_revealer;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp5_);
}

static Block20Data*
block20_data_ref (Block20Data* _data20_)
{
	g_atomic_int_inc (&_data20_->_ref_count_);
	return _data20_;
}

static void
block20_data_unref (void * _userdata_)
{
	Block20Data* _data20_;
	_data20_ = (Block20Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data20_->_ref_count_)) {
		WidgetsDeadlineButton* self;
		self = _data20_->self;
		_g_object_unref0 (_data20_->popover);
		_g_object_unref0 (self);
		g_slice_free (Block20Data, _data20_);
	}
}

static void
__lambda253_ (Block20Data* _data20_)
{
	WidgetsDeadlineButton* self;
	WidgetsCalendarCalendar* _tmp0_;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	self = _data20_->self;
	_tmp0_ = self->priv->calendar_view;
	_tmp1_ = widgets_calendar_calendar_get_date (_tmp0_);
	_tmp2_ = _tmp1_;
	g_signal_emit (self, widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_DATE_SELECTED_SIGNAL], 0, _tmp2_);
	gtk_widget_hide ((GtkWidget*) _data20_->popover);
}

static void
___lambda253__widgets_calendar_calendar_day_selected (WidgetsCalendarCalendar* _sender,
                                                      gpointer self)
{
	__lambda253_ (self);
}

static void
__lambda254_ (Block20Data* _data20_)
{
	WidgetsDeadlineButton* self;
	WidgetsCalendarCalendar* _tmp0_;
	GtkRevealer* _tmp1_;
	self = _data20_->self;
	g_signal_emit (self, widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_DATE_SELECTED_SIGNAL], 0, NULL);
	_tmp0_ = self->priv->calendar_view;
	widgets_calendar_calendar_reset (_tmp0_);
	_tmp1_ = self->priv->delete_revealer;
	gtk_revealer_set_reveal_child (_tmp1_, FALSE);
	gtk_widget_hide ((GtkWidget*) _data20_->popover);
}

static void
___lambda254__gtk_button_clicked (GtkButton* _sender,
                                  gpointer self)
{
	__lambda254_ (self);
}

GtkPopover*
widgets_deadline_button_build_popover (WidgetsDeadlineButton* self)
{
	Block20Data* _data20_;
	WidgetsCalendarCalendar* _tmp0_;
	GtkButton* delete_button = NULL;
	GtkButton* _tmp1_ = NULL;
	GtkWidget* _tmp2_;
	GtkRevealer* _tmp3_ = NULL;
	GtkBox* content_box = NULL;
	GtkBox* _tmp4_;
	WidgetsCalendarCalendar* _tmp5_;
	GtkRevealer* _tmp6_;
	GtkWidget* _tmp7_;
	GtkPopover* _tmp8_ = NULL;
	WidgetsCalendarCalendar* _tmp9_;
	GtkPopover* _tmp10_;
	GtkPopover* result;
	g_return_val_if_fail (self != NULL, NULL);
	_data20_ = g_slice_new0 (Block20Data);
	_data20_->_ref_count_ = 1;
	_data20_->self = g_object_ref (self);
	_tmp0_ = widgets_calendar_calendar_new (TRUE);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->calendar_view);
	self->priv->calendar_view = _tmp0_;
	_tmp1_ = (GtkButton*) gtk_button_new_with_label (_ ("Delete"));
	gtk_widget_set_margin_top ((GtkWidget*) _tmp1_, 12);
	g_object_ref_sink (_tmp1_);
	delete_button = _tmp1_;
	gtk_widget_add_css_class ((GtkWidget*) delete_button, "destructive-action");
	_tmp2_ = _g_object_ref0 ((GtkWidget*) delete_button);
	_tmp3_ = (GtkRevealer*) gtk_revealer_new ();
	gtk_revealer_set_transition_type (_tmp3_, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
	gtk_revealer_set_child (_tmp3_, _tmp2_);
	_g_object_unref0 (_tmp2_);
	gtk_revealer_set_reveal_child (_tmp3_, FALSE);
	g_object_ref_sink (_tmp3_);
	_g_object_unref0 (self->priv->delete_revealer);
	self->priv->delete_revealer = _tmp3_;
	_tmp4_ = (GtkBox*) gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	g_object_ref_sink (_tmp4_);
	content_box = _tmp4_;
	_tmp5_ = self->priv->calendar_view;
	gtk_box_append (content_box, (GtkWidget*) _tmp5_);
	_tmp6_ = self->priv->delete_revealer;
	gtk_box_append (content_box, (GtkWidget*) _tmp6_);
	_tmp7_ = _g_object_ref0 ((GtkWidget*) content_box);
	_tmp8_ = (GtkPopover*) gtk_popover_new ();
	gtk_popover_set_has_arrow (_tmp8_, FALSE);
	gtk_popover_set_child (_tmp8_, _tmp7_);
	_g_object_unref0 (_tmp7_);
	gtk_popover_set_position (_tmp8_, GTK_POS_BOTTOM);
	g_object_ref_sink (_tmp8_);
	_data20_->popover = _tmp8_;
	_tmp9_ = self->priv->calendar_view;
	g_signal_connect_data (_tmp9_, "day-selected", (GCallback) ___lambda253__widgets_calendar_calendar_day_selected, block20_data_ref (_data20_), (GClosureNotify) block20_data_unref, 0);
	g_signal_connect_data (delete_button, "clicked", (GCallback) ___lambda254__gtk_button_clicked, block20_data_ref (_data20_), (GClosureNotify) block20_data_unref, 0);
	_tmp10_ = _g_object_ref0 (_data20_->popover);
	result = _tmp10_;
	_g_object_unref0 (content_box);
	_g_object_unref0 (delete_button);
	block20_data_unref (_data20_);
	_data20_ = NULL;
	return result;
}

static gchar*
widgets_deadline_button_get_date_format (WidgetsDeadlineButton* self,
                                         GDateTime* date)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = utils_datetime_get_short_date_format_from_date (date);
	result = _tmp0_;
	return result;
}

static gchar*
widgets_deadline_button_get_relative_date_format (WidgetsDeadlineButton* self,
                                                  GDateTime* date)
{
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (date != NULL, NULL);
	_tmp0_ = utils_datetime_get_relative_time_from_date (date);
	result = _tmp0_;
	return result;
}

static void
widgets_deadline_button_update_error_style (WidgetsDeadlineButton* self,
                                            GDateTime* date)
{
	GDateTime* date_only = NULL;
	GDateTime* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	GDateTime* _tmp3_;
	gboolean is_overdue = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = utils_datetime_get_date_only (date);
	date_only = _tmp0_;
	_tmp3_ = date_only;
	if (utils_datetime_is_today (_tmp3_)) {
		_tmp2_ = TRUE;
	} else {
		GDateTime* _tmp4_;
		_tmp4_ = date_only;
		_tmp2_ = utils_datetime_is_yesterday (_tmp4_);
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		GDateTime* _tmp5_;
		_tmp5_ = date_only;
		_tmp1_ = utils_datetime_is_overdue (_tmp5_);
	}
	is_overdue = _tmp1_;
	if (is_overdue) {
		GtkLabel* _tmp6_;
		GtkImage* _tmp7_;
		_tmp6_ = self->priv->deadline_date_label;
		gtk_widget_add_css_class ((GtkWidget*) _tmp6_, "error");
		_tmp7_ = self->priv->deadline_icon;
		gtk_widget_add_css_class ((GtkWidget*) _tmp7_, "error");
	} else {
		GtkLabel* _tmp8_;
		GtkImage* _tmp9_;
		_tmp8_ = self->priv->deadline_date_label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp8_, "error");
		_tmp9_ = self->priv->deadline_icon;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp9_, "error");
	}
	_g_date_time_unref0 (date_only);
}

static void
widgets_deadline_button_update_card_error_style (WidgetsDeadlineButton* self,
                                                 GDateTime* date)
{
	GDateTime* date_only = NULL;
	GDateTime* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	GDateTime* _tmp3_;
	gboolean is_overdue = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (date != NULL);
	_tmp0_ = utils_datetime_get_date_only (date);
	date_only = _tmp0_;
	_tmp3_ = date_only;
	if (utils_datetime_is_today (_tmp3_)) {
		_tmp2_ = TRUE;
	} else {
		GDateTime* _tmp4_;
		_tmp4_ = date_only;
		_tmp2_ = utils_datetime_is_yesterday (_tmp4_);
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		GDateTime* _tmp5_;
		_tmp5_ = date_only;
		_tmp1_ = utils_datetime_is_overdue (_tmp5_);
	}
	is_overdue = _tmp1_;
	if (is_overdue) {
		GtkLabel* _tmp6_;
		GtkImage* _tmp7_;
		_tmp6_ = self->priv->deadline_label;
		gtk_widget_add_css_class ((GtkWidget*) _tmp6_, "error");
		_tmp7_ = self->priv->deadline_icon;
		gtk_widget_add_css_class ((GtkWidget*) _tmp7_, "error");
	} else {
		GtkLabel* _tmp8_;
		GtkImage* _tmp9_;
		_tmp8_ = self->priv->deadline_label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp8_, "error");
		_tmp9_ = self->priv->deadline_icon;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp9_, "error");
	}
	_g_date_time_unref0 (date_only);
}

void
widgets_deadline_button_remove_error_style (WidgetsDeadlineButton* self)
{
	DeadlineButtonType _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_button_type;
	if (_tmp0_ == DEADLINE_BUTTON_TYPE_BUTTON_DETAIL) {
		GtkLabel* _tmp1_;
		GtkImage* _tmp2_;
		_tmp1_ = self->priv->deadline_date_label;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp1_, "error");
		_tmp2_ = self->priv->deadline_icon;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp2_, "error");
	} else {
		DeadlineButtonType _tmp3_;
		_tmp3_ = self->priv->_button_type;
		if (_tmp3_ == DEADLINE_BUTTON_TYPE_CARD) {
			GtkLabel* _tmp4_;
			GtkImage* _tmp5_;
			_tmp4_ = self->priv->deadline_label;
			gtk_widget_remove_css_class ((GtkWidget*) _tmp4_, "error");
			_tmp5_ = self->priv->deadline_icon;
			gtk_widget_remove_css_class ((GtkWidget*) _tmp5_, "error");
		}
	}
}

DeadlineButtonType
widgets_deadline_button_get_button_type (WidgetsDeadlineButton* self)
{
	DeadlineButtonType result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_button_type;
	return result;
}

static void
widgets_deadline_button_set_button_type (WidgetsDeadlineButton* self,
                                         DeadlineButtonType value)
{
	DeadlineButtonType old_value;
	g_return_if_fail (self != NULL);
	old_value = widgets_deadline_button_get_button_type (self);
	if (old_value != value) {
		self->priv->_button_type = value;
		g_object_notify_by_pspec ((GObject *) self, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY]);
	}
}

void
widgets_deadline_button_set_datetime (WidgetsDeadlineButton* self,
                                      GDateTime* value)
{
	WidgetsCalendarCalendar* _tmp0_;
	GtkRevealer* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->calendar_view;
	widgets_calendar_calendar_set_date (_tmp0_, value);
	_tmp1_ = self->priv->delete_revealer;
	gtk_revealer_set_reveal_child (_tmp1_, value != NULL);
	if (value == NULL) {
		WidgetsCalendarCalendar* _tmp2_;
		DeadlineButtonType _tmp3_;
		_tmp2_ = self->priv->calendar_view;
		widgets_calendar_calendar_reset (_tmp2_);
		_tmp3_ = self->priv->_button_type;
		if (_tmp3_ == DEADLINE_BUTTON_TYPE_BUTTON_DETAIL) {
			GtkImage* _tmp4_;
			GtkLabel* _tmp5_;
			GtkLabel* _tmp6_;
			GtkLabel* _tmp7_;
			_tmp4_ = self->priv->deadline_icon;
			gtk_widget_remove_css_class ((GtkWidget*) _tmp4_, "error");
			_tmp5_ = self->priv->deadline_date_label;
			gtk_label_set_label (_tmp5_, _ ("Set Deadline"));
			_tmp6_ = self->priv->deadline_date_label;
			gtk_widget_remove_css_class ((GtkWidget*) _tmp6_, "error");
			_tmp7_ = self->priv->deadline_relative_label;
			gtk_label_set_label (_tmp7_, _ ("The latest date to complete this task"));
		} else {
			DeadlineButtonType _tmp8_;
			_tmp8_ = self->priv->_button_type;
			if (_tmp8_ == DEADLINE_BUTTON_TYPE_CARD) {
				GtkLabel* _tmp9_;
				GtkLabel* _tmp10_;
				GtkImage* _tmp11_;
				_tmp9_ = self->priv->deadline_label;
				gtk_label_set_label (_tmp9_, _ ("What is the latest date to complete this?"));
				_tmp10_ = self->priv->deadline_label;
				gtk_widget_set_tooltip_text ((GtkWidget*) _tmp10_, NULL);
				_tmp11_ = self->priv->deadline_icon;
				gtk_widget_remove_css_class ((GtkWidget*) _tmp11_, "error");
			}
		}
	} else {
		DeadlineButtonType _tmp12_;
		_tmp12_ = self->priv->_button_type;
		if (_tmp12_ == DEADLINE_BUTTON_TYPE_BUTTON_DETAIL) {
			GtkLabel* _tmp13_;
			gchar* _tmp14_;
			gchar* _tmp15_;
			GtkLabel* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			_tmp13_ = self->priv->deadline_date_label;
			_tmp14_ = widgets_deadline_button_get_date_format (self, value);
			_tmp15_ = _tmp14_;
			gtk_label_set_label (_tmp13_, _tmp15_);
			_g_free0 (_tmp15_);
			_tmp16_ = self->priv->deadline_relative_label;
			_tmp17_ = widgets_deadline_button_get_relative_date_format (self, value);
			_tmp18_ = _tmp17_;
			gtk_label_set_label (_tmp16_, _tmp18_);
			_g_free0 (_tmp18_);
			widgets_deadline_button_update_error_style (self, value);
		} else {
			DeadlineButtonType _tmp19_;
			_tmp19_ = self->priv->_button_type;
			if (_tmp19_ == DEADLINE_BUTTON_TYPE_CARD) {
				GtkLabel* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* _tmp23_;
				gchar* _tmp24_;
				gchar* _tmp25_;
				gchar* _tmp26_;
				GtkLabel* _tmp27_;
				GtkLabel* _tmp28_;
				const gchar* _tmp29_;
				const gchar* _tmp30_;
				_tmp20_ = self->priv->deadline_label;
				_tmp21_ = widgets_deadline_button_get_date_format (self, value);
				_tmp22_ = _tmp21_;
				_tmp23_ = widgets_deadline_button_get_relative_date_format (self, value);
				_tmp24_ = _tmp23_;
				_tmp25_ = g_strdup_printf ("%s, %s", _tmp22_, _tmp24_);
				_tmp26_ = _tmp25_;
				gtk_label_set_label (_tmp20_, _tmp26_);
				_g_free0 (_tmp26_);
				_g_free0 (_tmp24_);
				_g_free0 (_tmp22_);
				_tmp27_ = self->priv->deadline_label;
				_tmp28_ = self->priv->deadline_label;
				_tmp29_ = gtk_label_get_label (_tmp28_);
				_tmp30_ = _tmp29_;
				gtk_widget_set_tooltip_text ((GtkWidget*) _tmp27_, _tmp30_);
				widgets_deadline_button_update_card_error_style (self, value);
			}
		}
	}
	g_object_notify_by_pspec ((GObject *) self, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_DATETIME_PROPERTY]);
}

void
widgets_deadline_button_set_reveal_content (WidgetsDeadlineButton* self,
                                            gboolean value)
{
	GtkRevealer* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->main_revealer;
	gtk_revealer_set_reveal_child (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_REVEAL_CONTENT_PROPERTY]);
}

static void
_widgets_deadline_button___lambda255_ (WidgetsDeadlineButton* self)
{
	g_signal_emit (self, widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_PICKER_OPENED_SIGNAL], 0, FALSE);
}

static void
__widgets_deadline_button___lambda255__gtk_popover_closed (GtkPopover* _sender,
                                                           gpointer self)
{
	_widgets_deadline_button___lambda255_ ((WidgetsDeadlineButton*) self);
}

static void
_widgets_deadline_button___lambda256_ (WidgetsDeadlineButton* self)
{
	g_signal_emit (self, widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_PICKER_OPENED_SIGNAL], 0, TRUE);
}

static void
__widgets_deadline_button___lambda256__gtk_widget_show (GtkWidget* _sender,
                                                        gpointer self)
{
	_widgets_deadline_button___lambda256_ ((WidgetsDeadlineButton*) self);
}

static GObject *
widgets_deadline_button_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsDeadlineButton * self;
	GtkPopover* _tmp0_;
	GtkPopover* _tmp1_;
	GtkPopover* _tmp2_;
	parent_class = G_OBJECT_CLASS (widgets_deadline_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_DEADLINE_BUTTON, WidgetsDeadlineButton);
	_tmp0_ = widgets_deadline_button_build_popover (self);
	_g_object_unref0 (self->priv->calendar_popover);
	self->priv->calendar_popover = _tmp0_;
	widgets_deadline_button_build_button_content (self);
	widgets_deadline_button_build_ui (self);
	_tmp1_ = self->priv->calendar_popover;
	g_signal_connect_object (_tmp1_, "closed", (GCallback) __widgets_deadline_button___lambda255__gtk_popover_closed, self, 0);
	_tmp2_ = self->priv->calendar_popover;
	g_signal_connect_object ((GtkWidget*) _tmp2_, "show", (GCallback) __widgets_deadline_button___lambda256__gtk_widget_show, self, 0);
	return obj;
}

static void
widgets_deadline_button_class_init (WidgetsDeadlineButtonClass * klass,
                                    gpointer klass_data)
{
	widgets_deadline_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsDeadlineButton_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_widgets_deadline_button_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_widgets_deadline_button_set_property;
	G_OBJECT_CLASS (klass)->constructor = widgets_deadline_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_deadline_button_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY] = g_param_spec_enum ("button-type", "button-type", "button-type", TYPE_DEADLINE_BUTTON_TYPE, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_DEADLINE_BUTTON_DATETIME_PROPERTY, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_DATETIME_PROPERTY] = g_param_spec_boxed ("datetime", "datetime", "datetime", G_TYPE_DATE_TIME, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), WIDGETS_DEADLINE_BUTTON_REVEAL_CONTENT_PROPERTY, widgets_deadline_button_properties[WIDGETS_DEADLINE_BUTTON_REVEAL_CONTENT_PROPERTY] = g_param_spec_boolean ("reveal-content", "reveal-content", "reveal-content", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE));
	widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_DATE_SELECTED_SIGNAL] = g_signal_new ("date-selected", WIDGETS_TYPE_DEADLINE_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_DATE_TIME);
	widgets_deadline_button_signals[WIDGETS_DEADLINE_BUTTON_PICKER_OPENED_SIGNAL] = g_signal_new ("picker-opened", WIDGETS_TYPE_DEADLINE_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
}

static void
widgets_deadline_button_instance_init (WidgetsDeadlineButton * self,
                                       gpointer klass)
{
	self->priv = widgets_deadline_button_get_instance_private (self);
}

static void
widgets_deadline_button_finalize (GObject * obj)
{
	WidgetsDeadlineButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_TYPE_DEADLINE_BUTTON, WidgetsDeadlineButton);
	g_debug ("DeadlineButton.vala:105: Destroying - Widgets.DeadlineButton\n");
	_g_object_unref0 (self->priv->calendar_view);
	_g_object_unref0 (self->priv->calendar_popover);
	_g_object_unref0 (self->priv->button);
	_g_object_unref0 (self->priv->delete_revealer);
	_g_object_unref0 (self->priv->deadline_label);
	_g_object_unref0 (self->priv->deadline_date_label);
	_g_object_unref0 (self->priv->deadline_relative_label);
	_g_object_unref0 (self->priv->main_revealer);
	_g_object_unref0 (self->priv->deadline_icon);
	G_OBJECT_CLASS (widgets_deadline_button_parent_class)->finalize (obj);
}

static GType
widgets_deadline_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsDeadlineButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_deadline_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsDeadlineButton), 0, (GInstanceInitFunc) widgets_deadline_button_instance_init, NULL };
	GType widgets_deadline_button_type_id;
	widgets_deadline_button_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsDeadlineButton", &g_define_type_info, 0);
	WidgetsDeadlineButton_private_offset = g_type_add_instance_private (widgets_deadline_button_type_id, sizeof (WidgetsDeadlineButtonPrivate));
	return widgets_deadline_button_type_id;
}

GType
widgets_deadline_button_get_type (void)
{
	static volatile gsize widgets_deadline_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_deadline_button_type_id__once)) {
		GType widgets_deadline_button_type_id;
		widgets_deadline_button_type_id = widgets_deadline_button_get_type_once ();
		g_once_init_leave (&widgets_deadline_button_type_id__once, widgets_deadline_button_type_id);
	}
	return widgets_deadline_button_type_id__once;
}

static void
_vala_widgets_deadline_button_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec)
{
	WidgetsDeadlineButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_DEADLINE_BUTTON, WidgetsDeadlineButton);
	switch (property_id) {
		case WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY:
		g_value_set_enum (value, widgets_deadline_button_get_button_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_widgets_deadline_button_set_property (GObject * object,
                                            guint property_id,
                                            const GValue * value,
                                            GParamSpec * pspec)
{
	WidgetsDeadlineButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, WIDGETS_TYPE_DEADLINE_BUTTON, WidgetsDeadlineButton);
	switch (property_id) {
		case WIDGETS_DEADLINE_BUTTON_BUTTON_TYPE_PROPERTY:
		widgets_deadline_button_set_button_type (self, g_value_get_enum (value));
		break;
		case WIDGETS_DEADLINE_BUTTON_DATETIME_PROPERTY:
		widgets_deadline_button_set_datetime (self, g_value_get_boxed (value));
		break;
		case WIDGETS_DEADLINE_BUTTON_REVEAL_CONTENT_PROPERTY:
		widgets_deadline_button_set_reveal_content (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;
}

