"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 FooterBase from '@/components/sections/footer/FooterBase';
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="text-stagger"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="small"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="subtle-shadow"
                primaryButtonStyle="flat"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="SocialHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Profile","id":"profile"},
                                {"name":"Messages","id":"messages"},
                                {"name":"Notifications","id":"notifications"},
                                {"name":"Settings","id":"settings"},
                                {"name":"Explore","id":"explore"},
                                {"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":"Home","href":"/"},{"label":"Explore","href":"explore"},{"label":"Trending","href":"trending"}]},
                                {"title":"Community","items":[{"label":"Creators","href":"creators"},{"label":"Events","href":"events"},{"label":"Groups","href":"groups"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"privacy"},{"label":"Terms of Service","href":"terms"},{"label":"Contact","href":"contact"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="small"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="subtle-shadow"
            primaryButtonStyle="flat"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="SocialHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Profile","id":"profile"},
                            {"name":"Messages","id":"messages"},
                            {"name":"Notifications","id":"notifications"},
                            {"name":"Settings","id":"settings"},
                            {"name":"Explore","id":"explore"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                    <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":"Home","href":"/"},{"label":"Explore","href":"explore"},{"label":"Trending","href":"trending"}]},
                            {"title":"Community","items":[{"label":"Creators","href":"creators"},{"label":"Events","href":"events"},{"label":"Groups","href":"groups"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"privacy"},{"label":"Terms of Service","href":"terms"},{"label":"Contact","href":"contact"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}