"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterBase from '@/components/sections/footer/FooterBase';
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="expand-hover"
                defaultTextAnimation="background-highlight"
                borderRadius="soft"
                contentWidth="medium"
                sizing="large"
                background="circleGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="normal"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingOverlay
                            brandName="Clash of Clans"
                            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">
                        <FooterBase
                            logoText="Clash of Clans"
                            copyrightText="© 2025 Supercell. All rights reserved."
                            columns={[
                                {
                                    "title":"Game",                                    "items":[
                                        {"label":"Download","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Features","href":"/"},
                                        {"label":"Updates","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Clans","href":"/"}
                                    ]
                                },
                                {
                                    "title":"Community",                                    "items":[
                                        {"label":"Forums","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Tournaments","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Support","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Social","href":"https://supercell.com/en/games/clashofclans/"}
                                    ]
                                },
                                {
                                    "title":"Legal",                                    "items":[
                                        {"label":"Privacy Policy","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Terms of Service","href":"https://supercell.com/en/games/clashofclans/"},
                                        {"label":"Contact Us","href":"https://supercell.com/en/games/clashofclans/"}
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="expand-hover"
            defaultTextAnimation="background-highlight"
            borderRadius="soft"
            contentWidth="medium"
            sizing="large"
            background="circleGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="normal"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingOverlay
                        brandName="Clash of Clans"
                        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">
                    <FooterBase
                        logoText="Clash of Clans"
                        copyrightText="© 2025 Supercell. All rights reserved."
                        columns={[
                            {
                                "title":"Game",                                "items":[
                                    {"label":"Download","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Features","href":"/"},
                                    {"label":"Updates","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Clans","href":"/"}
                                ]
                            },
                            {
                                "title":"Community",                                "items":[
                                    {"label":"Forums","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Tournaments","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Support","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Social","href":"https://supercell.com/en/games/clashofclans/"}
                                ]
                            },
                            {
                                "title":"Legal",                                "items":[
                                    {"label":"Privacy Policy","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Terms of Service","href":"https://supercell.com/en/games/clashofclans/"},
                                    {"label":"Contact Us","href":"https://supercell.com/en/games/clashofclans/"}
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}