import React from "react";
import PageHeader from "@/sections/PageHeader";
import { cookies } from "next/headers";
import { getUserFromCookie } from "@/lib/auth";
import { User } from "@/types";
import AccountContent from "@/sections/AccountContent";
import { redirect } from "next/navigation";
import pb from "@/lib/pocketbase";

export default async function AccountPage() {
  const user = (await getUserFromCookie(cookies())) as User;
  const cookie = cookies().get("pb_auth");
  //server side
  pb.authStore.loadFromCookie(cookie?.value || "");
  !pb.authStore.isValid && redirect("/");
  return (
    user && (
      <>
        <PageHeader title="Account" subtitle={<></>} />

        <AccountContent user={user} />
      </>
    )
  );
}
