"use client";

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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="medium"
                sizing="mediumLarge"
                background="noise"
                cardStyle="subtle-shadow"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"About","id":"about"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Gallery","id":"gallery"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="Northstar Roofing"
                        bottomLeftText="North Dakota Roofing"
                        bottomRightText="(701) 555-0100"
                        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">
                    <FooterBaseReveal
                        columns={[
                            {"title":"Services","items":[{"label":"Roof Replacement","href":"/residential"},{"label":"Roof Repair","href":"/residential"},{"label":"Storm Damage","href":"/storm-damage"},{"label":"Commercial","href":"/commercial"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"/about"},{"label":"Gallery","href":"/gallery"},{"label":"Reviews","href":"/reviews"},{"label":"Contact","href":"/contact"}]},
                            {"title":"Contact","items":[{"label":"Phone: (701) 555-0100","href":"tel:+17015550100"},{"label":"Emergency: 24/7 Available","href":"tel:+17015550100"},{"label":"Licensed & Insured","href":"#"},{"label":"BBB Accredited","href":"#"}]}
                        ]}
                        copyrightText="© 2025 Northstar Roofing LLC. North Dakota Roofing Specialists. All rights reserved."
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="medium"
            sizing="mediumLarge"
            background="noise"
            cardStyle="subtle-shadow"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarStyleFullscreen
                    navItems={[
                        {"name":"Home","id":"/"},
                        {"name":"Services","id":"services"},
                        {"name":"About","id":"about"},
                        {"name":"Contact","id":"contact"},
                        {"name":"Gallery","id":"gallery"},
                        {"name":"Shop","id":"/shop"}
                    ]}
                    brandName="Northstar Roofing"
                    bottomLeftText="North Dakota Roofing"
                    bottomRightText="(701) 555-0100"
                    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">
                <FooterBaseReveal
                    columns={[
                        {"title":"Services","items":[{"label":"Roof Replacement","href":"/residential"},{"label":"Roof Repair","href":"/residential"},{"label":"Storm Damage","href":"/storm-damage"},{"label":"Commercial","href":"/commercial"}]},
                        {"title":"Company","items":[{"label":"About Us","href":"/about"},{"label":"Gallery","href":"/gallery"},{"label":"Reviews","href":"/reviews"},{"label":"Contact","href":"/contact"}]},
                        {"title":"Contact","items":[{"label":"Phone: (701) 555-0100","href":"tel:+17015550100"},{"label":"Emergency: 24/7 Available","href":"tel:+17015550100"},{"label":"Licensed & Insured","href":"#"},{"label":"BBB Accredited","href":"#"}]}
                    ]}
                    copyrightText="© 2025 Northstar Roofing LLC. North Dakota Roofing Specialists. All rights reserved."
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

export default function ShopPage() {
    return (
        <Suspense>
            <ShopPageContent />
        </Suspense>
    );
}