"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 [cartOpen, setCartOpen] = useState(false);
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="mediumLargeSizeLargeTitles"
                background="circleGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="flat"
                secondaryButtonStyle="layered"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="SaaS Pro"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            bottomLeftText="Built for Teams"
                            bottomRightText="hello@saaspro.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/man-wheelchair-having-office-job_23-2149571066.jpg"
                            imageAlt="Team working together"
                            logoText="SaaS Pro"
                            copyrightText="© 2025 SaaS Pro. All rights reserved."
                            columns={[
                                {"title":"Product","items":[{"label":"Features","href":"features"},{"label":"Pricing","href":"pricing"},{"label":"Security","href":"https://example.com/security"},{"label":"Roadmap","href":"https://example.com/roadmap"}]},
                                {"title":"Company","items":[{"label":"About","href":"https://example.com/about"},{"label":"Blog","href":"https://example.com/blog"},{"label":"Careers","href":"https://example.com/careers"}]},
                                {"title":"Legal","items":[{"label":"Privacy Policy","href":"https://example.com/privacy"},{"label":"Terms of Service","href":"https://example.com/terms"},{"label":"Cookie Policy","href":"https://example.com/cookies"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="mediumLargeSizeLargeTitles"
            background="circleGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="flat"
            secondaryButtonStyle="layered"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="SaaS Pro"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        bottomLeftText="Built for Teams"
                        bottomRightText="hello@saaspro.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/man-wheelchair-having-office-job_23-2149571066.jpg"
                        imageAlt="Team working together"
                        logoText="SaaS Pro"
                        copyrightText="© 2025 SaaS Pro. All rights reserved."
                        columns={[
                            {"title":"Product","items":[{"label":"Features","href":"features"},{"label":"Pricing","href":"pricing"},{"label":"Security","href":"https://example.com/security"},{"label":"Roadmap","href":"https://example.com/roadmap"}]},
                            {"title":"Company","items":[{"label":"About","href":"https://example.com/about"},{"label":"Blog","href":"https://example.com/blog"},{"label":"Careers","href":"https://example.com/careers"}]},
                            {"title":"Legal","items":[{"label":"Privacy Policy","href":"https://example.com/privacy"},{"label":"Terms of Service","href":"https://example.com/terms"},{"label":"Cookie Policy","href":"https://example.com/cookies"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}