import { chatGPTSignOutPath, requireChatGPTUser } from "./chatgpt-auth";
import AdminApp from "./admin-app";
import { isAdminEmail } from "../lib/admin-auth";

export const dynamic = "force-dynamic";

export default async function Page() {
  const user = await requireChatGPTUser("/");

  if (!isAdminEmail(user.email)) {
    return (
      <main className="admin-access-denied">
        <section>
          <p>KOC LOOP</p>
          <h1>当前账号没有后台权限</h1>
          <span>请切换为管理员账号后再试。</span>
          <a href={chatGPTSignOutPath("/")}>切换账号</a>
        </section>
      </main>
    );
  }

  return <AdminApp />;
}
