"use client";

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

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

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="mediumLargeSizeLargeTitles"
                background="floatingGradient"
                cardStyle="glass-elevated"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="Editorial"
                            bottomLeftText="Since 2024"
                            bottomRightText="hello@editorial.com"
                            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">
                        <FooterLogoEmphasis
                            logoText="Editorial"
                            columns={[
                                {"items":[{"label":"Home","href":"/"},{"label":"Shop","href":"/shop"}]},
                                {"items":[{"label":"Contact","href":"/contacts"}]},
                                {"items":[{"label":"Privacy Policy","href":"https://example.com/privacy"},{"label":"Terms of Service","href":"https://example.com/terms"},{"label":"RSS Feed","href":"https://example.com/rss"}]},
                                {"items":[{"label":"Twitter","href":"https://twitter.com/editorial"},{"label":"LinkedIn","href":"https://linkedin.com/company/editorial"},{"label":"Instagram","href":"https://instagram.com/editorial"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="mediumLargeSizeLargeTitles"
            background="floatingGradient"
            cardStyle="glass-elevated"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"},
                            {"name":"Contact","id":"/contacts"}
                        ]}
                        brandName="Editorial"
                        bottomLeftText="Since 2024"
                        bottomRightText="hello@editorial.com"
                        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">
                    <FooterLogoEmphasis
                        logoText="Editorial"
                        columns={[
                            {"items":[{"label":"Home","href":"/"},{"label":"Shop","href":"/shop"}]},
                            {"items":[{"label":"Contact","href":"/contacts"}]},
                            {"items":[{"label":"Privacy Policy","href":"https://example.com/privacy"},{"label":"Terms of Service","href":"https://example.com/terms"},{"label":"RSS Feed","href":"https://example.com/rss"}]},
                            {"items":[{"label":"Twitter","href":"https://twitter.com/editorial"},{"label":"LinkedIn","href":"https://linkedin.com/company/editorial"},{"label":"Instagram","href":"https://instagram.com/editorial"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}