'use strict';

const Promise = require("bluebird");
const stateRouter = require("../riot/state-router");

module.exports = function createRouter() {
	let router = stateRouter();

	router.get("/", (req, res) => {
		let text;

		if (req.query.target != null) {
			text = req.query.target;
		} else {
			text = "World";
		}

		res.render("sample", {
			text: `Hello ${text}!`
		});
	});

	router.get("/nodes/create", (req, res) => {
		res.render("node-create");
	});

	router.post("/nodes/create", (req, res) => {
		return Promise.try(() => {
			return req.pass();
		}).then((response) => {
			console.log(response.body);
		});
	});

	return router;
};
