"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 FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
import { useProductCatalog } from "@/hooks/useProductCatalog";

export default function ShopPage() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumSmall"
                sizing="largeSmallSizeLargeTitles"
                background="blurBottom"
                cardStyle="gradient-mesh"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Precision Pools"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Pool Installation", id: "pool-installation" },
                                { name: "Liner Replacement", id: "liner-replacement" },
                                { name: "Pool Services", id: "pool-services" },
                                { name: "Reviews", id: "reviews" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => console.log("cart") }}
                        />
                    </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">
                        <FooterLogoEmphasis
                            logoText="Precision Pools"
                            columns={[
                                {
                                    items: [
                                        { label: "Home", href: "#home" },
                                        { label: "Pool Installation", href: "#pool-installation" },
                                        { label: "Liner Replacement", href: "#liner-replacement" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Pool Services", href: "#pool-services" },
                                        { label: "Reviews", href: "#reviews" },
                                        { label: "Contact", href: "#contact" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Tonawanda, NY 14150", href: "#" },
                                        { label: "(716) 563-4603", href: "tel:+17165634603" },
                                        { label: "51 Fillmore Ave", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumSmall"
            sizing="largeSmallSizeLargeTitles"
            background="blurBottom"
            cardStyle="gradient-mesh"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Precision Pools"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Pool Installation", id: "pool-installation" },
                            { name: "Liner Replacement", id: "liner-replacement" },
                            { name: "Pool Services", id: "pool-services" },
                            { name: "Reviews", id: "reviews" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => console.log("cart") }}
                    />
                </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">
                    <FooterLogoEmphasis
                        logoText="Precision Pools"
                        columns={[
                            {
                                items: [
                                    { label: "Home", href: "#home" },
                                    { label: "Pool Installation", href: "#pool-installation" },
                                    { label: "Liner Replacement", href: "#liner-replacement" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Pool Services", href: "#pool-services" },
                                    { label: "Reviews", href: "#reviews" },
                                    { label: "Contact", href: "#contact" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Tonawanda, NY 14150", href: "#" },
                                    { label: "(716) 563-4603", href: "tel:+17165634603" },
                                    { label: "51 Fillmore Ave", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}