"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterMedia from '@/components/sections/footer/FooterMedia';
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-shift"
                defaultTextAnimation="reveal-blur"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="mediumSizeLargeTitles"
                background="aurora"
                cardStyle="solid"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="Lorenzo Noya"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Achievements","id":"achievements"},
                                {"name":"Skills","id":"skills"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"name":"Contact","id":"contact"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            bottomLeftText="Based in Italy"
                            bottomRightText="lorenzo@example.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>
                    <div id="footer" data-section="footer">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/male-athlete-playing-water-polo-indoor-pool_23-2150579126.jpg"
                            imageAlt="Water polo training"
                            logoText="Lorenzo Noya"
                            copyrightText="© 2025 Lorenzo Noya. All rights reserved."
                            columns={[
                                {"title":"Navigation","items":[{"label":"About","href":"about"},{"label":"Achievements","href":"achievements"},{"label":"Skills","href":"skills"},{"label":"Contact","href":"contact"}]},
                                {"title":"Social","items":[{"label":"LinkedIn","href":"https://linkedin.com"},{"label":"GitHub","href":"https://github.com"},{"label":"Instagram","href":"https://instagram.com"}]},
                                {"title":"Connect","items":[{"label":"Email","href":"mailto:lorenzo@example.com"},{"label":"Phone","href":"tel:+39123456789"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="mediumSizeLargeTitles"
            background="aurora"
            cardStyle="solid"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="Lorenzo Noya"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Achievements","id":"achievements"},
                            {"name":"Skills","id":"skills"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        bottomLeftText="Based in Italy"
                        bottomRightText="lorenzo@example.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/male-athlete-playing-water-polo-indoor-pool_23-2150579126.jpg"
                        imageAlt="Water polo training"
                        logoText="Lorenzo Noya"
                        copyrightText="© 2025 Lorenzo Noya. All rights reserved."
                        columns={[
                            {"title":"Navigation","items":[{"label":"About","href":"about"},{"label":"Achievements","href":"achievements"},{"label":"Skills","href":"skills"},{"label":"Contact","href":"contact"}]},
                            {"title":"Social","items":[{"label":"LinkedIn","href":"https://linkedin.com"},{"label":"GitHub","href":"https://github.com"},{"label":"Instagram","href":"https://instagram.com"}]},
                            {"title":"Connect","items":[{"label":"Email","href":"mailto:lorenzo@example.com"},{"label":"Phone","href":"tel:+39123456789"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}