(function () {
	var app = angular.module("app");
	app.controller('HeaderController', Controller);
	Controller.$inject = ['$scope'];

	function Controller($scope) {
		var vm = this;
		vm.activeLanguage = "en";
		vm.hideLanguageDropdownIntgrtn = false;

		if (window.location.pathname.split("/")[1].length != 2 && window.location.pathname.split("/")[1].length != 0) {
			vm.customLocationPrefix = '/' + window.location.pathname.split("/")[1] + '/';
		}

		var waitIntgrtn = setInterval(function () {
			if (!window.intgrtn) {
				return false;
			}
			clearInterval(waitIntgrtn);
			if (window.intgrtn.lookup("hideLanguageDropdown", true)) {
				vm.hideLanguageDropdownIntgrtn = true;
			}

			var reversedLocationPathArray = window.location.pathname.split("/").reverse();
			vm.activeLanguage = reversedLocationPathArray[0] != "lp.php" ? reversedLocationPathArray[1] : "en";
			$scope.$applyAsync();
		}, 10);

		vm.languages = [
			{
				name: "English",
				flagPath: "img/en.png",
				locationPrefix: vm.customLocationPrefix ? vm.customLocationPrefix : "/",
				code: 'en',
			},
			{
				name: "Deutsch",
				flagPath: "img/de.png",
				locationPrefix: "de/",
				code: "de",
			},
			{
				name: "Español",
				flagPath: "img/es.png",
				locationPrefix: "es/",
				code: "es",
			},
			{
				name: "Italiano",
				flagPath: "img/it.png",
				locationPrefix: "it/",
				code: "it",
			},
		];
	}

}());