"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
import { useProductCatalog } from "@/hooks/useProductCatalog";
import { useState } from "react";

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

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="slide-background"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="large"
                background="none"
                cardStyle="gradient-radial"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="BrewCraft"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                        />
                    </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: "Shop",                                    items: [
                                        { label: "Menu", href: "https://www.example.com/menu" },
                                        { label: "Order Online", href: "https://www.example.com/order" },
                                        { label: "Gift Cards", href: "https://www.example.com/gifts" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Careers", href: "https://www.example.com/careers" },
                                        { label: "Blog", href: "https://www.example.com/blog" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Contact", href: "contact" },
                                        { label: "Instagram", href: "https://instagram.com/brewcraft" },
                                        { label: "Facebook", href: "https://facebook.com/brewcraft" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 BrewCraft Coffee. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="large"
            background="none"
            cardStyle="gradient-radial"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="BrewCraft"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <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>
                <div id="footer" data-section="footer">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Shop",                                items: [
                                    { label: "Menu", href: "https://www.example.com/menu" },
                                    { label: "Order Online", href: "https://www.example.com/order" },
                                    { label: "Gift Cards", href: "https://www.example.com/gifts" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Careers", href: "https://www.example.com/careers" },
                                    { label: "Blog", href: "https://www.example.com/blog" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Contact", href: "contact" },
                                    { label: "Instagram", href: "https://instagram.com/brewcraft" },
                                    { label: "Facebook", href: "https://facebook.com/brewcraft" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 BrewCraft Coffee. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}