"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import FooterLogoEmphasis from '@/components/sections/footer/FooterLogoEmphasis';
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="elastic-effect"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="mediumLarge"
                sizing="largeSmallSizeLargeTitles"
                background="none"
                cardStyle="glass-depth"
                primaryButtonStyle="radial-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="SaaSync"
                            bottomLeftText="Made for modern teams"
                            bottomRightText="hello@saasync.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>
                    <div id="footer" data-section="footer">
                        <FooterLogoEmphasis
                            logoText="SaaSync"
                            columns={[
                                {
                                    items: [
                                        { label: "Product", href: "#features" },
                                        { label: "Pricing", href: "#pricing" },
                                        { label: "Security", href: "https://saasync.io/security" },
                                        { label: "Updates", href: "https://saasync.io/blog" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Company", href: "https://saasync.io/about" },
                                        { label: "Blog", href: "https://saasync.io/blog" },
                                        { label: "Careers", href: "https://saasync.io/careers" },
                                        { label: "Contact", href: "#contact" }
                                    ]
                                },
                                {
                                    items: [
                                        { label: "Privacy", href: "https://saasync.io/privacy" },
                                        { label: "Terms", href: "https://saasync.io/terms" },
                                        { label: "Cookies", href: "https://saasync.io/cookies" },
                                        { label: "Status", href: "https://status.saasync.io" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="mediumLarge"
            sizing="largeSmallSizeLargeTitles"
            background="none"
            cardStyle="glass-depth"
            primaryButtonStyle="radial-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="SaaSync"
                        bottomLeftText="Made for modern teams"
                        bottomRightText="hello@saasync.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">
                    <FooterLogoEmphasis
                        logoText="SaaSync"
                        columns={[
                            {
                                items: [
                                    { label: "Product", href: "#features" },
                                    { label: "Pricing", href: "#pricing" },
                                    { label: "Security", href: "https://saasync.io/security" },
                                    { label: "Updates", href: "https://saasync.io/blog" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Company", href: "https://saasync.io/about" },
                                    { label: "Blog", href: "https://saasync.io/blog" },
                                    { label: "Careers", href: "https://saasync.io/careers" },
                                    { label: "Contact", href: "#contact" }
                                ]
                            },
                            {
                                items: [
                                    { label: "Privacy", href: "https://saasync.io/privacy" },
                                    { label: "Terms", href: "https://saasync.io/terms" },
                                    { label: "Cookies", href: "https://saasync.io/cookies" },
                                    { label: "Status", href: "https://status.saasync.io" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}