import CardTiles from "../components/home/CardTiles";
import { getPortfolios } from "./utils";
import { AuthOptions } from "@/app/api/auth/[...nextauth]/authOptions";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";

const Home = async () => {
  const user = await getServerSession(AuthOptions);

  if (!user?.user) {
    console.error("User not found");
    redirect("/");
  }
  const portfolios = await getPortfolios(user.user.dbId);

  return (
    <>
      <div className="flex justify-center">
        <h1 className="text-3xl font-bold mt-3 mb-5 text-gray-700">
          {" "}
          Your Portfolios{" "}
        </h1>
      </div>
      <div className="px-5">
        <CardTiles Portfolios={portfolios} />
      </div>
    </>
  );
};
export default Home;
