import { redirect } from "next/navigation";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/auth";
import ClientErrorMessage from "@/components/client-error-message";
import UserUpdateForm from "@/components/user/user-update-form";
import { getProfileById } from "@/queries/users";
import { tryCatch } from "@/utils/tryCatch";
// import {
//   Select,
//   SelectContent,
//   SelectGroup,
//   SelectItem,
//   SelectLabel,
//   SelectTrigger,
//   SelectValue,
// } from "@/components/ui/select";

export default async function UserUpdate({
	params,
}: {
	params: Promise<{
		userId: string;
	}>;
}) {
	const { userId } = await params;
	const session = await getServerSession(authOptions);
	if (!session?.user?.is_admin) return redirect("/devices?page=1");
	const [error, user] = await tryCatch(getProfileById(userId));

	if (error) {
		if (error.message === "UNAUTHORIZED") {
			redirect("/auth/signin");
		} else {
			return <ClientErrorMessage message={error.message} />;
		}
	}

	return (
		<div>
			<div className="flex items-center justify-between text-gray-500 text-2xl font-bold title-bg py-4 px-2 mb-4">
				<h3 className="text-sarLinkOrange text-2xl">Verify user</h3>
			</div>
			<UserUpdateForm user={user} />
		</div>
	);
}
