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

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <gtk/gtk.h>
#include <glib.h>
#include <glib-object.h>
#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <cairo-gobject.h>
#include "ft_ui.h"
#include <float.h>
#include <math.h>
#include <pango/pango.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

typedef struct _FtTimeLabel FtTimeLabel;
typedef struct _FtTimeLabelClass FtTimeLabelClass;
typedef struct _FtTimeLabelPrivate FtTimeLabelPrivate;
enum  {
	FT_TIME_LABEL_0_PROPERTY,
	FT_TIME_LABEL_TIMESTAMP_PROPERTY,
	FT_TIME_LABEL_XALIGN_PROPERTY,
	FT_TIME_LABEL_NUM_PROPERTIES
};
static GParamSpec* ft_time_label_properties[FT_TIME_LABEL_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))

struct _FtTimeLabel {
	GtkWidget parent_instance;
	FtTimeLabelPrivate * priv;
};

struct _FtTimeLabelClass {
	GtkWidgetClass parent_class;
};

struct _FtTimeLabelPrivate {
	gint64 _timestamp;
	GtkLabel* label;
};

static gint FtTimeLabel_private_offset;
static gpointer ft_time_label_parent_class = NULL;

static gchar* ft_time_label_format_timestamp (FtTimeLabel* self);
static void ft_time_label_update_label (FtTimeLabel* self,
                                 gint64 timestamp);
static GtkSizeRequestMode ft_time_label_real_get_request_mode (GtkWidget* base);
static void ft_time_label_real_measure (GtkWidget* base,
                                 GtkOrientation orientation,
                                 gint for_size,
                                 gint* minimum,
                                 gint* natural,
                                 gint* minimum_baseline,
                                 gint* natural_baseline);
static void ft_time_label_real_size_allocate (GtkWidget* base,
                                       gint width,
                                       gint height,
                                       gint baseline);
static void ft_time_label_real_snapshot (GtkWidget* base,
                                  GtkSnapshot* snapshot);
static void ft_time_label_real_dispose (GObject* base);
static GObject * ft_time_label_constructor (GType type,
                                     guint n_construct_properties,
                                     GObjectConstructParam * construct_properties);
static void ft_time_label_finalize (GObject * obj);
static GType ft_time_label_get_type_once (void);
static void _vala_ft_time_label_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_ft_time_label_set_property (GObject * object,
                                       guint property_id,
                                       const GValue * value,
                                       GParamSpec * pspec);

static inline gpointer
ft_time_label_get_instance_private (FtTimeLabel* self)
{
	return G_STRUCT_MEMBER_P (self, FtTimeLabel_private_offset);
}

static gchar*
ft_time_label_format_timestamp (FtTimeLabel* self)
{
	gint64 seconds = 0LL;
	GDateTime* datetime = NULL;
	GDateTime* _tmp1_;
	GDateTime* _tmp2_;
	GDateTime* _tmp3_;
	GDateTime* _tmp4_;
	GDateTime* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->_timestamp < ((gint64) 0)) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup ("");
		result = _tmp0_;
		return result;
	}
	seconds = self->priv->_timestamp / FT_INTERVAL_SECOND;
	_tmp1_ = g_date_time_new_from_unix_utc (seconds);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_date_time_to_local (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_date_time_unref0 (_tmp2_);
	datetime = _tmp4_;
	_tmp5_ = datetime;
	_tmp6_ = g_date_time_format (_tmp5_, "%H:%M");
	result = _tmp6_;
	_g_date_time_unref0 (datetime);
	return result;
}

static void
ft_time_label_update_label (FtTimeLabel* self,
                            gint64 timestamp)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->label;
	_tmp1_ = ft_time_label_format_timestamp (self);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
}

static GtkSizeRequestMode
ft_time_label_real_get_request_mode (GtkWidget* base)
{
	FtTimeLabel * self;
	GtkSizeRequestMode result;
	self = (FtTimeLabel*) base;
	result = GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
	return result;
}

/**
         * Estimate size.
         *
         * Interpolate between two children and with-hours / without-hours.
         */
static void
ft_time_label_real_measure (GtkWidget* base,
                            GtkOrientation orientation,
                            gint for_size,
                            gint* minimum,
                            gint* natural,
                            gint* minimum_baseline,
                            gint* natural_baseline)
{
	FtTimeLabel * self;
	gint _vala_minimum = 0;
	gint _vala_natural = 0;
	gint _vala_minimum_baseline = 0;
	gint _vala_natural_baseline = 0;
	GtkLabel* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	self = (FtTimeLabel*) base;
	_tmp0_ = self->priv->label;
	gtk_widget_measure ((GtkWidget*) _tmp0_, orientation, for_size, &_tmp1_, &_tmp2_, &_tmp3_, &_tmp4_);
	_vala_minimum = _tmp1_;
	_vala_natural = _tmp2_;
	_vala_minimum_baseline = _tmp3_;
	_vala_natural_baseline = _tmp4_;
	if (minimum) {
		*minimum = _vala_minimum;
	}
	if (natural) {
		*natural = _vala_natural;
	}
	if (minimum_baseline) {
		*minimum_baseline = _vala_minimum_baseline;
	}
	if (natural_baseline) {
		*natural_baseline = _vala_natural_baseline;
	}
}

