import { auth } from '@/auth'
import { redirect } from 'next/navigation'
import { McpSettingsPanel } from '@/components/mcp/mcp-settings-panel'
import { listMcpKeys, getMcpServerStatus, getMcpAccessStatus } from '@/app/actions/mcp-keys'
import { McpSettingsHeader } from './mcp-settings-header'

export default async function McpSettingsPage() {
  const session = await auth()
  if (!session?.user) redirect('/api/auth/signin')

  const [keys, serverStatus, access] = await Promise.all([
    listMcpKeys(),
    getMcpServerStatus(),
    getMcpAccessStatus(),
  ])

  return (
    <div className="space-y-8">
      <McpSettingsHeader />
      <McpSettingsPanel initialKeys={keys} serverStatus={serverStatus} mcpAllowed={access.allowed} tier={access.tier} />
    </div>
  )
}
