"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
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="directional-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="pill"
                contentWidth="medium"
                sizing="mediumLargeSizeLargeTitles"
                background="none"
                cardStyle="outline"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="solid"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="WriteHub"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            bottomLeftText="Blog Community"
                            bottomRightText="hello@writehub.com"
                            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>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="pill"
            contentWidth="medium"
            sizing="mediumLargeSizeLargeTitles"
            background="none"
            cardStyle="outline"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="solid"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="WriteHub"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        bottomLeftText="Blog Community"
                        bottomRightText="hello@writehub.com"
                        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/still-life-office-desk-mess_23-2150164813.jpg"
                        imageAlt="Footer background workspace"
                        logoText="WriteHub"
                        copyrightText="© 2025 WriteHub. All rights reserved."
                        columns={[
                            {
                                "title":"Content",                                "items":[
                                    {"label":"All Articles","href":"#articles"},
                                    {"label":"Categories","href":"#categories"},
                                    {"label":"Most Popular","href":"#popular"},
                                    {"label":"Archives","href":"#archives"}
                                ]
                            },
                            {
                                "title":"Resources",                                "items":[
                                    {"label":"Writing Guide","href":"#guide"},
                                    {"label":"Best Practices","href":"#practices"},
                                    {"label":"Tools & Resources","href":"#tools"},
                                    {"label":"Community","href":"#community"}
                                ]
                            },
                            {
                                "title":"Connect",                                "items":[
                                    {"label":"About Us","href":"#about"},
                                    {"label":"Contact","href":"#contact"},
                                    {"label":"Twitter","href":"https://twitter.com"},
                                    {"label":"LinkedIn","href":"https://linkedin.com"}
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}