---
import Layout from '../../layouts/Layout.astro';
import NavBar from '../../components/NavBar.astro';
import { getUserResources, updateUserResources } from '../../lib/users';
import { getHighestWeightedLanguage, getLocales } from '../../lib/lang/langDriver';
String.prototype.format = function() {
return [...arguments].reduce((p,c) => p.replace(/{}/,c), this);
};
const loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
const username = Astro.cookies.get('username')?.value ?? "";
if(loggedToken === null || username === "") return Astro.redirect('/');
const resources = await getUserResources(username);
await updateUserResources(username, {
coal: resources.coal * 2,
iron: resources.iron * 3,
gold: resources.gold * 4,
});
const langResources = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources');
const langGame = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'game');
// console.log(resources);
---
{langGame['Link_logout']}
{langGame['Header_user'].format(username)}
- {langResources['Label_coal']}: {resources.coal * 2}
- {langResources['Label_iron']}: {resources.iron * 3}
- {langResources['Label_gold']}: {resources.gold * 4}