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

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

    const navbar = (
        <div id="navbar" data-section="navbar">
            <NavbarStyleFullscreen
                brandName="Go Fast"
                navItems={[
                    { name: "Home", id: "/" },
                    { name: "About", id: "/about" },
                    { name: "Team", id: "/team" },
                    { name: "News", id: "/news" },
                    { name: "Contact", id: "/contact" },
                    { name: "Shop", id: "/shop" }
                ]}
                bottomLeftText="Youth Football Team"
                bottomRightText="gofast@example.com"
                button={{ text: "Cart", onClick: () => {} }}
            />
        </div>
    );

    const footer = (
        <div id="footer" data-section="footer">
            <FooterMedia
                videoSrc="https://img.b2bpic.net/free-photo/green-grass-sports-field-boundary-line_84443-73902.jpg"
                videoAriaLabel="Green soccer field texture"
                logoText="Go Fast"
                columns={[
                    { title: "Team", items: [{ label: "About Us", href: "#about" }, { label: "Our Squad", href: "#team" }, { label: "News & Events", href: "#news" }] },
                    { title: "Support", items: [{ label: "FAQs", href: "#faq" }, { label: "Contact Us", href: "#contact" }, { label: "Privacy Policy", href: "/privacy-policy" }] }
                ]}
                copyrightText="© 2024 Go Fast Football. All rights reserved."
            />
        </div>
    );

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="bounce-effect"
                defaultTextAnimation="background-highlight"
                borderRadius="rounded"
                contentWidth="mediumSmall"
                sizing="mediumLargeSizeMediumTitles"
                background="noiseDiagonalGradient"
                cardStyle="soft-shadow"
                primaryButtonStyle="primary-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    {navbar}
                    <main className="min-h-screen flex items-center justify-center pt-20">
                        <p className="text-foreground">Loading products...</p>
                    </main>
                    {footer}
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="rounded"
            contentWidth="mediumSmall"
            sizing="mediumLargeSizeMediumTitles"
            background="noiseDiagonalGradient"
            cardStyle="soft-shadow"
            primaryButtonStyle="primary-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                {navbar}
                <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>
                {footer}
            </ReactLenis>
        </ThemeProvider>
    );
}

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