import { auth } from '@/auth'
import { redirect } from 'next/navigation'
import { ProfileForm } from './profile-form'
import prisma from '@/lib/prisma'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Sparkles } from 'lucide-react'
import { ProfilePageHeader } from '@/components/profile-page-header'
import { AISettingsLinkCard } from './ai-settings-link-card'

export default async function ProfilePage() {
  const session = await auth()

  if (!session?.user?.id) {
    redirect('/login')
  }

  const user = await prisma.user.findUnique({
    where: { id: session.user.id },
    select: { name: true, email: true, role: true }
  })

  if (!user) {
    redirect('/login')
  }

  // Get user AI settings for language preference
  const userAISettings = await prisma.userAISettings.findUnique({
    where: { userId: session.user.id },
    select: { preferredLanguage: true }
  })

  return (
    <div className="container max-w-2xl mx-auto py-10 px-4">
      <ProfilePageHeader />
      <ProfileForm user={user} userAISettings={userAISettings} />

      {/* AI Settings Link */}
      <AISettingsLinkCard />
    </div>
  )
}
