"use client";

import { Suspense } from "react";
import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import FooterBase from '@/components/sections/footer/FooterBase';
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="text-shift"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="largeSmall"
                background="fluid"
                cardStyle="outline"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="layered"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="K&G Digital 360"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { name: "Contact", id: "contact" }
                            ]}
                            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">
                        <FooterBase
                            logoText="K&G Digital 360"
                            copyrightText="© 2025 K&G Digital 360. All rights reserved."
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Branding", href: "#services" },
                                        { label: "Social Media", href: "#services" },
                                        { label: "Paid Ads", href: "#services" },
                                        { label: "Web Design", href: "#services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "#why-kg" },
                                        { label: "Process", href: "#process" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "Privacy", href: "#" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "LinkedIn", href: "https://linkedin.com" },
                                        { label: "Twitter", href: "https://twitter.com" },
                                        { label: "Email", href: "mailto:hello@kgdigital360.com" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="largeSmall"
            background="fluid"
            cardStyle="outline"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="layered"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="K&G Digital 360"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "contact" }
                        ]}
                        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">
                    <FooterBase
                        logoText="K&G Digital 360"
                        copyrightText="© 2025 K&G Digital 360. All rights reserved."
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Branding", href: "#services" },
                                    { label: "Social Media", href: "#services" },
                                    { label: "Paid Ads", href: "#services" },
                                    { label: "Web Design", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "#why-kg" },
                                    { label: "Process", href: "#process" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "Privacy", href: "#" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "LinkedIn", href: "https://linkedin.com" },
                                    { label: "Twitter", href: "https://twitter.com" },
                                    { label: "Email", href: "mailto:hello@kgdigital360.com" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}

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