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

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

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="shift-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="smallMedium"
                sizing="largeSmall"
                background="noiseDiagonalGradient"
                cardStyle="inset"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "Storm Damage", id: "storm" },
                            { name: "Gallery", id: "projects" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Viking Construction"
                        bottomLeftText="Licensed & Insured"
                        bottomRightText="Fast Response • Insurance Support"
                    />
                    </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
                        columns={[
                            {
                                items: [
                                    { label: "Home", href: "/" },
                                    { label: "Services", href: "/services" },
                                    { label: "Storm Damage", href: "/storm-damage" },
                                    { label: "Projects", href: "/projects" }
                                ]
                            },
                            {
                                items: [
                                    { label: "About Us", href: "#" },
                                    { label: "Inspections", href: "#" },
                                    { label: "Starlink Mounting", href: "#" },
                                    { label: "Contact", href: "/contact" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" },
                                    { label: "Warranty Info", href: "#" },
                                    { label: "Insurance FAQ", href: "#" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Call Us", href: "tel:1-800-ROOFING" },
                                    { label: "Text Us", href: "#" },
                                    { label: "Email Support", href: "mailto:support@vikingconstruction.com" },
                                    { label: "24/7 Emergency", href: "tel:1-800-ROOFING" }
                                ]
                            }
                        ]}
                        logoText="Viking Construction"
                        ariaLabel="Site footer with navigation and contact links"
                    />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="smallMedium"
            sizing="largeSmall"
            background="noiseDiagonalGradient"
            cardStyle="inset"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarStyleFullscreen
                    navItems={[
                        { name: "Home", id: "/" },
                        { name: "Services", id: "services" },
                        { name: "Storm Damage", id: "storm" },
                        { name: "Gallery", id: "projects" },
                        { name: "Contact", id: "contact" },
                        { name: "Shop", id: "/shop" }
                    ]}
                    brandName="Viking Construction"
                    bottomLeftText="Licensed & Insured"
                    bottomRightText="Fast Response • Insurance Support"
                />
                </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
                    columns={[
                        {
                            items: [
                                { label: "Home", href: "/" },
                                { label: "Services", href: "/services" },
                                { label: "Storm Damage", href: "/storm-damage" },
                                { label: "Projects", href: "/projects" }
                            ]
                        },
                        {
                            items: [
                                { label: "About Us", href: "#" },
                                { label: "Inspections", href: "#" },
                                { label: "Starlink Mounting", href: "#" },
                                { label: "Contact", href: "/contact" }
                            ]
                        },
                        {
                            items: [
                                { label: "Privacy Policy", href: "#" },
                                { label: "Terms of Service", href: "#" },
                                { label: "Warranty Info", href: "#" },
                                { label: "Insurance FAQ", href: "#" }
                            ]
                        },
                        {
                            items: [
                                { label: "Call Us", href: "tel:1-800-ROOFING" },
                                { label: "Text Us", href: "#" },
                                { label: "Email Support", href: "mailto:support@vikingconstruction.com" },
                                { label: "24/7 Emergency", href: "tel:1-800-ROOFING" }
                            ]
                        }
                    ]}
                    logoText="Viking Construction"
                    ariaLabel="Site footer with navigation and contact links"
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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