"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import FooterBaseReveal from '@/components/sections/footer/FooterBaseReveal';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
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="hover-magnetic"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="mediumLargeSizeMediumTitles"
                background="none"
                cardStyle="gradient-mesh"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="solid"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="BlogHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Articles", id: "blog" },
                                { name: "Categories", id: "features" },
                                { name: "Subscribe", id: "contact" },
                                { name: "About", id: "about" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            bottomLeftText="Insights & Stories"
                            bottomRightText="hello@bloghub.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">
                        <FooterBaseReveal
                            columns={[
                                {
                                    title: "Content",                                    items: [
                                        { label: "All Articles", href: "blog" },
                                        { label: "Categories", href: "features" },
                                        { label: "Archives", href: "blog" },
                                        { label: "Subscribe", href: "contact" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "about" },
                                        { label: "Contact", href: "contact" },
                                        { label: "Privacy Policy", href: "#" },
                                        { label: "Terms of Service", href: "#" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Twitter", href: "https://twitter.com" },
                                        { label: "LinkedIn", href: "https://linkedin.com" },
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "Email", href: "mailto:hello@bloghub.com" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 BlogHub. All rights reserved."
                            onPrivacyClick={null}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="mediumLargeSizeMediumTitles"
            background="none"
            cardStyle="gradient-mesh"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="solid"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="BlogHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Articles", id: "blog" },
                            { name: "Categories", id: "features" },
                            { name: "Subscribe", id: "contact" },
                            { name: "About", id: "about" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        bottomLeftText="Insights & Stories"
                        bottomRightText="hello@bloghub.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">
                    <FooterBaseReveal
                        columns={[
                            {
                                title: "Content",                                items: [
                                    { label: "All Articles", href: "blog" },
                                    { label: "Categories", href: "features" },
                                    { label: "Archives", href: "blog" },
                                    { label: "Subscribe", href: "contact" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "about" },
                                    { label: "Contact", href: "contact" },
                                    { label: "Privacy Policy", href: "#" },
                                    { label: "Terms of Service", href: "#" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Twitter", href: "https://twitter.com" },
                                    { label: "LinkedIn", href: "https://linkedin.com" },
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "Email", href: "mailto:hello@bloghub.com" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 BlogHub. All rights reserved."
                        onPrivacyClick={null}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}