"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
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="text-shift"
                defaultTextAnimation="reveal-blur"
                borderRadius="sharp"
                contentWidth="smallMedium"
                sizing="largeSmallSizeMediumTitles"
                background="circleGradient"
                cardStyle="subtle-shadow"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="glass"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Shop","id":"/shop"}
                            ]}
                            brandName="Lika-Comfort"
                            bottomLeftText="Kyiv, Ukraine"
                            bottomRightText="info@lika-comfort.ua"
                            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-vector/abstract-halftone-dots-background_1048-8194.jpg"
                            imageAlt="Lika-Comfort footer background"
                            columns={[
                                {"title":"Products","items":[{"label":"Residential Units","href":"#products"},{"label":"Commercial Systems","href":"#products"},{"label":"Replacement Parts","href":"#products"},{"label":"Accessories","href":"#products"}]},
                                {"title":"Services","items":[{"label":"Installation","href":"#features"},{"label":"Maintenance","href":"#features"},{"label":"Repairs","href":"#features"},{"label":"Consultation","href":"#contact"}]},
                                {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Support","href":"#contact"}]}
                            ]}
                            logoText="LIKA-COMFORT"
                            copyrightText="© 2025 Lika-Comfort | Premium Air Conditioning Solutions | Kyiv, Ukraine"
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="text-shift"
            defaultTextAnimation="reveal-blur"
            borderRadius="sharp"
            contentWidth="smallMedium"
            sizing="largeSmallSizeMediumTitles"
            background="circleGradient"
            cardStyle="subtle-shadow"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="glass"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Shop","id":"/shop"}
                        ]}
                        brandName="Lika-Comfort"
                        bottomLeftText="Kyiv, Ukraine"
                        bottomRightText="info@lika-comfort.ua"
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-vector/abstract-halftone-dots-background_1048-8194.jpg"
                        imageAlt="Lika-Comfort footer background"
                        columns={[
                            {"title":"Products","items":[{"label":"Residential Units","href":"#products"},{"label":"Commercial Systems","href":"#products"},{"label":"Replacement Parts","href":"#products"},{"label":"Accessories","href":"#products"}]},
                            {"title":"Services","items":[{"label":"Installation","href":"#features"},{"label":"Maintenance","href":"#features"},{"label":"Repairs","href":"#features"},{"label":"Consultation","href":"#contact"}]},
                            {"title":"Company","items":[{"label":"About Us","href":"#about"},{"label":"Contact","href":"#contact"},{"label":"Careers","href":"#"},{"label":"Support","href":"#contact"}]}
                        ]}
                        logoText="LIKA-COMFORT"
                        copyrightText="© 2025 Lika-Comfort | Premium Air Conditioning Solutions | Kyiv, Ukraine"
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}