"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="directional-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="mediumLarge"
                sizing="large"
                background="none"
                cardStyle="subtle-shadow"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="SocialHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Profile","id":"profile"},
                                {"name":"Explore","id":"explore"},
                                {"name":"Messages","id":"messages"},
                                {"name":"Settings","id":"settings"},
                                {"name":"Help","id":"help"},
                                {"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":"Discover","href":"discover"},{"label":"Trends","href":"trends"}]},
                                {"title":"Community","items":[{"label":"Guidelines","href":"guidelines"},{"label":"Safety","href":"safety"},{"label":"Support","href":"support"}]},
                                {"title":"Connect","items":[{"label":"Contact","href":"contact"},{"label":"Business","href":"business"},{"label":"Partnerships","href":"partnerships"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="mediumLarge"
            sizing="large"
            background="none"
            cardStyle="subtle-shadow"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="SocialHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Profile","id":"profile"},
                            {"name":"Explore","id":"explore"},
                            {"name":"Messages","id":"messages"},
                            {"name":"Settings","id":"settings"},
                            {"name":"Help","id":"help"},
                            {"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":"Discover","href":"discover"},{"label":"Trends","href":"trends"}]},
                            {"title":"Community","items":[{"label":"Guidelines","href":"guidelines"},{"label":"Safety","href":"safety"},{"label":"Support","href":"support"}]},
                            {"title":"Connect","items":[{"label":"Contact","href":"contact"},{"label":"Business","href":"business"},{"label":"Partnerships","href":"partnerships"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}