"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="text-shift"
                defaultTextAnimation="reveal-blur"
                borderRadius="sharp"
                contentWidth="mediumSmall"
                sizing="largeSmall"
                background="none"
                cardStyle="solid"
                primaryButtonStyle="inset-glow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="The Edge"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            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">
                        <FooterBaseCard
                            logoText="The Edge"
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Haircuts", href: "/" },
                                        { label: "Beard Grooming", href: "/" },
                                        { label: "Hot Towel Shave", href: "/" },
                                        { label: "Kids Cuts", href: "/" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "/" },
                                        { label: "Pricing", href: "/" },
                                        { label: "Reviews", href: "/" },
                                        { label: "FAQ", href: "/" }
                                    ]
                                },
                                {
                                    title: "Visit Us",                                    items: [
                                        { label: "123 Wynwood Ave, Miami, FL 33127", href: "https://maps.google.com" },
                                        { label: "(305) 555-EDGE", href: "tel:+13055553433" },
                                        { label: "Mon-Sat: 9AM - 7PM", href: "/" },
                                        { label: "Sun: 10AM - 5PM", href: "/" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 The Edge Barber Shop. All rights reserved."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="sharp"
            contentWidth="mediumSmall"
            sizing="largeSmall"
            background="none"
            cardStyle="solid"
            primaryButtonStyle="inset-glow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="The Edge"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        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">
                    <FooterBaseCard
                        logoText="The Edge"
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Haircuts", href: "/" },
                                    { label: "Beard Grooming", href: "/" },
                                    { label: "Hot Towel Shave", href: "/" },
                                    { label: "Kids Cuts", href: "/" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/" },
                                    { label: "Pricing", href: "/" },
                                    { label: "Reviews", href: "/" },
                                    { label: "FAQ", href: "/" }
                                ]
                            },
                            {
                                title: "Visit Us",                                items: [
                                    { label: "123 Wynwood Ave, Miami, FL 33127", href: "https://maps.google.com" },
                                    { label: "(305) 555-EDGE", href: "tel:+13055553433" },
                                    { label: "Mon-Sat: 9AM - 7PM", href: "/" },
                                    { label: "Sun: 10AM - 5PM", href: "/" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 The Edge Barber Shop. All rights reserved."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}