"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
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 {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    const [cartOpen, setCartOpen] = useState(false);

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="directional-hover"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="medium"
                sizing="largeSmall"
                background="floatingGradient"
                cardStyle="gradient-mesh"
                primaryButtonStyle="flat"
                secondaryButtonStyle="glass"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Four Seasons HVAC"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Services","id":"services"},
                                {"name":"About","id":"about"},
                                {"name":"Testimonials","id":"testimonials"},
                                {"name":"FAQ","id":"faq"},
                                {"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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-photo/adult-male-lying-sofa-playing-with-his-child-sunlight-through-windows_181624-41022.jpg"
                            imageAlt="Comfortable home with Four Seasons HVAC services"
                            logoText="Four Seasons HVAC"
                            copyrightText="© 2025 Four Seasons HVAC. All rights reserved."
                            columns={[
                                {"title":"Services","items":[{"label":"HVAC Installation","href":"services"},{"label":"Maintenance Plans","href":"services"},{"label":"Emergency Repair","href":"services"},{"label":"Air Quality","href":"services"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Testimonials","href":"testimonials"},{"label":"FAQ","href":"faq"},{"label":"Contact","href":"contact"}]},
                                {"title":"Support","items":[{"label":"Book Service","href":"contact"},{"label":"Get Estimate","href":"contact"},{"label":"Maintenance Tips","href":"faq"},{"label":"24/7 Emergency","href":"contact"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="directional-hover"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="medium"
            sizing="largeSmall"
            background="floatingGradient"
            cardStyle="gradient-mesh"
            primaryButtonStyle="flat"
            secondaryButtonStyle="glass"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Four Seasons HVAC"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Services","id":"services"},
                            {"name":"About","id":"about"},
                            {"name":"Testimonials","id":"testimonials"},
                            {"name":"FAQ","id":"faq"},
                            {"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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/adult-male-lying-sofa-playing-with-his-child-sunlight-through-windows_181624-41022.jpg"
                        imageAlt="Comfortable home with Four Seasons HVAC services"
                        logoText="Four Seasons HVAC"
                        copyrightText="© 2025 Four Seasons HVAC. All rights reserved."
                        columns={[
                            {"title":"Services","items":[{"label":"HVAC Installation","href":"services"},{"label":"Maintenance Plans","href":"services"},{"label":"Emergency Repair","href":"services"},{"label":"Air Quality","href":"services"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"about"},{"label":"Testimonials","href":"testimonials"},{"label":"FAQ","href":"faq"},{"label":"Contact","href":"contact"}]},
                            {"title":"Support","items":[{"label":"Book Service","href":"contact"},{"label":"Get Estimate","href":"contact"},{"label":"Maintenance Tips","href":"faq"},{"label":"24/7 Emergency","href":"contact"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}