"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
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-shift"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="compact"
                sizing="largeSizeMediumTitles"
                background="none"
                cardStyle="inset"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="ShopHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            bottomLeftText="Premium E-Commerce"
                            bottomRightText="hello@shophub.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">
                        <FooterSimple
                            columns={[
                                {"title":"Shop","items":[{"label":"All Products","href":"/products"},{"label":"New Arrivals","href":"/new"},{"label":"Sale Items","href":"/sale"},{"label":"Clearance","href":"/clearance"}]},
                                {"title":"Support","items":[{"label":"Contact Us","href":"/contact"},{"label":"Shipping Info","href":"/shipping"},{"label":"Returns","href":"/returns"},{"label":"Size Guide","href":"/size-guide"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"/about"},{"label":"Blog","href":"/blog"},{"label":"Careers","href":"/careers"},{"label":"Press","href":"/press"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"/privacy"},{"label":"Terms of Service","href":"/terms"},{"label":"Cookie Policy","href":"/cookies"}]}
                            ]}
                            bottomLeftText="© 2025 ShopHub. All rights reserved."
                            bottomRightText="Crafted with care for modern shoppers"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="compact"
            sizing="largeSizeMediumTitles"
            background="none"
            cardStyle="inset"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="ShopHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        bottomLeftText="Premium E-Commerce"
                        bottomRightText="hello@shophub.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">
                    <FooterSimple
                        columns={[
                            {"title":"Shop","items":[{"label":"All Products","href":"/products"},{"label":"New Arrivals","href":"/new"},{"label":"Sale Items","href":"/sale"},{"label":"Clearance","href":"/clearance"}]},
                            {"title":"Support","items":[{"label":"Contact Us","href":"/contact"},{"label":"Shipping Info","href":"/shipping"},{"label":"Returns","href":"/returns"},{"label":"Size Guide","href":"/size-guide"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"/about"},{"label":"Blog","href":"/blog"},{"label":"Careers","href":"/careers"},{"label":"Press","href":"/press"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"/privacy"},{"label":"Terms of Service","href":"/terms"},{"label":"Cookie Policy","href":"/cookies"}]}
                        ]}
                        bottomLeftText="© 2025 ShopHub. All rights reserved."
                        bottomRightText="Crafted with care for modern shoppers"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}