"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="reveal-blur"
                borderRadius="rounded"
                contentWidth="mediumLarge"
                sizing="largeSmall"
                background="grid"
                cardStyle="gradient-radial"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Midnight Cafe"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Our Story","id":"about"},
                                {"name":"The Experience","id":"features"},
                                {"name":"Community","id":"testimonials"},
                                {"name":"Visit Us","id":"contact"},
                                {"name":"Journal","id":"blog"},
                                {"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">
                        <FooterSimple
                            columns={[
                                {"title":"Navigate","items":[{"label":"Our Story","href":"#about"},{"label":"The Experience","href":"#features"},{"label":"Community","href":"#testimonials"}]},
                                {"title":"Connect","items":[{"label":"Visit Us","href":"#contact"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Email","href":"mailto:hello@midnightcafe.local"}]},
                                {"title":"Values","items":[{"label":"Ethical Sourcing","href":"#about"},{"label":"Slow Living","href":"#about"},{"label":"Community First","href":"#testimonials"}]}
                            ]}
                            bottomLeftText="© 2025 Midnight Cafe. All rights reserved."
                            bottomRightText="Crafted with intention"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="mediumLarge"
            sizing="largeSmall"
            background="grid"
            cardStyle="gradient-radial"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Midnight Cafe"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Our Story","id":"about"},
                            {"name":"The Experience","id":"features"},
                            {"name":"Community","id":"testimonials"},
                            {"name":"Visit Us","id":"contact"},
                            {"name":"Journal","id":"blog"},
                            {"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">
                    <FooterSimple
                        columns={[
                            {"title":"Navigate","items":[{"label":"Our Story","href":"#about"},{"label":"The Experience","href":"#features"},{"label":"Community","href":"#testimonials"}]},
                            {"title":"Connect","items":[{"label":"Visit Us","href":"#contact"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Email","href":"mailto:hello@midnightcafe.local"}]},
                            {"title":"Values","items":[{"label":"Ethical Sourcing","href":"#about"},{"label":"Slow Living","href":"#about"},{"label":"Community First","href":"#testimonials"}]}
                        ]}
                        bottomLeftText="© 2025 Midnight Cafe. All rights reserved."
                        bottomRightText="Crafted with intention"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}