"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
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="elastic-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="medium"
                sizing="medium"
                background="floatingGradient"
                cardStyle="glass-depth"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                            brandName="SocialHub"
                        />
                    </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">
                        <FooterBaseCard
                            logoText="SocialHub"
                            columns={[
                                {"title":"Platform","items":[{"label":"Explore","href":"#explore"},{"label":"Trending","href":"#trending"},{"label":"Discover","href":"#discover"}]},
                                {"title":"Community","items":[{"label":"Guidelines","href":"#guidelines"},{"label":"Support","href":"#support"},{"label":"Feedback","href":"#feedback"}]},
                                {"title":"Account","items":[{"label":"Settings","href":"#settings"},{"label":"Privacy","href":"#privacy"},{"label":"Security","href":"#security"}]},
                                {"title":"Connect","items":[{"label":"Twitter","href":"#twitter"},{"label":"Instagram","href":"#instagram"},{"label":"Contact","href":"#contact"}]}
                            ]}
                            copyrightText="© 2025 SocialHub. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="medium"
            sizing="medium"
            background="floatingGradient"
            cardStyle="glass-depth"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        brandName="SocialHub"
                    />
                </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">
                    <FooterBaseCard
                        logoText="SocialHub"
                        columns={[
                            {"title":"Platform","items":[{"label":"Explore","href":"#explore"},{"label":"Trending","href":"#trending"},{"label":"Discover","href":"#discover"}]},
                            {"title":"Community","items":[{"label":"Guidelines","href":"#guidelines"},{"label":"Support","href":"#support"},{"label":"Feedback","href":"#feedback"}]},
                            {"title":"Account","items":[{"label":"Settings","href":"#settings"},{"label":"Privacy","href":"#privacy"},{"label":"Security","href":"#security"}]},
                            {"title":"Connect","items":[{"label":"Twitter","href":"#twitter"},{"label":"Instagram","href":"#instagram"},{"label":"Contact","href":"#contact"}]}
                        ]}
                        copyrightText="© 2025 SocialHub. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}