'use strict';

module.exports = function() {
	var count = 0;

	return {
		restrict: 'A',

		scope: {
			mode: '@',
			position: '@',
			accentColor: '@',
			widgetHeight: '@',
			widgetWidth: '@',
			smartvoteEnabled: '@',
			identify: '='
		},

		link: function(scope, elem, attrs) {
			elem.attr('id', 'feedback-uservoice-' + count.toString());
			count = count + 1;

			var set = [
				scope.mode,
				scope.position,
				scope.accentColor,
				scope.widgetHeight,
				scope.widgetWidth,
				scope.smartvoteEnabled ];

			var def = ['contact', 'automatic', '#448dd6', '300px', '300px', true];

			for (var i = 0; i < set.length; i++) {
				if (!set[i]) {
					set[i] = def[i];
				}
			}

			if (set[5] === 'true') {
				set[5] = true;
			}
			else if (set[5] === 'false') {
				set[5] = false;
			}
			else {
				set[5] = true;
			}

			if (UserVoice) {
				UserVoice.push(['set', {
					position: set[1],
					accent_color: set[2],
					height: set[3],
					width: set[4],
					smartvote_enabled: set[5]
				}]);

				UserVoice.push(['addTrigger', '#' + elem.attr('id'), {
					mode: set[0]
				}]);

				UserVoice.push(['autoprompt', { mode: 'smartvote', trigger_position: 'bottom-right' }]);
			}

			var setIdentify = function() {
				if (scope.identify) {
					UserVoice.push(['identify', scope.identify]);
				}
			}

			scope.$watch('identify', setIdentify);
		}
	}
}

@@ -1095,32 +1095,35 @@
 %5D%0A%09%09%09%09%7D%5D);%0A%0A%09%09%09%09
+// 
 UserVoice.push(%5B
@@ -1195,16 +1195,56 @@
 t' %7D%5D);%0A
+%09%09%09%09UserVoice.push(%5B'autoprompt', %7B%7D%5D);%0A
 %09%09%09%7D%0A%0A%09%09

Modify uservoice autoprompt.