import Link from "next/link"
import Image from "next/image"
import { ArrowRight, ShieldCheck, Lock, History, LayoutDashboard } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Card, CardContent } from "@/components/ui/card"
import { createClient } from "@/lib/supabase-server"
import { getSiteContents } from "@/lib/data"

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

  return (
    <div className="flex flex-col min-h-screen">
      {/* Hero Section */}
      <section className="relative w-full h-[80vh] flex items-center bg-black overflow-hidden">
        <div className="absolute inset-0 z-0">
          <Image
            src={contents.home_hero_bg_image || "/images/hero-safe.png"}
            alt="Premium Çelik Kasa"
            fill
            className="object-cover opacity-60"
            priority
          />
          <div className="absolute inset-0 bg-gradient-to-r from-black/90 via-black/50 to-transparent" />
        </div>

        <div className="container relative z-10 px-4 md:px-6">
          <div className="max-w-2xl space-y-4">
            <h1
              className="text-3xl md:text-6xl lg:text-7xl font-bold tracking-tighter text-white font-outfit"
              dangerouslySetInnerHTML={{ __html: contents.home_hero_title || 'GÜVENLİK SINIR <br /> <span class="text-transparent bg-clip-text bg-gradient-to-r from-slate-200 to-slate-500">TANIMAZ</span>' }}
            />
            <p className="text-lg md:text-xl text-slate-300 max-w-[600px]">
              {contents.home_hero_description || "En değerli varlıklarınız için tasarlanmış yüksek güvenlikli çelik kasalar. Modern teknoloji ve zanaatkarlığın mükemmel uyumu."}
            </p>
            <div className="flex flex-col sm:flex-row gap-4 mt-8">
              <Button size="lg" className="bg-slate-100 text-slate-900 hover:bg-slate-200 font-semibold text-lg px-8" asChild>
                <Link href="/products">{contents.home_hero_button_text || "Koleksiyonu İncele"}</Link>
              </Button>
              {user && (
                <Button size="lg" variant="outline" className="border-slate-400 text-slate-100 hover:bg-slate-800 hover:text-white font-semibold text-lg px-8">
                  <Link href="/dashboard" className="flex items-center">
                    <LayoutDashboard className="mr-2 h-5 w-5" />
                    Panele Git
                  </Link>
                </Button>
              )}
            </div>
          </div>
        </div>
      </section>

      {/* Categories Section */}
      <section className="py-20 md:py-32 bg-slate-50 dark:bg-slate-950">
        <div className="container px-4 md:px-6">
          <div className="flex flex-col items-center justify-center space-y-4 text-center mb-16">
            <h2 className="text-3xl md:text-5xl font-bold tracking-tighter font-outfit">{contents.home_categories_title || "Ürün Kategorileri"}</h2>
            <p className="max-w-[700px] text-muted-foreground md:text-lg">
              {contents.home_categories_description || "İhtiyacınıza uygun güvenlik çözümünü seçin."}
            </p>
          </div>

          <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
            {/* Home Safes */}
            <Link href="/products?category=ev" className="group">
              <Card className="h-full overflow-hidden border-0 shadow-lg transition-all duration-300 group-hover:shadow-2xl group-hover:-translate-y-2 bg-white dark:bg-slate-900">
                <CardContent className="p-0 relative aspect-[4/5]">
                  <div className="absolute inset-0 bg-slate-200 dark:bg-slate-800 animate-pulse" /> {/* Placeholder for image */}
                  <div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent flex flex-col justify-end p-6">
                    <h3 className="text-2xl font-bold text-white mb-2">Ev Tipi Kasalar</h3>
                    <div className="flex items-center text-slate-300 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity transform translate-y-4 group-hover:translate-y-0">
                      İncele <ArrowRight className="ml-2 h-4 w-4" />
                    </div>
                  </div>
                </CardContent>
              </Card>
            </Link>

            {/* Office Safes */}
            <Link href="/products?category=ofis" className="group">
              <Card className="h-full overflow-hidden border-0 shadow-lg transition-all duration-300 group-hover:shadow-2xl group-hover:-translate-y-2 bg-white dark:bg-slate-900">
                <CardContent className="p-0 relative aspect-[4/5]">
                  <div className="absolute inset-0 bg-slate-300 dark:bg-slate-700 animate-pulse" />
                  <div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent flex flex-col justify-end p-6">
                    <h3 className="text-2xl font-bold text-white mb-2">Ofis Kasaları</h3>
                    <div className="flex items-center text-slate-300 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity transform translate-y-4 group-hover:translate-y-0">
                      İncele <ArrowRight className="ml-2 h-4 w-4" />
                    </div>
                  </div>
                </CardContent>
              </Card>
            </Link>

            {/* Hotel/Room Safes */}
            <Link href="/products?category=otel" className="group">
              <Card className="h-full overflow-hidden border-0 shadow-lg transition-all duration-300 group-hover:shadow-2xl group-hover:-translate-y-2 bg-white dark:bg-slate-900">
                <CardContent className="p-0 relative aspect-[4/5]">
                  <div className="absolute inset-0 bg-slate-200 dark:bg-slate-800 animate-pulse" />
                  <div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent flex flex-col justify-end p-6">
                    <h3 className="text-2xl font-bold text-white mb-2">Otel & Oda</h3>
                    <div className="flex items-center text-slate-300 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity transform translate-y-4 group-hover:translate-y-0">
                      İncele <ArrowRight className="ml-2 h-4 w-4" />
                    </div>
                  </div>
                </CardContent>
              </Card>
            </Link>

            {/* Gun/Special Safes */}
            <Link href="/products?category=ozel" className="group">
              <Card className="h-full overflow-hidden border-0 shadow-lg transition-all duration-300 group-hover:shadow-2xl group-hover:-translate-y-2 bg-white dark:bg-slate-900">
                <CardContent className="p-0 relative aspect-[4/5]">
                  <div className="absolute inset-0 bg-slate-300 dark:bg-slate-700 animate-pulse" />
                  <div className="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent flex flex-col justify-end p-6">
                    <h3 className="text-2xl font-bold text-white mb-2">Diğer Ürünler</h3>
                    <div className="flex items-center text-slate-300 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity transform translate-y-4 group-hover:translate-y-0">
                      İncele <ArrowRight className="ml-2 h-4 w-4" />
                    </div>
                  </div>
                </CardContent>
              </Card>
            </Link>
          </div>
        </div>
      </section>

      {/* Trust/Features Section */}
      <section className="py-20 md:py-32 bg-white dark:bg-black">
        <div className="container px-4 md:px-6">
          <div className="grid grid-cols-1 md:grid-cols-3 gap-12 text-center">
            <div className="flex flex-col items-center space-y-4">
              <div className="p-4 bg-slate-100 dark:bg-slate-900 rounded-full">
                <ShieldCheck className="w-12 h-12 text-slate-900 dark:text-slate-100" />
              </div>
              <h3 className="text-xl font-bold">Sertifikalı Güvenlik</h3>
              <p className="text-muted-foreground">Uluslararası standartlarda yangına ve hırsızlığa karşı dayanıklılık sertifikaları.</p>
            </div>
            <div className="flex flex-col items-center space-y-4">
              <div className="p-4 bg-slate-100 dark:bg-slate-900 rounded-full">
                <Lock className="w-12 h-12 text-slate-900 dark:text-slate-100" />
              </div>
              <h3 className="text-xl font-bold">Gelişmiş Kilit Sistemleri</h3>
              <p className="text-muted-foreground">Biyometrik, elektronik şifreli ve anahtarlı hibrit kilit teknolojileri.</p>
            </div>
            <div className="flex flex-col items-center space-y-4">
              <div className="p-4 bg-slate-100 dark:bg-slate-900 rounded-full">
                <History className="w-12 h-12 text-slate-900 dark:text-slate-100" />
              </div>
              <h3 className="text-xl font-bold">Yılların Tecrübesi</h3>
              <p className="text-muted-foreground">Uzun yıllara dayanan sektör tecrübesi ve %100 müşteri memnuniyeti.</p>
            </div>
          </div>
        </div>
      </section>
    </div>
  )
}
