/* SPDX-FileCopyrightText: 2026 - Sébastien Wilmet <swilmet@gnome.org>
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */

#include <amtk/amtk.h>

#define INSERT_VERY_LONG_ROW		FALSE
#define TAKE_FULL_MONITOR_HEIGHT	FALSE

static GtkListStore *
create_list_store (gint n_rows)
{
	GtkListStore *store;
	gint num;

	store = gtk_list_store_new (1, G_TYPE_STRING);

#if INSERT_VERY_LONG_ROW
	{
		gchar *long_str;
		GtkTreeIter iter;

		long_str = g_strnfill (200, 'Z');

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    0, long_str,
				    -1);

		g_free (long_str);
	}
#endif

	for (num = 0; num < n_rows; num++)
	{
		gchar *num_str;
		GtkTreeIter iter;

		num_str = g_strdup_printf ("Row number %d", num);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    0, num_str,
				    -1);

		g_free (num_str);
	}

	return store;
}

static GtkTreeView *
create_tree_view (void)
{
	GtkListStore *store;
	GtkTreeView *view;
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;

	store = create_list_store (100);
	view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)));
	g_object_unref (store);

	gtk_tree_view_set_headers_visible (view, FALSE);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Title",
							   renderer,
							   "text", 0,
							   NULL);
	gtk_tree_view_append_column (view, column);

	return view;
}

static void
create_window (void)
{
	GtkWindow *window;
	GtkTreeView *tree_view;
	AmtkTreeViewScrolledWindowSizing *scrolled_window;
	GtkGrid *grid;

	window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
	gtk_window_set_default_size (window, 800, 600);
	g_signal_connect (window, "destroy", gtk_main_quit, NULL);

	tree_view = create_tree_view ();
	scrolled_window = amtk_tree_view_scrolled_window_sizing_new ();
#if !TAKE_FULL_MONITOR_HEIGHT
	gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scrolled_window), 180);
#endif
	gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (tree_view));

	grid = GTK_GRID (gtk_grid_new ());
	gtk_container_add (GTK_CONTAINER (grid), GTK_WIDGET (scrolled_window));
	gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (grid));
	gtk_widget_show_all (GTK_WIDGET (window));
}

int
main (int    argc,
      char **argv)
{
	amtk_init ();
	gtk_init (&argc, &argv);

	create_window ();

	gtk_main ();
	amtk_finalize ();
	return EXIT_SUCCESS;
}
