import { redirect } from 'next/navigation'
import Link from 'next/link'
import { ArrowLeft, TrendingUp } from 'lucide-react'
import { getSession, isAdmin } from '@/lib/auth'
import { TradeProfiles } from '@/components/trade-profiles'

export const dynamic = 'force-dynamic'

export default async function TradesPage() {
  const session = await getSession()
  if (!session) redirect('/login')
  if (!(await isAdmin(session.userId))) redirect('/')

  return (
    <div className="min-h-screen max-w-md mx-auto flex flex-col">
      <header className="safe-top px-5 pb-3 flex items-center gap-2">
        <Link href="/" className="p-2 -ml-2 rounded-lg hover:bg-muted text-muted-foreground" aria-label="Back">
          <ArrowLeft className="h-4 w-4" />
        </Link>
        <div className="w-9 h-9 rounded-xl bg-gradient-to-tr from-primary to-violet-400 flex items-center justify-center">
          <TrendingUp className="h-5 w-5 text-primary-foreground" />
        </div>
        <div>
          <div className="font-semibold tracking-tight leading-none">Trade Profiles</div>
          <div className="text-xs text-muted-foreground">Live bot status</div>
        </div>
      </header>

      <main className="flex-1 px-4 pb-10">
        <TradeProfiles />
      </main>

      <footer className="safe-bottom" />
    </div>
  )
}
