"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 [cartOpen, setCartOpen] = useState(false);
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="directional-hover"
                defaultTextAnimation="reveal-blur"
                borderRadius="rounded"
                contentWidth="smallMedium"
                sizing="mediumLargeSizeMediumTitles"
                background="floatingGradient"
                cardStyle="inset"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="layered"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "About", id: "about" },
                            { name: "Experience", id: "features" },
                            { name: "Visit", id: "contact" },
                            { name: "Connect", id: "newsletter" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Fix Coffee"
                        bottomLeftText="Quiet spaces for creative minds"
                        bottomRightText="hello@fixcoffee.local"
                        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>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="smallMedium"
            sizing="mediumLargeSizeMediumTitles"
            background="floatingGradient"
            cardStyle="inset"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="layered"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                <NavbarStyleFullscreen
                    navItems={[
                        { name: "Home", id: "/" },
                        { name: "About", id: "about" },
                        { name: "Experience", id: "features" },
                        { name: "Visit", id: "contact" },
                        { name: "Connect", id: "newsletter" },
                        { name: "Shop", id: "/shop" }
                    ]}
                    brandName="Fix Coffee"
                    bottomLeftText="Quiet spaces for creative minds"
                    bottomRightText="hello@fixcoffee.local"
                    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/team-young-colleagues-having-meeting-cafe_273609-16250.jpg"
                    imageAlt="Fix Coffee community gathering"
                    logoText="Fix Coffee"
                    copyrightText="© 2025 Fix Coffee. Brewed with care for creative minds."
                    columns={[
                        {
                            title: "Explore",                            items: [
                                { label: "About Us", href: "#about" },
                                { label: "Experience", href: "#features" },
                                { label: "Gallery", href: "#gallery" }
                            ]
                        },
                        {
                            title: "Connect",                            items: [
                                { label: "Email Us", href: "mailto:hello@fixcoffee.local" },
                                { label: "Instagram", href: "https://instagram.com" },
                                { label: "Community Events", href: "#" }
                            ]
                        },
                        {
                            title: "Hours",                            items: [
                                { label: "Mon–Fri: 7am–8pm", href: "#" },
                                { label: "Sat–Sun: 8am–9pm", href: "#" },
                                { label: "Closed: Holiday", href: "#" }
                            ]
                        }
                    ]}
                />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}