"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
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="text-shift"
                defaultTextAnimation="background-highlight"
                borderRadius="sharp"
                contentWidth="mediumSmall"
                sizing="medium"
                background="none"
                cardStyle="inset"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Midnight Coffee"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"},
                                {"name":"Contact","id":"/contacts"}
                            ]}
                            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/fragrant-coffee-beans-are-scattered-from-jar-rustic-tabletop-background-closeup-selective-focus-copy-space-banner_166373-2309.jpg"
                            imageAlt="Premium coffee shop aesthetic"
                            logoText="Midnight Coffee"
                            copyrightText="© 2025 Midnight Coffee. All rights reserved."
                            columns={[
                                {"title":"Shop","items":[{"label":"All Coffees","href":"/shop"},{"label":"Subscribe","href":"/contacts"},{"label":"Gift Cards","href":"#"},{"label":"Brewing Gear","href":"#"}]},
                                {"title":"About","items":[{"label":"Our Story","href":"#"},{"label":"Sourcing","href":"#"},{"label":"Roasting Process","href":"#"},{"label":"Sustainability","href":"#"}]},
                                {"title":"Connect","items":[{"label":"Contact Us","href":"/contacts"},{"label":"Instagram","href":"#"},{"label":"Book a Tasting","href":"/contacts"},{"label":"Wholesale Inquiry","href":"#"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="background-highlight"
            borderRadius="sharp"
            contentWidth="mediumSmall"
            sizing="medium"
            background="none"
            cardStyle="inset"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Midnight Coffee"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"},
                            {"name":"Contact","id":"/contacts"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/fragrant-coffee-beans-are-scattered-from-jar-rustic-tabletop-background-closeup-selective-focus-copy-space-banner_166373-2309.jpg"
                        imageAlt="Premium coffee shop aesthetic"
                        logoText="Midnight Coffee"
                        copyrightText="© 2025 Midnight Coffee. All rights reserved."
                        columns={[
                            {"title":"Shop","items":[{"label":"All Coffees","href":"/shop"},{"label":"Subscribe","href":"/contacts"},{"label":"Gift Cards","href":"#"},{"label":"Brewing Gear","href":"#"}]},
                            {"title":"About","items":[{"label":"Our Story","href":"#"},{"label":"Sourcing","href":"#"},{"label":"Roasting Process","href":"#"},{"label":"Sustainability","href":"#"}]},
                            {"title":"Connect","items":[{"label":"Contact Us","href":"/contacts"},{"label":"Instagram","href":"#"},{"label":"Book a Tasting","href":"/contacts"},{"label":"Wholesale Inquiry","href":"#"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}