import React, { FC } from 'react'
import {
Link,
LinkProps,
useLocation,
useResolvedPath,
useRoutes,
} from 'react-router-dom'
import tw from 'twin.macro'
import './App.css'
import { PageHeader, Parchment } from './components'
import { LanguageSwitcher } from './components/language-switcher'
import YxansKlaganLogo from './logo'
import { CalendarPage } from './pages/calendar.page'
import { DiceRollerPage } from './pages/dice-roller.page'
import { EncounterPage } from './pages/encounter.page'
import { GearPage } from './pages/gear.page'
import { MapPage } from './pages/map.page'
import { NameGeneratorPage } from './pages/name-generator.page'
import { SessionPage } from './pages/session.page'
import { useTranslation } from 'react-i18next'
import { MonstersPage } from './pages/monsters.page'
const styles = {
// Move long class sets out of jsx to keep it scannable
// container: ({ hasBackground }: { hasBackground: boolean }) => [
container: () => [
tw`bg-gray-50 flex-col min-h-screen h-full w-screen max-w-full`,
// hasBackground && tw`wbg-gradient-to-b from-electric to-ribbon`,
//tw`bg-yellow-50`,
],
}
const App = () => {
const routes = useRoutes([
{
path: '/',
element: <HomePage />,
},
{
path: '/dice',
element: <DiceRollerPage />,
},
{
path: '/names',
element: <NameGeneratorPage />,
},
{
path: '/gear',
element: <GearPage />,
},
{
path: '/calendar',
element: <CalendarPage />,
},
{
path: '/session',
element: <SessionPage />,
},
{
path: '/map',
element: <MapPage />,
},
{
path: '/encounter',
element: <EncounterPage />,
},
{
path: '/monsters',
element: <MonstersPage />,
},
])
const { t } = useTranslation('core')
return (
<div className="App" css={styles.container()}>
<div tw="flex flex-col h-full lg:(flex-row)">
<div tw="flex flex-col bg-gray-200 lg:(h-full fixed w-48 )">
<div tw="p-2 mb-4">
<Link to="/" tw="block w-full">
<YxansKlaganLogo />
</Link>
</div>
<div tw="h-full flex flex-col justify-between pb-4">
<nav tw="text-lg w-full flex flex-col gap-y-1">
<MenuLink to="/session">{t('Menu-Session')}</MenuLink>
<MenuLink to="/encounter">{t('Menu-Encounters')}</MenuLink>
<MenuLink to="/monsters">{t('Menu-Monsters')}</MenuLink>
<MenuLink to="/map">{t('Menu-Map')}</MenuLink>
<MenuLink to="/calendar">{t('Menu-Calendar')}</MenuLink>
<MenuLink to="/gear">{t('Menu-Gear')}</MenuLink>
<MenuLink to="/names">{t('Menu-Names')}</MenuLink>
{/* <MenuLink to="/dice">{t('Menu-Dice')}</MenuLink> */}
</nav>
<LanguageSwitcher></LanguageSwitcher>
</div>
</div>
<main tw="w-full mt-4 lg:(ml-48)">{routes}</main>
</div>
</div>
)
}
export default App
const HomePage = () => (
<div tw="flex flex-col gap-y-8 max-w-prose">
<PageHeader>Forbidden Lands</PageHeader>
<Parchment>
<p className="yx-prose">
Welcome to Forbidden Lands. In this tabletop roleplaying game, you are not heroes sent on missions dictated by others – instead, you are raiders and rogues bent on making your own mark on a cursed world. You will wander the wild lands, discover lost tombs, fight monsters, and, if you live long enough, build your own stronghold to defend. During your ad- ventures, you will uncover the secrets of dark powers lurking in the shadows and, in the end, you can be the ones to decide the fate of the Forbidden Lands.
</p>
</Parchment>
<Parchment>
<div tw="flex flex-col gap-4">
<h2 tw="text-4xl text-center flex" className="yx-heading">
Tack
</h2>
<p className="yx-prose">
Tack till{' '}
<a
tw=" hover:text-yellow-500 underline"
href="https://freeleaguepublishing.com/sv/"
>
Free League
</a>{' '}
for a fantastic game.
</p>
<p className="yx-prose">
Thanks to the Forbidden Lands community for the inspiration and others generators.
</p>
</div>
</Parchment>
<div></div>
</div>
)
const MenuLink: FC<LinkProps> = ({ to, children }: LinkProps) => {
const { pathname } = useLocation()
const { pathname: toPathname } = useResolvedPath(to)
const isLinkActive = pathname === toPathname
return (
<Link
tw="px-4 py-1 w-full font-medium hover:bg-yellow-500"
css={[
isLinkActive &&
tw`bg-black text-white font-semibold hover:bg-black hover:text-yellow-500`,
]}
to={to}
>
{children}
</Link>
)
}