"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterCard from '@/components/sections/footer/FooterCard';
import { Instagram, Twitter, Mail } from 'lucide-react';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";

function ShopPageContent() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-magnetic"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="largeSmall"
                background="fluid"
                cardStyle="layered-gradient"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="The Soap Shop"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"products"},
                                {"name":"About","id":"about"},
                                {"name":"Reviews","id":"testimonials"},
                                {"name":"FAQ","id":"faq"}
                            ]}
                            button={{ text: "Cart", onClick: () => console.log("cart") }}
                            className="bg-background/80 backdrop-blur-md border border-accent/10"
                            navItemClassName="text-foreground hover:text-accent transition-colors"
                            buttonClassName="bg-primary-cta hover:bg-primary-cta/90"
                            buttonTextClassName="text-primary-cta-text font-medium"
                        />
                    </div>
                    <main className="min-h-screen flex items-center justify-center pt-20">
                        <p className="text-foreground">Loading products...</p>
                    </main>
                    <div id="footer" data-section="footer">
                        <FooterCard
                            logoText="The Soap Shop"
                            copyrightText="© 2025 The Soap Shop. Small-batch organic soap bars."
                            socialLinks={[
                                {"icon":Instagram,"href":"https://instagram.com/thesoapshop","ariaLabel":"Instagram"},
                                {"icon":Twitter,"href":"https://twitter.com/thesoapshop","ariaLabel":"Twitter"},
                                {"icon":Mail,"href":"mailto:hello@thesoapshop.com","ariaLabel":"Email"}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="largeSmall"
            background="fluid"
            cardStyle="layered-gradient"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="The Soap Shop"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"products"},
                            {"name":"About","id":"about"},
                            {"name":"Reviews","id":"testimonials"},
                            {"name":"FAQ","id":"faq"}
                        ]}
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                        className="bg-background/80 backdrop-blur-md border border-accent/10"
                        navItemClassName="text-foreground hover:text-accent transition-colors"
                        buttonClassName="bg-primary-cta hover:bg-primary-cta/90"
                        buttonTextClassName="text-primary-cta-text font-medium"
                    />
                </div>
                <div id="productCatalog" data-section="productCatalog">
                    <ProductCatalog
                        layout="page"
                        products={products}
                        searchValue={search}
                        onSearchChange={setSearch}
                        searchPlaceholder="Search products..."
                        filters={filters}
                        emptyMessage="No products found"
                    />
                </div>
                <div id="footer" data-section="footer">
                    <FooterCard
                        logoText="The Soap Shop"
                        copyrightText="© 2025 The Soap Shop. Small-batch organic soap bars."
                        socialLinks={[
                            {"icon":Instagram,"href":"https://instagram.com/thesoapshop","ariaLabel":"Instagram"},
                            {"icon":Twitter,"href":"https://twitter.com/thesoapshop","ariaLabel":"Twitter"},
                            {"icon":Mail,"href":"mailto:hello@thesoapshop.com","ariaLabel":"Email"}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

export default function ShopPage() {
    return (
        <Suspense>
            <ShopPageContent />
        </Suspense>
    );
}