'use strict';
app.controller('sdkLicenseConfigController', ['$scope', '$http', '$modalInstance', '$translate', 'blockUI', 'lib', function ($scope, $http, $modalInstance, $translate, blockUI, lib) {

	$scope.license = '';

	$scope.submit = function () {
		
		if ($scope.license === '') {
			$translate(['message', 'slFillLicense']).then(function (msgs) {
				lib.showAlert(msgs.message, msgs.slFillLicense);
			});
			return;
		}

		blockUI.start();
		$http.put('/Api/Settings/SdkLicense', {
			value: $scope.license
		}).then(function (response) {
			blockUI.stop();
			$translate(['message', 'ssConfigChanged']).then(function (msgs) {
				lib.showAlert(msgs.message, msgs.ssConfigChanged, function (alertModal) {
					alertModal.close();
					$modalInstance.close(response.data);
				});
			});
		}, lib.handleRestError);

	};

	$scope.cancel = function () {
		$modalInstance.dismiss();
	};
}]);
