#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "gddcalc.h"
#include "oneday.h"

bool c1_LocaleOK(c1_widgets *);                           // prototype
int getMonthNumber(char *);                               // prototype
void setMonthLengths(int);                                // prototype

int c1_CheckEntries(c1_widgets *w) {

// Check the left side of the array. c1_LocaleOK becomes false when one
// or more of the location variables is unacceptable.
	
	if (!c1_LocaleOK(w)) {                                // test locale
		if (error_watch == 1) {return 1;}
	}

// Check the right side of the display.

	const gchar *t;
	t = gtk_entry_get_text(GTK_ENTRY(w->c1_entry6));
	int day = atoi(t);

	gchar *month_text = gtk_combo_box_text_get_active_text(w->c1_cbtxt_month);
	int month = getMonthNumber(month_text);
	g_free(month_text);

	t = gtk_entry_get_text(GTK_ENTRY(w->c1_entry8));
	int year = atoi(t);
	
	if (year < 2000 || year > 2050) {return 3;}                  // test year

	setMonthLengths(year);
	if (day < 1 || day > dayspermonth[month - 1]) {return 2;}    // test day

	return 0;
}
