"use client";

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 FooterMedia from '@/components/sections/footer/FooterMedia';
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="text-stagger"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="compact"
                sizing="largeSmallSizeLargeTitles"
                background="floatingGradient"
                cardStyle="layered-gradient"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="layered"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="Brew & Bean"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "About", id: "about" },
                                { name: "Menu", id: "menu" },
                                { name: "Testimonials", id: "testimonials" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            bottomLeftText="Coffee Culture"
                            bottomRightText="hello@brewandbean.com"
                            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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/table-chairs-bar_107420-65857.jpg"
                            imageAlt="Brew & Bean coffee shop storefront"
                            logoText="Brew & Bean"
                            copyrightText="© 2025 Brew & Bean Coffee. All rights reserved."
                            columns={[
                                {
                                    title: "Menu",                                    items: [
                                        { label: "Espresso", href: "#menu" },
                                        { label: "Cappuccino", href: "#menu" },
                                        { label: "Cold Brew", href: "#menu" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About", href: "#about" },
                                        { label: "Our Story", href: "#about" },
                                        { label: "Sustainability", href: "#about" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "Phone: (555) 123-4567", href: "#" },
                                        { label: "Email: hello@brewandbean.com", href: "#" },
                                        { label: "123 Coffee Lane, Your City", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="compact"
            sizing="largeSmallSizeLargeTitles"
            background="floatingGradient"
            cardStyle="layered-gradient"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="layered"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="Brew & Bean"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Menu", id: "menu" },
                            { name: "Testimonials", id: "testimonials" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        bottomLeftText="Coffee Culture"
                        bottomRightText="hello@brewandbean.com"
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/table-chairs-bar_107420-65857.jpg"
                        imageAlt="Brew & Bean coffee shop storefront"
                        logoText="Brew & Bean"
                        copyrightText="© 2025 Brew & Bean Coffee. All rights reserved."
                        columns={[
                            {
                                title: "Menu",                                items: [
                                    { label: "Espresso", href: "#menu" },
                                    { label: "Cappuccino", href: "#menu" },
                                    { label: "Cold Brew", href: "#menu" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About", href: "#about" },
                                    { label: "Our Story", href: "#about" },
                                    { label: "Sustainability", href: "#about" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Phone: (555) 123-4567", href: "#" },
                                    { label: "Email: hello@brewandbean.com", href: "#" },
                                    { label: "123 Coffee Lane, Your City", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}