import { Head, Link } from '@inertiajs/react';
import {
    ArrowRight,
    BadgeCheck,
    Boxes,
    Search,
    ShieldCheck,
    Sparkles,
    Store,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import ProductCard from './product-card';
import type {
    AppSettings,
    BlogPost,
    Product,
    PublicPage,
    Taxonomy,
} from './types';

type PageProps = {
    featuredProducts: Product[];
    categories: Taxonomy[];
    brands: Taxonomy[];
    recentPosts: BlogPost[];
    settings: AppSettings;
    pages: PublicPage[];
};

export default function Home({
    featuredProducts,
    categories,
    brands,
    recentPosts,
    settings,
}: PageProps) {
    return (
        <>
            <Head title="Home" />

            <section className="relative overflow-hidden bg-slate-950 text-white">
                <div className="absolute inset-0 bg-[radial-gradient(circle_at_15%_20%,rgba(34,211,238,0.2),transparent_30%),radial-gradient(circle_at_85%_30%,rgba(139,92,246,0.2),transparent_30%)]" />
                <div className="mx-auto grid max-w-7xl gap-12 px-4 py-16 md:py-24 lg:grid-cols-[1.05fr_0.95fr] lg:items-center">
                    <div className="relative">
                        <div className="inline-flex items-center gap-2 rounded-full border border-white/15 bg-white/5 px-4 py-2 text-sm text-cyan-300 backdrop-blur">
                            <Sparkles className="size-4" />
                            One catalog. Every store. Real availability.
                        </div>
                        <h1 className="mt-6 max-w-3xl text-5xl leading-[1.05] font-bold tracking-tight sm:text-6xl">
                            Find the right product{' '}
                            <span className="text-cyan-400">
                                in the right store.
                            </span>
                        </h1>
                        <p className="mt-6 max-w-2xl text-lg leading-8 text-slate-300">
                            Search {settings.shop_name}, compare products, and
                            instantly see which store has stock available.
                        </p>
                        <div className="mt-8 flex flex-wrap gap-3">
                            <Button
                                size="lg"
                                className="rounded-full bg-cyan-400 text-slate-950 hover:bg-cyan-300"
                                asChild
                            >
                                <Link href="/shop">
                                    Explore catalog
                                    <ArrowRight />
                                </Link>
                            </Button>
                            <Button
                                size="lg"
                                variant="outline"
                                className="rounded-full border-white/20 bg-white/5 text-white hover:bg-white/10 hover:text-white"
                                asChild
                            >
                                <Link href="/contact">Talk to us</Link>
                            </Button>
                        </div>
                        <div className="mt-10 grid max-w-xl grid-cols-3 gap-3">
                            {[
                                {
                                    icon: Search,
                                    label: 'Fast search',
                                },
                                {
                                    icon: Store,
                                    label: 'Store visibility',
                                },
                                {
                                    icon: ShieldCheck,
                                    label: 'Live stock',
                                },
                            ].map((item) => (
                                <div
                                    key={item.label}
                                    className="rounded-2xl border border-white/10 bg-white/5 p-4 backdrop-blur"
                                >
                                    <item.icon className="size-5 text-cyan-400" />
                                    <div className="mt-3 text-xs font-medium text-slate-300 sm:text-sm">
                                        {item.label}
                                    </div>
                                </div>
                            ))}
                        </div>
                    </div>

                    <div className="relative">
                        <div className="absolute -inset-8 rounded-full bg-cyan-400/10 blur-3xl" />
                        <div className="relative grid grid-cols-2 gap-4 rounded-3xl border border-white/10 bg-white/5 p-4 backdrop-blur-xl">
                            {featuredProducts.slice(0, 4).map((product) => (
                                <Link
                                    key={product.id}
                                    href={`/product/${product.slug}`}
                                    className="group relative aspect-square overflow-hidden rounded-2xl bg-slate-800"
                                >
                                    {product.feature_image_url ? (
                                        <img
                                            src={product.feature_image_url}
                                            alt={product.name}
                                            className="size-full object-cover transition-transform duration-500 group-hover:scale-105"
                                        />
                                    ) : (
                                        <div className="flex size-full items-center justify-center">
                                            <Boxes className="size-8 text-slate-500" />
                                        </div>
                                    )}
                                    <div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/90 to-transparent p-3 pt-10">
                                        <div className="truncate text-sm font-semibold">
                                            {product.name}
                                        </div>
                                        <div className="mt-1 text-xs text-cyan-300">
                                            {product.store?.name} ·{' '}
                                            {product.stock} available
                                        </div>
                                    </div>
                                </Link>
                            ))}
                        </div>
                    </div>
                </div>
            </section>

            <section className="mx-auto max-w-7xl px-4 py-16">
                <div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
                    <div>
                        <div className="text-sm font-semibold tracking-wider text-cyan-600 uppercase dark:text-cyan-400">
                            Browse by category
                        </div>
                        <h2 className="mt-2 text-3xl font-bold tracking-tight">
                            Find what you need faster
                        </h2>
                    </div>
                    <Link
                        href="/shop"
                        className="flex items-center gap-2 text-sm font-semibold hover:text-cyan-600"
                    >
                        View all products <ArrowRight className="size-4" />
                    </Link>
                </div>
                <div className="mt-8 grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
                    {categories.slice(0, 6).map((category, index) => (
                        <Link
                            key={category.id}
                            href={`/shop?category=${category.slug}`}
                            className="group relative overflow-hidden rounded-2xl border bg-white p-6 shadow-sm transition-all hover:-translate-y-1 hover:shadow-lg dark:bg-slate-900"
                        >
                            <div className="absolute top-0 right-0 text-8xl font-black text-slate-100 transition-colors group-hover:text-cyan-50 dark:text-slate-800 dark:group-hover:text-cyan-950/40">
                                {String(index + 1).padStart(2, '0')}
                            </div>
                            <div className="relative">
                                <h3 className="text-xl font-bold">
                                    {category.name}
                                </h3>
                                <p className="mt-2 line-clamp-2 max-w-xs text-sm leading-6 text-muted-foreground">
                                    {category.description ??
                                        'Explore available products in this category.'}
                                </p>
                                <ArrowRight className="mt-5 size-5 transition-transform group-hover:translate-x-1" />
                            </div>
                        </Link>
                    ))}
                </div>
            </section>

            <section className="border-y bg-slate-100/70 dark:bg-slate-900/50">
                <div className="mx-auto max-w-7xl px-4 py-16">
                    <div className="flex items-end justify-between gap-4">
                        <div>
                            <div className="text-sm font-semibold tracking-wider text-cyan-600 uppercase dark:text-cyan-400">
                                Fresh inventory
                            </div>
                            <h2 className="mt-2 text-3xl font-bold tracking-tight">
                                Featured products
                            </h2>
                            <p className="mt-2 text-muted-foreground">
                                See current stock and store availability at a
                                glance.
                            </p>
                        </div>
                    </div>
                    <div className="mt-8 grid gap-5 sm:grid-cols-2 lg:grid-cols-4">
                        {featuredProducts.map((product) => (
                            <ProductCard
                                key={product.id}
                                product={product}
                                settings={settings}
                            />
                        ))}
                    </div>
                </div>
            </section>

            <section className="mx-auto grid max-w-7xl gap-10 px-4 py-16 lg:grid-cols-[0.8fr_1.2fr] lg:items-center">
                <div>
                    <div className="flex size-14 items-center justify-center rounded-2xl bg-amber-400/15 text-amber-600">
                        <BadgeCheck className="size-7" />
                    </div>
                    <h2 className="mt-5 text-3xl font-bold tracking-tight">
                        Trusted brands, one searchable catalog
                    </h2>
                    <p className="mt-3 leading-7 text-muted-foreground">
                        Browse products from established brands and immediately
                        identify where each item is stocked.
                    </p>
                </div>
                <div className="flex flex-wrap gap-3">
                    {brands.map((brand) => (
                        <Link
                            key={brand.id}
                            href={`/shop?brand=${brand.slug}`}
                            className="rounded-full border bg-white px-5 py-3 text-sm font-semibold shadow-sm transition-colors hover:border-cyan-400 hover:text-cyan-600 dark:bg-slate-900"
                        >
                            {brand.name}
                        </Link>
                    ))}
                </div>
            </section>

            {recentPosts.length > 0 && (
                <section className="mx-auto max-w-7xl px-4 py-16">
                    <div className="flex items-end justify-between gap-4">
                        <div>
                            <div className="text-sm font-semibold tracking-wider text-cyan-600 uppercase dark:text-cyan-400">
                                From the journal
                            </div>
                            <h2 className="mt-2 text-3xl font-bold tracking-tight">
                                Latest stories
                            </h2>
                        </div>
                        <Button variant="outline" asChild>
                            <Link href="/blog">Read all</Link>
                        </Button>
                    </div>
                    <div className="mt-8 grid gap-5 md:grid-cols-3">
                        {recentPosts.map((post) => (
                            <Link
                                key={post.id}
                                href={`/blog/${post.slug}`}
                                className="group overflow-hidden rounded-2xl border bg-white shadow-sm dark:bg-slate-900"
                            >
                                <div className="aspect-video overflow-hidden bg-slate-100 dark:bg-slate-800">
                                    {post.feature_image_url && (
                                        <img
                                            src={post.feature_image_url}
                                            alt={post.title}
                                            className="size-full object-cover transition-transform duration-500 group-hover:scale-105"
                                        />
                                    )}
                                </div>
                                <div className="p-5">
                                    <div className="text-xs font-semibold text-cyan-600 uppercase">
                                        {post.published_at
                                            ? new Date(
                                                  post.published_at,
                                              ).toLocaleDateString()
                                            : 'Published'}
                                    </div>
                                    <h3 className="mt-2 line-clamp-2 text-lg font-bold">
                                        {post.title}
                                    </h3>
                                    <p className="mt-2 line-clamp-2 text-sm leading-6 text-muted-foreground">
                                        {post.excerpt ??
                                            'Read the full article.'}
                                    </p>
                                </div>
                            </Link>
                        ))}
                    </div>
                </section>
            )}
        </>
    );
}
