"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import FooterBase from '@/components/sections/footer/FooterBase';
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="background-highlight"
                borderRadius="rounded"
                contentWidth="medium"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="subtle-shadow"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="SaasHub"
                            bottomLeftText="Global Platform"
                            bottomRightText="hello@saashub.io"
                            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="background-highlight"
            borderRadius="rounded"
            contentWidth="medium"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="subtle-shadow"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="SaasHub"
                        bottomLeftText="Global Platform"
                        bottomRightText="hello@saashub.io"
                        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">
                    <FooterBase
                        logoText="SaasHub"
                        copyrightText="© 2025 SaasHub. All rights reserved."
                        columns={[
                            {"title":"Product","items":[{"label":"Features","href":"features"},{"label":"Pricing","href":"pricing"},{"label":"Security","href":"#"},{"label":"Roadmap","href":"#"}]},
                            {"title":"Company","items":[{"label":"About","href":"about"},{"label":"Blog","href":"https://blog.saashub.io"},{"label":"Careers","href":"#"},{"label":"Contact","href":"contact"}]},
                            {"title":"Resources","items":[{"label":"Documentation","href":"#"},{"label":"API Reference","href":"#"},{"label":"Community","href":"#"},{"label":"Support","href":"#"}]}
                        ]}
                        containerClassName="bg-card border-t border-accent/30 py-16"
                        columnsClassName="grid grid-cols-1 md:grid-cols-3 gap-12 mb-12"
                        columnTitleClassName="font-bold text-foreground mb-6"
                        columnItemClassName="text-foreground/70 hover:text-primary-cta transition-colors mb-3"
                        copyrightContainerClassName="border-t border-accent/30 pt-8 text-center text-foreground/60 text-sm"
                        copyrightTextClassName="text-foreground/70"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}