"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
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="hover-magnetic"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="medium"
                sizing="mediumLargeSizeMediumTitles"
                background="aurora"
                cardStyle="glass-depth"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="DetailPro Mobile"
                            bottomLeftText="Available 24/7"
                            bottomRightText="hello@detailpro.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">
                        <FooterBaseReveal
                            columns={[
                                {"title":"Services","items":[{"label":"Exterior Detailing","href":"services"},{"label":"Interior Cleaning","href":"services"},{"label":"Ceramic Coating","href":"services"},{"label":"Fleet Services","href":"#"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Contact","href":"contact"},{"label":"FAQ","href":"faq"},{"label":"Blog","href":"#"}]},
                                {"title":"Contact","items":[{"label":"hello@detailpro.com","href":"#"},{"label":"(555) 123-4567","href":"#"},{"label":"Available 24/7","href":"#"},{"label":"Service Area Map","href":"#"}]}
                            ]}
                            copyrightText="© 2025 DetailPro Mobile | Professional Car Detailing"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="medium"
            sizing="mediumLargeSizeMediumTitles"
            background="aurora"
            cardStyle="glass-depth"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="DetailPro Mobile"
                        bottomLeftText="Available 24/7"
                        bottomRightText="hello@detailpro.com"
                        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">
                    <FooterBaseReveal
                        columns={[
                            {"title":"Services","items":[{"label":"Exterior Detailing","href":"services"},{"label":"Interior Cleaning","href":"services"},{"label":"Ceramic Coating","href":"services"},{"label":"Fleet Services","href":"#"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Contact","href":"contact"},{"label":"FAQ","href":"faq"},{"label":"Blog","href":"#"}]},
                            {"title":"Contact","items":[{"label":"hello@detailpro.com","href":"#"},{"label":"(555) 123-4567","href":"#"},{"label":"Available 24/7","href":"#"},{"label":"Service Area Map","href":"#"}]}
                        ]}
                        copyrightText="© 2025 DetailPro Mobile | Professional Car Detailing"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}