/* SectionButton.c generated by valac 0.56.19, the Vala compiler
 * generated from SectionButton.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-object.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gee.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_SECTION_PICKER_SECTION_BUTTON_0_PROPERTY,
	WIDGETS_SECTION_PICKER_SECTION_BUTTON_NUM_PROPERTIES
};
static GParamSpec* widgets_section_picker_section_button_properties[WIDGETS_SECTION_PICKER_SECTION_BUTTON_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	WIDGETS_SECTION_PICKER_SECTION_BUTTON_SELECTED_SIGNAL,
	WIDGETS_SECTION_PICKER_SECTION_BUTTON_NUM_SIGNALS
};
static guint widgets_section_picker_section_button_signals[WIDGETS_SECTION_PICKER_SECTION_BUTTON_NUM_SIGNALS] = {0};

struct _WidgetsSectionPickerSectionButtonPrivate {
	GtkLabel* section_label;
	WidgetsSectionPickerSectionPicker* picker;
};

static gint WidgetsSectionPickerSectionButton_private_offset;
static gpointer widgets_section_picker_section_button_parent_class = NULL;

static GObject * widgets_section_picker_section_button_constructor (GType type,
                                                             guint n_construct_properties,
                                                             GObjectConstructParam * construct_properties);
static void _widgets_section_picker_section_button___lambda370_ (WidgetsSectionPickerSectionButton* self,
                                                          ObjectsSection* section);
static void __widgets_section_picker_section_button___lambda370__widgets_section_picker_section_picker_selected (WidgetsSectionPickerSectionPicker* _sender,
                                                                                                          ObjectsSection* section,
                                                                                                          gpointer self);
static void widgets_section_picker_section_button_finalize (GObject * obj);
static GType widgets_section_picker_section_button_get_type_once (void);
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_section_picker_section_button_get_instance_private (WidgetsSectionPickerSectionButton* self)
{
	return G_STRUCT_MEMBER_P (self, WidgetsSectionPickerSectionButton_private_offset);
}

WidgetsSectionPickerSectionButton*
widgets_section_picker_section_button_construct (GType object_type)
{
	WidgetsSectionPickerSectionButton * self = NULL;
	self = (WidgetsSectionPickerSectionButton*) g_object_new (object_type, "tooltip-text", _ ("Set Section"), NULL);
	return self;
}

WidgetsSectionPickerSectionButton*
widgets_section_picker_section_button_new (void)
{
	return widgets_section_picker_section_button_construct (WIDGETS_SECTION_PICKER_TYPE_SECTION_BUTTON);
}

void
widgets_section_picker_section_button_set_sections (WidgetsSectionPickerSectionButton* self,
                                                    GeeArrayList* sections)
{
	WidgetsSectionPickerSectionPicker* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sections != NULL);
	_tmp0_ = self->priv->picker;
	widgets_section_picker_section_picker_set_sections (_tmp0_, sections);
}

void
widgets_section_picker_section_button_update_from_item (WidgetsSectionPickerSectionButton* self,
                                                        ObjectsItem* item)
{
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	WidgetsSectionPickerSectionPicker* _tmp16_;
	const gchar* _tmp17_;
	const gchar* _tmp18_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	_tmp0_ = self->priv->section_label;
	gtk_label_set_label (_tmp0_, _ ("No Section"));
	_tmp1_ = self->priv->section_label;
	gtk_widget_set_tooltip_text ((GtkWidget*) _tmp1_, NULL);
	_tmp2_ = objects_item_get_parent_id (item);
	_tmp3_ = _tmp2_;
	if (g_strcmp0 (_tmp3_, "") != 0) {
		return;
	}
	_tmp4_ = objects_item_get_section_id (item);
	_tmp5_ = _tmp4_;
	if (g_strcmp0 (_tmp5_, "") != 0) {
		GtkLabel* _tmp6_;
		ObjectsSection* _tmp7_;
		ObjectsSection* _tmp8_;
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		GtkLabel* _tmp11_;
		ObjectsSection* _tmp12_;
		ObjectsSection* _tmp13_;
		const gchar* _tmp14_;
		const gchar* _tmp15_;
		_tmp6_ = self->priv->section_label;
		_tmp7_ = objects_item_get_section (item);
		_tmp8_ = _tmp7_;
		_tmp9_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp8_);
		_tmp10_ = _tmp9_;
		gtk_label_set_label (_tmp6_, _tmp10_);
		_tmp11_ = self->priv->section_label;
		_tmp12_ = objects_item_get_section (item);
		_tmp13_ = _tmp12_;
		_tmp14_ = objects_base_object_get_name ((ObjectsBaseObject*) _tmp13_);
		_tmp15_ = _tmp14_;
		gtk_widget_set_tooltip_text ((GtkWidget*) _tmp11_, _tmp15_);
	}
	_tmp16_ = self->priv->picker;
	_tmp17_ = objects_item_get_section_id (item);
	_tmp18_ = _tmp17_;
	widgets_section_picker_section_picker_set_section (_tmp16_, _tmp18_);
}

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

static void
_widgets_section_picker_section_button___lambda370_ (WidgetsSectionPickerSectionButton* self,
                                                     ObjectsSection* section)
{
	g_return_if_fail (section != NULL);
	g_signal_emit (self, widgets_section_picker_section_button_signals[WIDGETS_SECTION_PICKER_SECTION_BUTTON_SELECTED_SIGNAL], 0, section);
}

static void
__widgets_section_picker_section_button___lambda370__widgets_section_picker_section_picker_selected (WidgetsSectionPickerSectionPicker* _sender,
                                                                                                     ObjectsSection* section,
                                                                                                     gpointer self)
{
	_widgets_section_picker_section_button___lambda370_ ((WidgetsSectionPickerSectionButton*) self, section);
}

static GObject *
widgets_section_picker_section_button_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	WidgetsSectionPickerSectionButton * self;
	GtkLabel* title_label = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar** _tmp3_;
	GtkLabel* _tmp4_ = NULL;
	gchar* _tmp5_;
	gchar** _tmp6_;
	GtkLabel* _tmp7_ = NULL;
	GtkGrid* card_grid = NULL;
	GtkGrid* _tmp8_ = NULL;
	GtkGrid* _tmp9_;
	GtkImage* _tmp10_;
	GtkImage* _tmp11_;
	GtkGrid* _tmp12_;
	GtkLabel* _tmp13_;
	GtkGrid* _tmp14_;
	GtkLabel* _tmp15_;
	WidgetsSectionPickerSectionPicker* _tmp16_;
	GtkMenuButton* menu_button = NULL;
	WidgetsSectionPickerSectionPicker* _tmp17_;
	GtkPopover* _tmp18_;
	GtkGrid* _tmp19_;
	GtkWidget* _tmp20_;
	gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gchar** _tmp25_;
	GtkMenuButton* _tmp26_ = NULL;
	GtkMenuButton* _tmp27_;
	WidgetsSectionPickerSectionPicker* _tmp28_;
	parent_class = G_OBJECT_CLASS (widgets_section_picker_section_button_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_SECTION_PICKER_TYPE_SECTION_BUTTON, WidgetsSectionPickerSectionButton);
	_tmp0_ = g_strdup ("title-4");
	_tmp1_ = g_strdup ("caption");
	_tmp2_ = g_strdup ("font-bold");
	_tmp3_ = g_new0 (gchar*, 3 + 1);
	_tmp3_[0] = _tmp0_;
	_tmp3_[1] = _tmp1_;
	_tmp3_[2] = _tmp2_;
	_tmp4_ = (GtkLabel*) gtk_label_new (_ ("Section"));
	gtk_widget_set_halign ((GtkWidget*) _tmp4_, GTK_ALIGN_START);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp4_, _tmp3_);
	_tmp3_ = (_vala_array_free (_tmp3_, 3, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp4_);
	title_label = _tmp4_;
	_tmp5_ = g_strdup ("caption");
	_tmp6_ = g_new0 (gchar*, 1 + 1);
	_tmp6_[0] = _tmp5_;
	_tmp7_ = (GtkLabel*) gtk_label_new (_ ("Select Section"));
	gtk_label_set_xalign (_tmp7_, (gfloat) 0);
	gtk_label_set_use_markup (_tmp7_, TRUE);
	gtk_widget_set_halign ((GtkWidget*) _tmp7_, GTK_ALIGN_START);
	gtk_label_set_ellipsize (_tmp7_, PANGO_ELLIPSIZE_END);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp7_, _tmp6_);
	_tmp6_ = (_vala_array_free (_tmp6_, 1, (GDestroyNotify) g_free), NULL);
	g_object_ref_sink (_tmp7_);
	_g_object_unref0 (self->priv->section_label);
	self->priv->section_label = _tmp7_;
	_tmp8_ = (GtkGrid*) gtk_grid_new ();
	gtk_grid_set_column_spacing (_tmp8_, 12);
	gtk_widget_set_margin_start ((GtkWidget*) _tmp8_, 12);
	gtk_widget_set_margin_end ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_margin_top ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_margin_bottom ((GtkWidget*) _tmp8_, 6);
	gtk_widget_set_vexpand ((GtkWidget*) _tmp8_, TRUE);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp8_, TRUE);
	g_object_ref_sink (_tmp8_);
	card_grid = _tmp8_;
	_tmp9_ = card_grid;
	_tmp10_ = (GtkImage*) gtk_image_new_from_icon_name ("arrow3-right-symbolic");
	g_object_ref_sink (_tmp10_);
	_tmp11_ = _tmp10_;
	gtk_grid_attach (_tmp9_, (GtkWidget*) _tmp11_, 0, 0, 1, 2);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = card_grid;
	_tmp13_ = title_label;
	gtk_grid_attach (_tmp12_, (GtkWidget*) _tmp13_, 1, 0, 1, 1);
	_tmp14_ = card_grid;
	_tmp15_ = self->priv->section_label;
	gtk_grid_attach (_tmp14_, (GtkWidget*) _tmp15_, 1, 1, 1, 1);
	_tmp16_ = widgets_section_picker_section_picker_new ();
	g_object_ref_sink (_tmp16_);
	_g_object_unref0 (self->priv->picker);
	self->priv->picker = _tmp16_;
	_tmp17_ = self->priv->picker;
	_tmp18_ = _g_object_ref0 ((GtkPopover*) _tmp17_);
	_tmp19_ = card_grid;
	_tmp20_ = _g_object_ref0 ((GtkWidget*) _tmp19_);
	_tmp21_ = g_strdup ("flat");
	_tmp22_ = g_strdup ("card");
	_tmp23_ = g_strdup ("activatable");
	_tmp24_ = g_strdup ("menu-button-no-padding");
	_tmp25_ = g_new0 (gchar*, 4 + 1);
	_tmp25_[0] = _tmp21_;
	_tmp25_[1] = _tmp22_;
	_tmp25_[2] = _tmp23_;
	_tmp25_[3] = _tmp24_;
	_tmp26_ = (GtkMenuButton*) gtk_menu_button_new ();
	gtk_menu_button_set_popover (_tmp26_, _tmp18_);
	_g_object_unref0 (_tmp18_);
	gtk_menu_button_set_child (_tmp26_, _tmp20_);
	_g_object_unref0 (_tmp20_);
	gtk_widget_set_css_classes ((GtkWidget*) _tmp26_, _tmp25_);
	_tmp25_ = (_vala_array_free (_tmp25_, 4, (GDestroyNotify) g_free), NULL);
	gtk_widget_set_hexpand ((GtkWidget*) _tmp26_, TRUE);
	g_object_ref_sink (_tmp26_);
	menu_button = _tmp26_;
	_tmp27_ = menu_button;
	adw_bin_set_child ((AdwBin*) self, (GtkWidget*) _tmp27_);
	_tmp28_ = self->priv->picker;
	g_signal_connect_object (_tmp28_, "selected", (GCallback) __widgets_section_picker_section_button___lambda370__widgets_section_picker_section_picker_selected, self, 0);
	_g_object_unref0 (menu_button);
	_g_object_unref0 (card_grid);
	_g_object_unref0 (title_label);
	return obj;
}

static void
widgets_section_picker_section_button_class_init (WidgetsSectionPickerSectionButtonClass * klass,
                                                  gpointer klass_data)
{
	widgets_section_picker_section_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &WidgetsSectionPickerSectionButton_private_offset);
	G_OBJECT_CLASS (klass)->constructor = widgets_section_picker_section_button_constructor;
	G_OBJECT_CLASS (klass)->finalize = widgets_section_picker_section_button_finalize;
	widgets_section_picker_section_button_signals[WIDGETS_SECTION_PICKER_SECTION_BUTTON_SELECTED_SIGNAL] = g_signal_new ("selected", WIDGETS_SECTION_PICKER_TYPE_SECTION_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, OBJECTS_TYPE_SECTION);
}

static void
widgets_section_picker_section_button_instance_init (WidgetsSectionPickerSectionButton * self,
                                                     gpointer klass)
{
	self->priv = widgets_section_picker_section_button_get_instance_private (self);
}

static void
widgets_section_picker_section_button_finalize (GObject * obj)
{
	WidgetsSectionPickerSectionButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, WIDGETS_SECTION_PICKER_TYPE_SECTION_BUTTON, WidgetsSectionPickerSectionButton);
	_g_object_unref0 (self->priv->section_label);
	_g_object_unref0 (self->priv->picker);
	G_OBJECT_CLASS (widgets_section_picker_section_button_parent_class)->finalize (obj);
}

static GType
widgets_section_picker_section_button_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (WidgetsSectionPickerSectionButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) widgets_section_picker_section_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (WidgetsSectionPickerSectionButton), 0, (GInstanceInitFunc) widgets_section_picker_section_button_instance_init, NULL };
	GType widgets_section_picker_section_button_type_id;
	widgets_section_picker_section_button_type_id = g_type_register_static (adw_bin_get_type (), "WidgetsSectionPickerSectionButton", &g_define_type_info, 0);
	WidgetsSectionPickerSectionButton_private_offset = g_type_add_instance_private (widgets_section_picker_section_button_type_id, sizeof (WidgetsSectionPickerSectionButtonPrivate));
	return widgets_section_picker_section_button_type_id;
}

GType
widgets_section_picker_section_button_get_type (void)
{
	static volatile gsize widgets_section_picker_section_button_type_id__once = 0;
	if (g_once_init_enter (&widgets_section_picker_section_button_type_id__once)) {
		GType widgets_section_picker_section_button_type_id;
		widgets_section_picker_section_button_type_id = widgets_section_picker_section_button_get_type_once ();
		g_once_init_leave (&widgets_section_picker_section_button_type_id__once, widgets_section_picker_section_button_type_id);
	}
	return widgets_section_picker_section_button_type_id__once;
}

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;
}

