"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="elastic-effect"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="smallMedium"
                sizing="mediumLarge"
                background="floatingGradient"
                cardStyle="gradient-bordered"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="SocialHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Explore","id":"explore"},
                                {"name":"Messages","id":"messages"},
                                {"name":"Notifications","id":"notifications"},
                                {"name":"Settings","id":"settings"},
                                {"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">
                        <FooterBase
                            logoText="SocialHub"
                            copyrightText="© 2025 SocialHub. All rights reserved."
                            columns={[
                                {"title":"Platform","items":[{"label":"Explore","href":"explore"},{"label":"Trends","href":"trends"},{"label":"Creator Program","href":"creators"}]},
                                {"title":"Connect","items":[{"label":"Messages","href":"messages"},{"label":"Notifications","href":"notifications"},{"label":"Communities","href":"communities"}]},
                                {"title":"Account","items":[{"label":"Settings","href":"settings"},{"label":"Privacy","href":"#"},{"label":"Terms","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="smallMedium"
            sizing="mediumLarge"
            background="floatingGradient"
            cardStyle="gradient-bordered"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="SocialHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Explore","id":"explore"},
                            {"name":"Messages","id":"messages"},
                            {"name":"Notifications","id":"notifications"},
                            {"name":"Settings","id":"settings"},
                            {"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">
                    <FooterBase
                        logoText="SocialHub"
                        copyrightText="© 2025 SocialHub. All rights reserved."
                        columns={[
                            {"title":"Platform","items":[{"label":"Explore","href":"explore"},{"label":"Trends","href":"trends"},{"label":"Creator Program","href":"creators"}]},
                            {"title":"Connect","items":[{"label":"Messages","href":"messages"},{"label":"Notifications","href":"notifications"},{"label":"Communities","href":"communities"}]},
                            {"title":"Account","items":[{"label":"Settings","href":"settings"},{"label":"Privacy","href":"#"},{"label":"Terms","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}