var React = require('react/addons'),
	Document = require("../../models/document").Document;

exports.index = {
	auth: {
		mode: 'try',
		strategy: 'session'
	},
	handler: function (request, reply) {

		if (!request.auth.isAuthenticated) {
			return reply.redirect('/login');
		}

		Document.findByOwnerId(request.auth.credentials._id, request.query.page, 10).then(function(data) {

			var ReactApp = React.createFactory(require('../../components/documentList.jsx'));
			var intialHTNL = React.renderToString(ReactApp({initialData: data}));

	   		return reply.view("dashboard/index", {
	   			intialHTNL: intialHTNL,
	   			data: JSON.stringify(data)
	   		});

	   	});

	}

};
