import { Route, Router } from '@solidjs/router';
import type { Component } from 'solid-js';

import { RootShell } from './layout';
import {
	BlobPage,
	CommitPage,
	CommitsPage,
	IssuePage,
	IssuesPage,
	NewIssuePage,
	NewPullPage,
	PullPage,
	PullsPage,
	RepoCodePage,
} from './pages/repo';
import { RepoLayout } from './pages/repo/shared';
import { HomePage } from './pages/home';
import { NotFoundPage } from './pages/not-found';
import { OAuthCallbackPage } from './pages/oauth-callback';
import { SearchPage } from './pages/search';

export const AppRoutes: Component = () => (
	<Router root={RootShell}>
		<Route path="/" component={HomePage} />
		<Route path="/search" component={SearchPage} />
		<Route path="/oauth/callback" component={OAuthCallbackPage} />
		<Route path="/:owner/:repo" component={RepoLayout}>
			<Route path="/" component={RepoCodePage} />
			<Route path="/issues/new" component={NewIssuePage} />
			<Route path="/issues/:issueRef" component={IssuePage} />
			<Route path="/issues" component={IssuesPage} />
			<Route path="/pulls/new" component={NewPullPage} />
			<Route path="/pulls/:pullRef" component={PullPage} />
			<Route path="/pulls" component={PullsPage} />
			<Route path="/commits" component={CommitsPage} />
			<Route path="/commits/:ref" component={CommitsPage} />
			<Route path="/commit/:ref" component={CommitPage} />
			<Route path="/blob/:ref/*path" component={BlobPage} />
			<Route path="/tree/:ref/*path" component={RepoCodePage} />
		</Route>
		<Route path="*404" component={NotFoundPage} />
	</Router>
);
