import 'vfonts/FiraSans.css'

import {
	loadAndSetLocale
} from '@/i18n.js'

import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/Home.vue'
import LogsList from '../views/LogsList.vue'
import CreateLog from '../views/CreateLog.vue'
import CameraCapture from '../views/CameraCapture.vue'
import ManagePhotos from '../views/ManagePhotos.vue'
import DevView from '../views/DevView.vue'

const routes = [
	{
		path: '/',
		name: 'Home',
		component: HomeView,
	},
	{
		path: '/logs',
		name: 'LogsList',
		component: LogsList
	},
	{
		path: '/logs/create/:e?',
		name: 'CreateLog',
		component: CreateLog,
		props: (route) => {
			const e = Number.parseInt(route.params.e)
			if (Number.isNaN(e)) {
				return ''
			}
			return {e}
		}
	},
	{
		path: '/capture',
		name: 'CameraCapture',
		component: CameraCapture
	},
	{
		path: '/photos',
		name: 'ManagePhotos',
		component: ManagePhotos
	},
	{
		path: '/dev',
		name: 'Development',
		component: DevView
	},
]

const router = createRouter({
	history: createWebHistory(),
	routes,
})

// navigation guards
router.beforeEach(async (to, from, next) => {
	const paramsLocale = to.params.locale
	await loadAndSetLocale(paramsLocale)
	next()
})

export default router
