import { getPlatformStatsServer } from "@/lib/server-api";
import { HomeNavbar } from "@/components/home-navbar";
import { Suspense } from "react";
import { Shield, LineChart, Zap, ArrowRight, CheckCircle2, Sparkles } from "lucide-react";
import { Button } from "@/components/ui/button";
import Link from "next/link";
import { AnimatedStatsSection } from "@/components/animated-stats-section";

// Force the page to be dynamically rendered
export const dynamic = 'force-dynamic';

// Constants
const PY_20 = 20;
const PY_32 = 32;
const PX_6 = 6;
const PX_10 = 10;

// Format number with commas
function formatNumberValue(num: number): string {
  return new Intl.NumberFormat().format(Math.round(num));
}

// Format currency
function formatCurrencyValue(amount: number): string {
  return new Intl.NumberFormat('en-GB', {
    style: 'currency',
    currency: 'GBP',
    maximumFractionDigits: 0
  }).format(amount);
}

// This is a server component
export default async function Home() {
  try {
    const stats = await getPlatformStatsServer();

    return (
      <div className="flex flex-col min-h-screen bg-black text-white">
        <div className="absolute inset-0 bg-gradient-to-br from-[#D53F8C]/10 via-[#D53F8C]/3 to-transparent pointer-events-none scale-100" />
        <HomeNavbar />

        {/* Hero Section */}  
        <section className="relative overflow-hidden">
          <div className="relative flex flex-col items-center px-4 py-20 md:py-32 mx-auto max-w-7xl">
            <div className="flex flex-col items-center text-center space-y-6 max-w-3xl">
              <div className="inline-flex items-center px-4 py-2 rounded-full bg-[#D53F8C]/10 border border-[#D53F8C]/20 mb-4">
                <Sparkles className="h-4 w-4 text-[#D53F8C] mr-2" />
                <span className="text-sm font-medium text-[#D53F8C]">Secure Crypto Payments</span>
              </div>
              <h1 className="text-4xl md:text-6xl font-bold tracking-tight">
                The Future of <span className="text-[#D53F8C]">E-commerce</span> Management
              </h1>
              <p className="text-lg md:text-xl text-zinc-400 max-w-2xl">
                Streamline your online business with our all-in-one platform. Secure payments, order tracking, and analytics in one place.
              </p>
              <div className="flex flex-col sm:flex-row gap-4 mt-4">
                <Link href="/dashboard">
                  <Button size="lg" className="gap-2 bg-[#D53F8C] hover:bg-[#B83280] text-white border-0 h-12 px-8">
                    Get Started
                    <ArrowRight className="h-4 w-4" />
                  </Button>
                </Link>
                <Link href="/auth/register">
                  <Button size="lg" variant="outline" className="border-zinc-800 text-white hover:bg-zinc-900 h-12 px-8">
                    Create Account
                  </Button>
                </Link>
              </div>
            </div>
          </div>
        </section>

        {/* Features Grid */}
        <section className="relative py-20 px-4">
          <div className="max-w-7xl mx-auto space-y-20">
            <div className="grid md:grid-cols-3 gap-6">
              {[
                {
                  icon: Shield,
                  title: "Secure Payments",
                  description: "Built-in cryptocurrency support with maximum privacy and security for your transactions."
                },
                {
                  icon: LineChart,
                  title: "Real-time Analytics",
                  description: "Track your business performance with detailed insights and reporting tools."
                },
                {
                  icon: Zap,
                  title: "Lightning Fast",
                  description: "Optimized for speed with real-time updates and instant notifications."
                }
              ].map((feature, i) => (
                <div key={i} className="group relative overflow-hidden rounded-xl bg-gradient-to-b from-zinc-800/30 to-transparent p-6 border border-zinc-800">
                  <div className="absolute inset-0 bg-gradient-to-b from-[#D53F8C]/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity" />
                  <div className="relative">
                    <div className="h-12 w-12 flex items-center justify-center rounded-lg bg-[#D53F8C]/10 mb-4">
                      <feature.icon className="h-6 w-6 text-[#D53F8C]" />
                    </div>
                    <h3 className="text-lg font-semibold text-white mb-2">{feature.title}</h3>
                    <p className="text-sm text-zinc-400">{feature.description}</p>
                  </div>
                </div>
              ))}
            </div>

            {/* Stats Section */}
            <div className="relative">
              <AnimatedStatsSection stats={stats as any} />
            </div>
          </div>
        </section>

        {/* Footer */}
        <footer className="relative py-12 px-4 mt-auto">
          <div className="max-w-7xl mx-auto flex flex-col items-center">
            <div className="flex items-center gap-2 mb-4">
            </div>

            <div className="text-sm text-zinc-500">
              © {new Date().getFullYear()} Ember. All rights reserved.
            </div>
          </div>
        </footer>
      </div>
    );
  } catch (error) {
    console.error(error);
    return <div>Error loading page</div>;
  }
}
