import { createClient } from '@/lib/supabase/server'
import { redirect } from 'next/navigation'
import Link from 'next/link'
import { Button } from '@/components/ui/button'

export default async function Home() {
  const supabase = await createClient()
  const { data: { user } } = await supabase.auth.getUser()

  // If logged in, redirect to dashboard
  if (user) {
    redirect('/dashboard')
  }

  // Landing page for non-authenticated users
  return (
    <main className="min-h-screen flex flex-col items-center justify-center p-8 bg-gradient-to-b from-blue-50 to-white">
      <div className="text-center max-w-2xl">
        <h1 className="text-5xl font-bold text-gray-900 mb-4">
          Leopost
        </h1>
        <p className="text-xl text-gray-600 mb-8">
          Il tuo social media manager potenziato dall&apos;AI.
          <br />
          Minimo sforzo, massima resa.
        </p>

        <div className="flex gap-4 justify-center">
          <Link href="/register">
            <Button size="lg">
              Inizia gratis
            </Button>
          </Link>
          <Link href="/login">
            <Button variant="outline" size="lg">
              Accedi
            </Button>
          </Link>
        </div>

        <p className="mt-8 text-sm text-gray-500">
          Nessuna carta richiesta. Piano gratuito disponibile.
        </p>
      </div>
    </main>
  )
}
