import { createFileRoute, redirect } from "@tanstack/react-router";
import { checkUserAccess } from "@/lib/authClient";
import QualityRequest from "./-components/QualityRequest";
import RequestPallet from "./-components/RequestPallet";

export const Route = createFileRoute("/_old/old/quality/")({
	component: RouteComponent,
	beforeLoad: async () => {
		const auth = await checkUserAccess({
			allowedRoles: [
				"systemAdmin",
				"technician",
				"admin",
				"manager",
				"supervisor",
				"user",
			],
			moduleName: "quality", // optional
		});

		if (!auth) {
			throw redirect({
				to: "/login",
				search: {
					// Use the current location to power a redirect after login
					// (Do not use `router.state.resolvedLocation` as it can
					// potentially lag behind the actual current location)
					redirect: location.pathname + location.search,
				},
			});
		}
	},
});

function RouteComponent() {
	return (
		<div className="flex flex-col m-2">
			<div className="flex justify-items-start ml-2">
				<RequestPallet />
			</div>

			<QualityRequest />
		</div>
	);
}
