import type { Metadata } from "next";
import { auth } from "@/auth";
import { db } from "@/lib/db";
import { redirect } from "next/navigation";
import ProfileForms from "./ProfileForms";

export const metadata: Metadata = { title: "My Profile" };

export default async function ProfilePage() {
  const session = await auth();
  if (!session?.user?.id) redirect("/login");

  const user = await db.user.findUnique({
    where: { id: session.user.id },
    select: { 
      id: true, 
      name: true, 
      email: true, 
      phone: true, 
      role: true, 
      emailVerified: true, 
      createdAt: true,
      shippingAddress: true,
      shippingCity: true,
      shippingState: true,
      shippingZip: true,
      shippingCountry: true,
    },
  });
  if (!user) redirect("/login");

  return (
    <div className="min-h-screen bg-neutral-50">
      <div className="max-w-2xl mx-auto px-4 sm:px-6 py-10">
        <div className="mb-8">
          <h1 className="text-2xl font-bold text-navy-800">My Profile</h1>
          <p className="text-neutral-500 text-sm mt-1">Manage your personal information and password.</p>
        </div>

        <ProfileForms user={user} />
      </div>
    </div>
  );
}