static void
ft_time_label_real_size_allocate (GtkWidget* base,
                                  gint width,
                                  gint height,
                                  gint baseline)
{
	FtTimeLabel * self;
	GtkAllocation allocation = {0};
	GtkLabel* _tmp0_;
	gint _tmp1_ = 0;
	GtkLabel* _tmp2_;
	gint _tmp3_ = 0;
	GtkAlign _tmp4_;
	GtkAlign _tmp5_;
	GtkAllocation _tmp8_;
	GtkLabel* _tmp9_;
	GtkAllocation _tmp10_;
	self = (FtTimeLabel*) base;
	memset (&allocation, 0, sizeof (GtkAllocation));
	_tmp0_ = self->priv->label;
	gtk_widget_measure ((GtkWidget*) _tmp0_, GTK_ORIENTATION_VERTICAL, height, NULL, &_tmp1_, NULL, NULL);
	allocation.height = _tmp1_;
	_tmp2_ = self->priv->label;
	gtk_widget_measure ((GtkWidget*) _tmp2_, GTK_ORIENTATION_HORIZONTAL, -1, NULL, &_tmp3_, NULL, NULL);
	allocation.width = _tmp3_;
	_tmp4_ = gtk_widget_get_halign ((GtkWidget*) self);
	_tmp5_ = _tmp4_;
	switch (_tmp5_) {
		case GTK_ALIGN_START:
		{
			allocation.x = 0;
			break;
		}
		case GTK_ALIGN_END:
		{
			GtkAllocation _tmp6_;
			_tmp6_ = allocation;
			allocation.x = width - _tmp6_.width;
			break;
		}
		case GTK_ALIGN_CENTER:
		case GTK_ALIGN_FILL:
		{
			GtkAllocation _tmp7_;
			_tmp7_ = allocation;
			allocation.x = (width - _tmp7_.width) / 2;
			break;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
	_tmp8_ = allocation;
	allocation.y = (height - _tmp8_.height) / 2;
	_tmp9_ = self->priv->label;
	_tmp10_ = allocation;
	gtk_widget_size_allocate ((GtkWidget*) _tmp9_, &_tmp10_, baseline);
}

static void
ft_time_label_real_snapshot (GtkWidget* base,
                             GtkSnapshot* snapshot)
{
	FtTimeLabel * self;
	GtkLabel* _tmp0_;
	self = (FtTimeLabel*) base;
	g_return_if_fail (snapshot != NULL);
	_tmp0_ = self->priv->label;
	gtk_widget_snapshot_child ((GtkWidget*) self, (GtkWidget*) _tmp0_, snapshot);
}

static void
ft_time_label_real_dispose (GObject* base)
{
	FtTimeLabel * self;
	GtkLabel* _tmp0_;
	self = (FtTimeLabel*) base;
	_tmp0_ = self->priv->label;
	if (_tmp0_ != NULL) {
		GtkLabel* _tmp1_;
		_tmp1_ = self->priv->label;
		gtk_widget_unparent ((GtkWidget*) _tmp1_);
		_g_object_unref0 (self->priv->label);
		self->priv->label = NULL;
	}
	G_OBJECT_CLASS (ft_time_label_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_widget_get_type (), GtkWidget));
}

FtTimeLabel*
ft_time_label_construct (GType object_type)
{
	FtTimeLabel * self = NULL;
	self = (FtTimeLabel*) g_object_new (object_type, NULL);
	return self;
}

FtTimeLabel*
ft_time_label_new (void)
{
	return ft_time_label_construct (FT_TYPE_TIME_LABEL);
}

gint64
ft_time_label_get_timestamp (FtTimeLabel* self)
{
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	result = self->priv->_timestamp;
	return result;
}

void
ft_time_label_set_timestamp (FtTimeLabel* self,
                             gint64 value)
{
	g_return_if_fail (self != NULL);
	self->priv->_timestamp = value;
	ft_time_label_update_label (self, FT_TIMESTAMP_UNDEFINED);
	g_object_notify_by_pspec ((GObject *) self, ft_time_label_properties[FT_TIME_LABEL_TIMESTAMP_PROPERTY]);
}

gfloat
ft_time_label_get_xalign (FtTimeLabel* self)
{
	gfloat result;
	GtkLabel* _tmp0_;
	gfloat _tmp1_;
	gfloat _tmp2_;
	g_return_val_if_fail (self != NULL, -1.0F);
	_tmp0_ = self->priv->label;
	_tmp1_ = gtk_label_get_xalign (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

void
ft_time_label_set_xalign (FtTimeLabel* self,
                          gfloat value)
{
	GtkLabel* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->label;
	gtk_label_set_xalign (_tmp0_, value);
	g_object_notify_by_pspec ((GObject *) self, ft_time_label_properties[FT_TIME_LABEL_XALIGN_PROPERTY]);
}

static GObject *
ft_time_label_constructor (GType type,
                           guint n_construct_properties,
                           GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	FtTimeLabel * self;
	GtkLabel* _tmp0_;
	GtkLabel* _tmp1_;
	GtkLabel* _tmp2_;
	GtkLabel* _tmp3_;
	GtkLabel* _tmp4_;
	parent_class = G_OBJECT_CLASS (ft_time_label_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_LABEL, FtTimeLabel);
	_tmp0_ = (GtkLabel*) gtk_label_new (NULL);
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->label);
	self->priv->label = _tmp0_;
	_tmp1_ = self->priv->label;
	gtk_label_set_ellipsize (_tmp1_, PANGO_ELLIPSIZE_END);
	_tmp2_ = self->priv->label;
	gtk_label_set_single_line_mode (_tmp2_, TRUE);
	_tmp3_ = self->priv->label;
	gtk_label_set_wrap (_tmp3_, FALSE);
	_tmp4_ = self->priv->label;
	gtk_widget_set_parent ((GtkWidget*) _tmp4_, (GtkWidget*) self);
	return obj;
}

static void
ft_time_label_class_init (FtTimeLabelClass * klass,
                          gpointer klass_data)
{
	ft_time_label_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtTimeLabel_private_offset);
	((GtkWidgetClass *) klass)->get_request_mode = (GtkSizeRequestMode (*) (GtkWidget*)) ft_time_label_real_get_request_mode;
	((GtkWidgetClass *) klass)->measure = (void (*) (GtkWidget*, GtkOrientation, gint, gint*, gint*, gint*, gint*)) ft_time_label_real_measure;
	((GtkWidgetClass *) klass)->size_allocate = (void (*) (GtkWidget*, gint, gint, gint)) ft_time_label_real_size_allocate;
	((GtkWidgetClass *) klass)->snapshot = (void (*) (GtkWidget*, GtkSnapshot*)) ft_time_label_real_snapshot;
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_time_label_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_time_label_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_time_label_set_property;
	G_OBJECT_CLASS (klass)->constructor = ft_time_label_constructor;
	G_OBJECT_CLASS (klass)->finalize = ft_time_label_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_LABEL_TIMESTAMP_PROPERTY, ft_time_label_properties[FT_TIME_LABEL_TIMESTAMP_PROPERTY] = g_param_spec_int64 ("timestamp", "timestamp", "timestamp", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_TIME_LABEL_XALIGN_PROPERTY, ft_time_label_properties[FT_TIME_LABEL_XALIGN_PROPERTY] = g_param_spec_float ("xalign", "xalign", "xalign", -G_MAXFLOAT, G_MAXFLOAT, 0.0F, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
ft_time_label_instance_init (FtTimeLabel * self,
                             gpointer klass)
{
	self->priv = ft_time_label_get_instance_private (self);
	self->priv->_timestamp = FT_TIMESTAMP_UNDEFINED;
}

static void
ft_time_label_finalize (GObject * obj)
{
	FtTimeLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_TIME_LABEL, FtTimeLabel);
	_g_object_unref0 (self->priv->label);
	G_OBJECT_CLASS (ft_time_label_parent_class)->finalize (obj);
}

static GType
ft_time_label_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtTimeLabelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_time_label_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtTimeLabel), 0, (GInstanceInitFunc) ft_time_label_instance_init, NULL };
	GType ft_time_label_type_id;
	ft_time_label_type_id = g_type_register_static (gtk_widget_get_type (), "FtTimeLabel", &g_define_type_info, 0);
	FtTimeLabel_private_offset = g_type_add_instance_private (ft_time_label_type_id, sizeof (FtTimeLabelPrivate));
	return ft_time_label_type_id;
}

GType
ft_time_label_get_type (void)
{
	static volatile gsize ft_time_label_type_id__once = 0;
	if (g_once_init_enter (&ft_time_label_type_id__once)) {
		GType ft_time_label_type_id;
		ft_time_label_type_id = ft_time_label_get_type_once ();
		g_once_init_leave (&ft_time_label_type_id__once, ft_time_label_type_id);
	}
	return ft_time_label_type_id__once;
}

static void
_vala_ft_time_label_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	FtTimeLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_LABEL, FtTimeLabel);
	switch (property_id) {
		case FT_TIME_LABEL_TIMESTAMP_PROPERTY:
		g_value_set_int64 (value, ft_time_label_get_timestamp (self));
		break;
		case FT_TIME_LABEL_XALIGN_PROPERTY:
		g_value_set_float (value, ft_time_label_get_xalign (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_time_label_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	FtTimeLabel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_TIME_LABEL, FtTimeLabel);
	switch (property_id) {
		case FT_TIME_LABEL_TIMESTAMP_PROPERTY:
		ft_time_label_set_timestamp (self, g_value_get_int64 (value));
		break;
		case FT_TIME_LABEL_XALIGN_PROPERTY:
		ft_time_label_set_xalign (self, g_value_get_float (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

