"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
import FooterMedia from '@/components/sections/footer/FooterMedia';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
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="elastic-effect"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="large"
                background="none"
                cardStyle="gradient-bordered"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="glass"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Ollupa"
                            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/summer-vegetation_23-2147685410.jpg"
                            imageAlt="Beautiful flowers background"
                            columns={[
                                {"title":"Shop","items":[{"label":"Bouquets","href":"#products"},{"label":"Seasonal","href":"#"},{"label":"Custom Orders","href":"#"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Our Story","href":"#"},{"label":"Careers","href":"#"}]},
                                {"title":"Support","items":[{"label":"Contact","href":"mailto:hello@ollupa.com"},{"label":"FAQ","href":"#"},{"label":"Delivery Info","href":"#"}]}
                            ]}
                            logoText="Ollupa"
                            copyrightText="© 2025 Ollupa Flowers. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="large"
            background="none"
            cardStyle="gradient-bordered"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="glass"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Ollupa"
                        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/summer-vegetation_23-2147685410.jpg"
                        imageAlt="Beautiful flowers background"
                        columns={[
                            {"title":"Shop","items":[{"label":"Bouquets","href":"#products"},{"label":"Seasonal","href":"#"},{"label":"Custom Orders","href":"#"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Our Story","href":"#"},{"label":"Careers","href":"#"}]},
                            {"title":"Support","items":[{"label":"Contact","href":"mailto:hello@ollupa.com"},{"label":"FAQ","href":"#"},{"label":"Delivery Info","href":"#"}]}
                        ]}
                        logoText="Ollupa"
                        copyrightText="© 2025 Ollupa Flowers. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}