import tpl from "./templates/html.js";
import global from "./_global.js";

export default async function(bx){

	bx.templates.init(tpl);
	global(bx);

	bx.templates.get('head').setVars({
		title: `Baxxon - Examples - Single Page Application`,
	});

	bx.templates.get('body').setVars({
		title: "Single Page Application (SPA)",
		subtitle: "",
		intro: bx.renderContent("content/intro.md"),
		demo: bx.renderContent("content/demo.html"),
	});

	bx.templates.get('root').setVars({
		head: bx.templates.merge('head'),
		body: bx.templates.merge('body'),
		js: `<script type="module">
import spa from "/js/baxxon/spa.js";
import API from "/js/baxxon/api.js";

// DEV TESTING: Auto-reset data on load ****
(async ()=>{
	const api = new API({
		requestURI: "/devtest-spa-data-reset"
	});
	const res = await api.send("reset", { db: spa.op.db });
	if(res.success){
		await spa.load();
	}
})();
// ****
</script>`

	});

	bx.render.HTML(bx.templates.merge('root'));
}
