<script lang="ts">
// routing
	// may not need {link} here
	import Router, { link } from "svelte-spa-router";
  import { routes } from "../routes.js";

  import LoginPage from "./LoginPage.svelte";
	import UserPage from "../UserPage.svelte";
    import NotFound from "../pages/NotFound.svelte";

	// Ideally fuck all this shit in the long run
	let pages = ['login', 'user', 'account'];
	// make this a $: currentPage ?
	let currentPage = 'booba';
	// prolly change this? yea idk...
	// let userIndex;
	// tmp for testing
	let userId = 0;
	// horrible naming... can be HOME or ACCOUNT
	let currentType = 'account';

	// this page should handle the SPA history management...

	// set to false later for actual security
	let loggedIn = true;

	// not sure if this is how i want to do this...
	// might do differently cuz URL route manangement...
	const handleLogin = () => {
		currentPage = 'user';
		loggedIn = true;
	};

// I don't know if i should but i'm tempted to put this here...

	// import axios from 'axios';
  // import { onMount } from 'svelte';
	// import { push } from 'svelte-spa-router';

	// let user = {logedIn: false};

	// onMount(async () => {
	// 	// console.log('PROFIL SVELTE');
	// 	const {data} = await axios.get('http://transcendance:8080/api/v2/user');
	// 	if (data)
	// 		user.logedIn = true;
	// });

	// $: submit = async() => {
	// 	window.location.href = 'http://transcendance:8080/api/v2/auth';
	// }

	// $: logout = async() => {
	// 	await fetch('http://transcendance:8080/api/v2/auth/logout',);
	// 	user.logedIn = false;
	// }




</script>

<!-- eventually we will do this with routes, but for now use a prop -->
<!-- {#if currentPage === 'login'}
	<LoginPage {pages} {currentPage} {userId} on:loggedIn={handleLogin}/>
{:else if currentPage === 'user'}
	<UserPage {pages} {currentPage} {userId} {currentType}/>
{:else}
	<NotFound />
{/if} -->
<Router {routes}/>

<style>
	
	/* doesn't work... */
  /* body{
    background: bisque;
  } */
</style>


