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

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

#include "ft_ui.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <float.h>
#include <math.h>
#include <glib-object.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  {
	FT_STATS_CARD_0_PROPERTY,
	FT_STATS_CARD_LABEL_PROPERTY,
	FT_STATS_CARD_UNIT_PROPERTY,
	FT_STATS_CARD_VALUE_PROPERTY,
	FT_STATS_CARD_NUM_PROPERTIES
};
static GParamSpec* ft_stats_card_properties[FT_STATS_CARD_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))

struct _FtStatsCardPrivate {
	gchar* _label;
	GtkLabel* value_label;
	FtUnit _unit;
	gdouble _value;
};

static gint FtStatsCard_private_offset;
static gpointer ft_stats_card_parent_class = NULL;

static void ft_stats_card_update (FtStatsCard* self);
static void ft_stats_card_finalize (GObject * obj);
static GType ft_stats_card_get_type_once (void);
static void _vala_ft_stats_card_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec);
static void _vala_ft_stats_card_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
ft_stats_card_get_instance_private (FtStatsCard* self)
{
	return G_STRUCT_MEMBER_P (self, FtStatsCard_private_offset);
}

static void
ft_stats_card_update (FtStatsCard* self)
{
	GtkLabel* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->value_label;
	_tmp1_ = ft_unit_format (self->priv->_unit, self->priv->_value);
	_tmp2_ = _tmp1_;
	gtk_label_set_label (_tmp0_, _tmp2_);
	_g_free0 (_tmp2_);
}

FtStatsCard*
ft_stats_card_construct (GType object_type)
{
	FtStatsCard * self = NULL;
	self = (FtStatsCard*) g_object_new (object_type, NULL);
	return self;
}

FtStatsCard*
ft_stats_card_new (void)
{
	return ft_stats_card_construct (FT_TYPE_STATS_CARD);
}

const gchar*
ft_stats_card_get_label (FtStatsCard* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_label;
	result = _tmp0_;
	return result;
}

void
ft_stats_card_set_label (FtStatsCard* self,
                         const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_stats_card_get_label (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_label);
		self->priv->_label = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, ft_stats_card_properties[FT_STATS_CARD_LABEL_PROPERTY]);
	}
}

FtUnit
ft_stats_card_get_unit (FtStatsCard* self)
{
	FtUnit result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_unit;
	return result;
}

void
ft_stats_card_set_unit (FtStatsCard* self,
                        FtUnit value)
{
	g_return_if_fail (self != NULL);
	self->priv->_unit = value;
	ft_stats_card_update (self);
	g_object_notify_by_pspec ((GObject *) self, ft_stats_card_properties[FT_STATS_CARD_UNIT_PROPERTY]);
}

gdouble
ft_stats_card_get_value (FtStatsCard* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->_value;
	return result;
}

void
ft_stats_card_set_value (FtStatsCard* self,
                         gdouble value)
{
	g_return_if_fail (self != NULL);
	self->priv->_value = value;
	ft_stats_card_update (self);
	g_object_notify_by_pspec ((GObject *) self, ft_stats_card_properties[FT_STATS_CARD_VALUE_PROPERTY]);
}

static void
ft_stats_card_class_init (FtStatsCardClass * klass,
                          gpointer klass_data)
{
	ft_stats_card_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtStatsCard_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_stats_card_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_stats_card_set_property;
	G_OBJECT_CLASS (klass)->finalize = ft_stats_card_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_CARD_LABEL_PROPERTY, ft_stats_card_properties[FT_STATS_CARD_LABEL_PROPERTY] = g_param_spec_string ("label", "label", "label", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_CARD_UNIT_PROPERTY, ft_stats_card_properties[FT_STATS_CARD_UNIT_PROPERTY] = g_param_spec_enum ("unit", "unit", "unit", FT_TYPE_UNIT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_STATS_CARD_VALUE_PROPERTY, ft_stats_card_properties[FT_STATS_CARD_VALUE_PROPERTY] = g_param_spec_double ("value", "value", "value", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/io/github/focustimerhq/FocusTimer/ui/main/stats/widgets/stats-card.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "value_label", FALSE, FtStatsCard_private_offset + G_STRUCT_OFFSET (FtStatsCardPrivate, value_label));
	gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "statscard");
}

static void
ft_stats_card_instance_init (FtStatsCard * self,
                             gpointer klass)
{
	self->priv = ft_stats_card_get_instance_private (self);
	self->priv->_unit = FT_UNIT_AMOUNT;
	self->priv->_value = ((double) NAN);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
ft_stats_card_finalize (GObject * obj)
{
	FtStatsCard * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_STATS_CARD, FtStatsCard);
	_g_free0 (self->priv->_label);
	G_OBJECT_CLASS (ft_stats_card_parent_class)->finalize (obj);
}

static GType
ft_stats_card_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtStatsCardClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_stats_card_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtStatsCard), 0, (GInstanceInitFunc) ft_stats_card_instance_init, NULL };
	GType ft_stats_card_type_id;
	ft_stats_card_type_id = g_type_register_static (adw_bin_get_type (), "FtStatsCard", &g_define_type_info, 0);
	FtStatsCard_private_offset = g_type_add_instance_private (ft_stats_card_type_id, sizeof (FtStatsCardPrivate));
	return ft_stats_card_type_id;
}

GType
ft_stats_card_get_type (void)
{
	static volatile gsize ft_stats_card_type_id__once = 0;
	if (g_once_init_enter (&ft_stats_card_type_id__once)) {
		GType ft_stats_card_type_id;
		ft_stats_card_type_id = ft_stats_card_get_type_once ();
		g_once_init_leave (&ft_stats_card_type_id__once, ft_stats_card_type_id);
	}
	return ft_stats_card_type_id__once;
}

static void
_vala_ft_stats_card_get_property (GObject * object,
                                  guint property_id,
                                  GValue * value,
                                  GParamSpec * pspec)
{
	FtStatsCard * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_CARD, FtStatsCard);
	switch (property_id) {
		case FT_STATS_CARD_LABEL_PROPERTY:
		g_value_set_string (value, ft_stats_card_get_label (self));
		break;
		case FT_STATS_CARD_UNIT_PROPERTY:
		g_value_set_enum (value, ft_stats_card_get_unit (self));
		break;
		case FT_STATS_CARD_VALUE_PROPERTY:
		g_value_set_double (value, ft_stats_card_get_value (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_stats_card_set_property (GObject * object,
                                  guint property_id,
                                  const GValue * value,
                                  GParamSpec * pspec)
{
	FtStatsCard * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_STATS_CARD, FtStatsCard);
	switch (property_id) {
		case FT_STATS_CARD_LABEL_PROPERTY:
		ft_stats_card_set_label (self, g_value_get_string (value));
		break;
		case FT_STATS_CARD_UNIT_PROPERTY:
		ft_stats_card_set_unit (self, g_value_get_enum (value));
		break;
		case FT_STATS_CARD_VALUE_PROPERTY:
		ft_stats_card_set_value (self, g_value_get_double (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;
}

