"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
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="slide-background"
                defaultTextAnimation="entrance-slide"
                borderRadius="rounded"
                contentWidth="mediumLarge"
                sizing="mediumLarge"
                background="floatingGradient"
                cardStyle="glass-depth"
                primaryButtonStyle="flat"
                secondaryButtonStyle="layered"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="Sharp Cuts Barbershop"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"About","id":"about"},
                                {"name":"Services","id":"services"},
                                {"name":"Team","id":"team"},
                                {"name":"Contact","id":"contact"},
                                {"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">
                        <FooterLogoEmphasis
                            logoText="Sharp Cuts"
                            columns={[
                                {"items":[{"label":"Home","href":"home"},{"label":"Services","href":"services"},{"label":"About","href":"about"}]},
                                {"items":[{"label":"Team","href":"team"},{"label":"Pricing","href":"pricing"},{"label":"Contact","href":"contact"}]},
                                {"items":[{"label":"Book Online","href":"contact"},{"label":"Gift Cards","href":"contact"},{"label":"Call Us","href":"tel:+1-555-0123"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="entrance-slide"
            borderRadius="rounded"
            contentWidth="mediumLarge"
            sizing="mediumLarge"
            background="floatingGradient"
            cardStyle="glass-depth"
            primaryButtonStyle="flat"
            secondaryButtonStyle="layered"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="Sharp Cuts Barbershop"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"About","id":"about"},
                            {"name":"Services","id":"services"},
                            {"name":"Team","id":"team"},
                            {"name":"Contact","id":"contact"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                    <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="Sharp Cuts"
                        columns={[
                            {"items":[{"label":"Home","href":"home"},{"label":"Services","href":"services"},{"label":"About","href":"about"}]},
                            {"items":[{"label":"Team","href":"team"},{"label":"Pricing","href":"pricing"},{"label":"Contact","href":"contact"}]},
                            {"items":[{"label":"Book Online","href":"contact"},{"label":"Gift Cards","href":"contact"},{"label":"Call Us","href":"tel:+1-555-0123"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}