"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-stagger"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="small"
                sizing="mediumLarge"
                background="none"
                cardStyle="gradient-radial"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Midnight Cafe"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Menu","id":"menu"},
                                {"name":"About","id":"about"},
                                {"name":"Atmosphere","id":"atmosphere"},
                                {"name":"Community","id":"community"},
                                {"name":"Contact","id":"contact"},
                                {"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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/full-shot-business-owner-standing-outdoors_23-2149434497.jpg"
                            imageAlt="Midnight Cafe storefront in the evening"
                            logoText="Midnight Cafe"
                            copyrightText="© 2025 Midnight Cafe. A neighborhood ritual."
                            columns={[
                                {"title":"Hours","items":[{"label":"Mon-Fri: 7am - 11pm","href":""},{"label":"Sat-Sun: 8am - 12am","href":""}]},
                                {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Email","href":"mailto:hello@midnightcafe.local"},{"label":"Phone","href":"tel:+1234567890"}]},
                                {"title":"Visit","items":[{"label":"123 Neighborhood St","href":"https://maps.google.com"},{"label":"Parking Available","href":""}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="small"
            sizing="mediumLarge"
            background="none"
            cardStyle="gradient-radial"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Midnight Cafe"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Menu","id":"menu"},
                            {"name":"About","id":"about"},
                            {"name":"Atmosphere","id":"atmosphere"},
                            {"name":"Community","id":"community"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        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/full-shot-business-owner-standing-outdoors_23-2149434497.jpg"
                        imageAlt="Midnight Cafe storefront in the evening"
                        logoText="Midnight Cafe"
                        copyrightText="© 2025 Midnight Cafe. A neighborhood ritual."
                        columns={[
                            {"title":"Hours","items":[{"label":"Mon-Fri: 7am - 11pm","href":""},{"label":"Sat-Sun: 8am - 12am","href":""}]},
                            {"title":"Connect","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Email","href":"mailto:hello@midnightcafe.local"},{"label":"Phone","href":"tel:+1234567890"}]},
                            {"title":"Visit","items":[{"label":"123 Neighborhood St","href":"https://maps.google.com"},{"label":"Parking Available","href":""}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}