"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 { useCart } from "@/hooks/useCart";

export default function ShopPage() {
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    const {
        isOpen: cartOpen,
        setIsOpen: setCartOpen,
    } = useCart();

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="slide-background"
                defaultTextAnimation="reveal-blur"
                borderRadius="rounded"
                contentWidth="mediumSmall"
                sizing="large"
                background="none"
                cardStyle="solid"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="semibold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Clash of Clans"
                            navItems={[
                                {"name":"Home","id":"/"},
                                {"name":"Features","id":"features"},
                                {"name":"Gameplay","id":"gameplay"},
                                {"name":"Community","id":"testimonials"},
                                {"name":"Download","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/portrait-scandinavian-female-viking-person_23-2151707039.jpg"
                            imageAlt="Clash of Clans epic battle scene"
                            logoText="Clash of Clans"
                            copyrightText="© 2024 Supercell | Clash of Clans Official"
                            columns={[
                                {"title":"Game","items":[{"label":"Download","href":"#contact"},{"label":"Features","href":"#features"},{"label":"Gameplay","href":"#gameplay"}]},
                                {"title":"Community","items":[{"label":"Join a Clan","href":"https://supercell.com"},{"label":"Global Rankings","href":"https://supercell.com"},{"label":"Events & Updates","href":"https://supercell.com"}]},
                                {"title":"Support","items":[{"label":"Help Center","href":"https://supercell.com"},{"label":"Contact Us","href":"https://supercell.com"},{"label":"Privacy Policy","href":"https://supercell.com"}]}
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="reveal-blur"
            borderRadius="rounded"
            contentWidth="mediumSmall"
            sizing="large"
            background="none"
            cardStyle="solid"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="semibold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Clash of Clans"
                        navItems={[
                            {"name":"Home","id":"/"},
                            {"name":"Features","id":"features"},
                            {"name":"Gameplay","id":"gameplay"},
                            {"name":"Community","id":"testimonials"},
                            {"name":"Download","id":"contact"},
                            {"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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/portrait-scandinavian-female-viking-person_23-2151707039.jpg"
                        imageAlt="Clash of Clans epic battle scene"
                        logoText="Clash of Clans"
                        copyrightText="© 2024 Supercell | Clash of Clans Official"
                        columns={[
                            {"title":"Game","items":[{"label":"Download","href":"#contact"},{"label":"Features","href":"#features"},{"label":"Gameplay","href":"#gameplay"}]},
                            {"title":"Community","items":[{"label":"Join a Clan","href":"https://supercell.com"},{"label":"Global Rankings","href":"https://supercell.com"},{"label":"Events & Updates","href":"https://supercell.com"}]},
                            {"title":"Support","items":[{"label":"Help Center","href":"https://supercell.com"},{"label":"Contact Us","href":"https://supercell.com"},{"label":"Privacy Policy","href":"https://supercell.com"}]}
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}