"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 FooterSimple from '@/components/sections/footer/FooterSimple';
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="expand-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="rounded"
                contentWidth="smallMedium"
                sizing="largeSmallSizeLargeTitles"
                background="aurora"
                cardStyle="soft-shadow"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Imperio"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Services","id":"services"},
                                {"name":"About","id":"about"},
                                {"name":"Process","id":"process"},
                                {"name":"Gallery","id":"gallery"},
                                {"name":"Contact","id":"contact"},
                                {"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">
                        <FooterSimple
                            columns={[
                                {"title":"Navigate","items":[{"label":"Home","href":"#"},{"label":"Services","href":"#services"},{"label":"About","href":"#about"},{"label":"Gallery","href":"#gallery"}]},
                                {"title":"Services","items":[{"label":"Paint Correction","href":"#services"},{"label":"Ceramic Coating","href":"#services"},{"label":"Interior Detail","href":"#services"},{"label":"Full Detail Package","href":"#services"}]},
                                {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com/imperio-detailing"},{"label":"Contact","href":"#contact"},{"label":"Book Now","href":"#contact"},{"label":"FAQ","href":"#"}]}
                            ]}
                            bottomLeftText="© 2025 Imperio Car Detailing. All rights reserved."
                            bottomRightText="Command the Road."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="rounded"
            contentWidth="smallMedium"
            sizing="largeSmallSizeLargeTitles"
            background="aurora"
            cardStyle="soft-shadow"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Imperio"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"About","id":"about"},
                            {"name":"Process","id":"process"},
                            {"name":"Gallery","id":"gallery"},
                            {"name":"Contact","id":"contact"},
                            {"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">
                    <FooterSimple
                        columns={[
                            {"title":"Navigate","items":[{"label":"Home","href":"#"},{"label":"Services","href":"#services"},{"label":"About","href":"#about"},{"label":"Gallery","href":"#gallery"}]},
                            {"title":"Services","items":[{"label":"Paint Correction","href":"#services"},{"label":"Ceramic Coating","href":"#services"},{"label":"Interior Detail","href":"#services"},{"label":"Full Detail Package","href":"#services"}]},
                            {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com/imperio-detailing"},{"label":"Contact","href":"#contact"},{"label":"Book Now","href":"#contact"},{"label":"FAQ","href":"#"}]}
                        ]}
                        bottomLeftText="© 2025 Imperio Car Detailing. All rights reserved."
                        bottomRightText="Command the Road."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}