(function () {
	'use strict';

	angular.module('uniflash').directive('ufConfigSaved', ufConfigSaved);

	function ufConfigSaved() {

		var directive = {
			restrict: 'E',
			templateUrl: 'target_setup/configSaved.html',
			controller: ufConfigSavedController,
			controllerAs: 'vm',
			scope: {}
		};

		return directive;
	}


	ufConfigSavedController.$inject = ['ufSession', 'ufPreferencesSrv'];

	function ufConfigSavedController(ufSession, ufPreferencesSrv) {
		var vm = this;
		vm.showMore = false;

		vm.showSavedConfig = true;

		vm.files = [];
		vm.noFilesMessage = 'No Saved Sessions Available';

		ufPreferencesSrv.getRecentSessions()
			.then((files) => {
				vm.files = files;
			});

		vm.loadSession = function (selections) {
			ufSession.load(selections);
		};

		vm.clearAll = function () {
			ufPreferencesSrv.purgeRecentSessions();
			vm.files = [];
		};
	}

})();