"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
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="text-shift"
                defaultTextAnimation="reveal-blur"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="largeSmallSizeLargeTitles"
                background="circleGradient"
                cardStyle="gradient-mesh"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="ProfileHub"
                            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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/close-up-portrait-curly-handsome-european-male_176532-8133.jpg"
                            imageAlt="Profile footer image"
                            logoText="ProfileHub"
                            copyrightText="© 2025 Social Profile Hub. All rights reserved."
                            columns={[
                                {"title":"Profile","items":[{"label":"My Stories","href":"#stories"},{"label":"My Posts","href":"#posts"},{"label":"About","href":"#about"}]},
                                {"title":"Connect","items":[{"label":"Contact Me","href":"contact"},{"label":"Collaborate","href":"contact"},{"label":"Message","href":"contact"}]},
                                {"title":"Social","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="largeSmallSizeLargeTitles"
            background="circleGradient"
            cardStyle="gradient-mesh"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="ProfileHub"
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/close-up-portrait-curly-handsome-european-male_176532-8133.jpg"
                        imageAlt="Profile footer image"
                        logoText="ProfileHub"
                        copyrightText="© 2025 Social Profile Hub. All rights reserved."
                        columns={[
                            {"title":"Profile","items":[{"label":"My Stories","href":"#stories"},{"label":"My Posts","href":"#posts"},{"label":"About","href":"#about"}]},
                            {"title":"Connect","items":[{"label":"Contact Me","href":"contact"},{"label":"Collaborate","href":"contact"},{"label":"Message","href":"contact"}]},
                            {"title":"Social","items":[{"label":"Instagram","href":"https://instagram.com"},{"label":"Twitter","href":"https://twitter.com"},{"label":"LinkedIn","href":"https://linkedin.com"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}