"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 FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="background-highlight"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="largeSmall"
                background="aurora"
                cardStyle="inset"
                primaryButtonStyle="flat"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Savoria"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"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">
                        <FooterLogoEmphasis
                            logoText="Savoria"
                            columns={[
                                {"items":[{"label":"Hours","href":"#"},{"label":"Tue-Thu: 5PM-11PM","href":"#"},{"label":"Fri-Sat: 5PM-12AM","href":"#"},{"label":"Sunday: 5PM-10PM","href":"#"},{"label":"Closed Mondays","href":"#"}]},
                                {"items":[{"label":"Contact","href":"#"},{"label":"+1 (555) 123-4567","href":"tel:+15551234567"},{"label":"hello@savoria.com","href":"mailto:hello@savoria.com"},{"label":"123 Park Avenue","href":"#"},{"label":"New York, NY 10017","href":"#"}]},
                                {"items":[{"label":"Shop","href":"/shop"},{"label":"Private Events","href":"#"},{"label":"Wine List","href":"#"},{"label":"Careers","href":"#"},{"label":"Contact Us","href":"/contacts"}]},
                                {"items":[{"label":"Follow Us","href":"#"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-stagger"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="largeSmall"
            background="aurora"
            cardStyle="inset"
            primaryButtonStyle="flat"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Savoria"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"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">
                    <FooterLogoEmphasis
                        logoText="Savoria"
                        columns={[
                            {"items":[{"label":"Hours","href":"#"},{"label":"Tue-Thu: 5PM-11PM","href":"#"},{"label":"Fri-Sat: 5PM-12AM","href":"#"},{"label":"Sunday: 5PM-10PM","href":"#"},{"label":"Closed Mondays","href":"#"}]},
                            {"items":[{"label":"Contact","href":"#"},{"label":"+1 (555) 123-4567","href":"tel:+15551234567"},{"label":"hello@savoria.com","href":"mailto:hello@savoria.com"},{"label":"123 Park Avenue","href":"#"},{"label":"New York, NY 10017","href":"#"}]},
                            {"items":[{"label":"Shop","href":"/shop"},{"label":"Private Events","href":"#"},{"label":"Wine List","href":"#"},{"label":"Careers","href":"#"},{"label":"Contact Us","href":"/contacts"}]},
                            {"items":[{"label":"Follow Us","href":"#"},{"label":"Instagram","href":"https://instagram.com"},{"label":"Facebook","href":"https://facebook.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}