"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
import { useProductCatalog } from "@/hooks/useProductCatalog";
import { useState } from "react";

export default function ShopPage() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });
    
    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-magnetic"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="compact"
                sizing="mediumLargeSizeLargeTitles"
                background="aurora"
                cardStyle="glass-elevated"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Spike Media"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Services","id":"services"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"name":"Contact","id":"contact"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </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">
                        <FooterSimple
                            columns={[
                                {"title":"Company","items":[{"label":"About","href":"#about"},{"label":"Services","href":"#services"},{"label":"Contact","href":"#contact"}]},
                                {"title":"Resources","items":[{"label":"Blog","href":"#"},{"label":"Portfolio","href":"#"},{"label":"Case Studies","href":"#"}]},
                                {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"TikTok","href":"https://tiktok.com"},{"label":"Email","href":"mailto:hello@spikemedia.com"}]}
                            ]}
                            bottomLeftText="© 2025 Spike Media. All rights reserved."
                            bottomRightText="Created with passion for authentic content"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="compact"
            sizing="mediumLargeSizeLargeTitles"
            background="aurora"
            cardStyle="glass-elevated"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Spike Media"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Services","id":"services"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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">
                    <FooterSimple
                        columns={[
                            {"title":"Company","items":[{"label":"About","href":"#about"},{"label":"Services","href":"#services"},{"label":"Contact","href":"#contact"}]},
                            {"title":"Resources","items":[{"label":"Blog","href":"#"},{"label":"Portfolio","href":"#"},{"label":"Case Studies","href":"#"}]},
                            {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"TikTok","href":"https://tiktok.com"},{"label":"Email","href":"mailto:hello@spikemedia.com"}]}
                        ]}
                        bottomLeftText="© 2025 Spike Media. All rights reserved."
                        bottomRightText="Created with passion for authentic content"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}