import * as p from '@mindfusion/scheduling';
import * as Controls from "@mindfusion/controls";
import * as Common from "@mindfusion/common";
import enLocale from 'cldr-dates-full/main/en/ca-gregorian.json';
import deLocale from 'cldr-dates-full/main/de/ca-gregorian.json';
import ruLocale from 'cldr-dates-full/main/ru/ca-gregorian.json';
import deLocaleStrings from '@mindfusion/scheduling/localization/de.json';
import ruLocaleStrings from '@mindfusion/scheduling/localization/ru.json';

namespace MinApp {


	// create a new instance of the calendar 
	var calendar = new p.Calendar(<HTMLDivElement>document.getElementById("calendar"));

	var date = new p.DateTime();

	for (var i = 0; i < 5; i++) {
		var item = new p.Item();
		item.subject = "calendar item" + i.toString();
		item.startTime = date.clone().addDays(Math.floor((Math.random() * 30) + 1));
		item.endTime = item.startTime.clone().addDays(Math.floor(Math.random() * 5));
		calendar.schedule.items.add(item);
	}

	// render the calendar control
	calendar.render();


	export function changeView(value) {
		calendar.currentView = value;
	}

	let theme = document.getElementById("theme") as HTMLInputElement;
	theme.onchange = () => {
		calendar.theme = theme.value;
	}

	let locale = document.getElementById("locale") as HTMLInputElement;
	locale.onchange = () => {
		var localeId = (<HTMLSelectElement>document.getElementById("locale")).value;
		var locale;
		if (localeId == "en") {
			locale = Common.Locale.create(enLocale);
		}
		else if (localeId == "de") {
			locale = Common.Locale.create(deLocale);
			locale.strings = deLocaleStrings;
		}
		else if (localeId == "ru") {
			locale = Common.Locale.create(ruLocale);
			locale.strings = ruLocaleStrings;
			locale.dateSettings.firstDayOfWeek = 1;
		}

		calendar.locale = locale;
	}
}

global["MinApp"] = MinApp;