var WindowManager = require('helper/WindowManager');
var Utils = require('helper/Utils');
var Cloud = require('ti.cloud');
exports['Show User'] = function(evt) {
	var userId;
	var win = WindowManager.createWindow({
		backgroundColor: 'white'
	});
	var button = Ti.UI.createButton({
		title: 'Copy User ID',
		top: 10 + Utils.u,
		left: 10 + Utils.u,
		right: 10 + Utils.u,
		bottom: 10 + Utils.u,
		height: 40 + Utils.u
	});
	win.add(button);
	var content = Ti.UI.createScrollView({
		top: 60 + Utils.u,
		bottom: 0,
		contentHeight: 'auto',
		layout: 'vertical'
	});
	win.add(content);

	var status = Ti.UI.createLabel({
		text: 'Loading, please wait...',
		textAlign: 'left',
		height: 30 + Utils.u,
		left: 20 + Utils.u,
		right: 20 + Utils.u,
		color: 'black'
	});
	content.add(status);

	button.addEventListener('click', function() {
		if (userId) {
			alert('User id ' + userId + ' copied to clipboard.');
			Ti.UI.Clipboard.setText(userId);
		}
	});

	Cloud.Users.show({
		user_id: evt.id
	}, function(e) {
		content.remove(status);
		if (e.success) {
			Utils.enumerateProperties(content, e.users[0], 20);
			userId = e.users[0].id;
		} else {
			Utils.error(e);
		}
	});

	return win;
};