"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterSimple from '@/components/sections/footer/FooterSimple';
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="elastic-effect"
                defaultTextAnimation="background-highlight"
                borderRadius="pill"
                contentWidth="compact"
                sizing="mediumSizeLargeTitles"
                background="none"
                cardStyle="inset"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="solid"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="DetailPro"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { name: "Contact", id: "contact" }
                            ]}
                            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">
                        <FooterSimple
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Exterior Detailing", href: "#services" },
                                        { label: "Interior Cleaning", href: "#services" },
                                        { label: "Polish & Wax", href: "#services" },
                                        { label: "Wheel Care", href: "#services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Why DetailPro", href: "#about" },
                                        { label: "Reviews", href: "#testimonials" },
                                        { label: "Contact", href: "#contact" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "FAQ", href: "#faq" },
                                        { label: "Booking Info", href: "#contact" },
                                        { label: "Cancellation Policy", href: "#faq" },
                                        { label: "Privacy Policy", href: "#" }
                                    ]
                                }
                            ]}
                            bottomLeftText="© 2025 DetailPro Mobile Detailing. All rights reserved."
                            bottomRightText="Serving your area with professional car care."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="elastic-effect"
            defaultTextAnimation="background-highlight"
            borderRadius="pill"
            contentWidth="compact"
            sizing="mediumSizeLargeTitles"
            background="none"
            cardStyle="inset"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="solid"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="DetailPro"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "contact" }
                        ]}
                        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">
                    <FooterSimple
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Exterior Detailing", href: "#services" },
                                    { label: "Interior Cleaning", href: "#services" },
                                    { label: "Polish & Wax", href: "#services" },
                                    { label: "Wheel Care", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Why DetailPro", href: "#about" },
                                    { label: "Reviews", href: "#testimonials" },
                                    { label: "Contact", href: "#contact" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "FAQ", href: "#faq" },
                                    { label: "Booking Info", href: "#contact" },
                                    { label: "Cancellation Policy", href: "#faq" },
                                    { label: "Privacy Policy", href: "#" }
                                ]
                            }
                        ]}
                        bottomLeftText="© 2025 DetailPro Mobile Detailing. All rights reserved."
                        bottomRightText="Serving your area with professional car care."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}