---
import { ObjectId } from 'mongodb';
import { getHighestWeightedLanguage, getLocales } from '../lib/utils/langDriver';
import { getUserWithPlanets } from '../lib/db/users';
import { createPlanet } from '../lib/db/planets';

// await createPlanet({
//     name: "BiałePodNapletem2",
//     ownerId: new ObjectId(Astro.cookies.get('userid')?.value ?? ""),
//     fields: 69
// })

if(!Astro.cookies.get('userid')?.value) return;
const planets = (await getUserWithPlanets(new ObjectId(Astro.cookies.get('userid')?.value ?? "")))?.planets.data;
if(!planets) return;

// console.log(planets);

// const resourceLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources');
// const resBarLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar');


---
<div id="planetview">
    {planets.map(planet => <div>
        <b>{planet.name}</b><br />
        <p>{planet.fields}</p>
    </div>)}
</div>

<style>
#planetview {
    color: red;
    background-color: pink;
}
</style>