import { createFileRoute, Link, Outlet } from "@tanstack/react-router"

export const Route = createFileRoute("/_authed")({
	beforeLoad: ({ context }) => {
		if (context.error) {
			throw new Error("Not authenticated")
		}
	},
	errorComponent: ({ error }) => {
		if (error.message === "Not authenticated") {
			return (
				<p>
					Not authenticated. Please <Link to="/access/login">login</Link>.
				</p>
			)
		}
		throw error
	},
	component: RouteComponent
})

function RouteComponent() {
	return (
		<div className="min-h-screen flex gap-2">
			<div className="p-2"></div>
			<div className="sm:pl-25 w-full">
				<Outlet />
			</div>
		</div>
	)
}
