"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingOverlay from '@/components/navbar/NavbarLayoutFloatingOverlay/NavbarLayoutFloatingOverlay';
import FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="shift-hover"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="medium"
                sizing="largeSmallSizeLargeTitles"
                background="circleGradient"
                cardStyle="solid"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="bold"
            >
                <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">
                        <FooterBaseCard
                            logoText="Clash of Clans"
                            columns={[
                                {"title":"Game","items":[{"label":"Features","href":"#features"},{"label":"Gameplay","href":"#gameplay"},{"label":"Updates","href":"#mechanics"}]},
                                {"title":"Community","items":[{"label":"Clans","href":"https://clashroyale.supercell.com"},{"label":"Forums","href":"https://forum.supercell.com"},{"label":"Events","href":"https://clashroyale.supercell.com"}]},
                                {"title":"Support","items":[{"label":"Help Center","href":"https://supercell.helpshift.com"},{"label":"Report Issue","href":"https://supercell.helpshift.com"},{"label":"Contact Us","href":"https://supercell.com/en/contact"}]},
                                {"title":"Company","items":[{"label":"About Supercell","href":"https://supercell.com"},{"label":"Careers","href":"https://supercell.com/en/careers"},{"label":"Blog","href":"https://supercell.com/en/blog"}]}
                            ]}
                            copyrightText="© 2024 Supercell Oy. Clash of Clans is a trademark of Supercell Oy."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="shift-hover"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="medium"
            sizing="largeSmallSizeLargeTitles"
            background="circleGradient"
            cardStyle="solid"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="bold"
        >
            <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">
                    <FooterBaseCard
                        logoText="Clash of Clans"
                        columns={[
                            {"title":"Game","items":[{"label":"Features","href":"#features"},{"label":"Gameplay","href":"#gameplay"},{"label":"Updates","href":"#mechanics"}]},
                            {"title":"Community","items":[{"label":"Clans","href":"https://clashroyale.supercell.com"},{"label":"Forums","href":"https://forum.supercell.com"},{"label":"Events","href":"https://clashroyale.supercell.com"}]},
                            {"title":"Support","items":[{"label":"Help Center","href":"https://supercell.helpshift.com"},{"label":"Report Issue","href":"https://supercell.helpshift.com"},{"label":"Contact Us","href":"https://supercell.com/en/contact"}]},
                            {"title":"Company","items":[{"label":"About Supercell","href":"https://supercell.com"},{"label":"Careers","href":"https://supercell.com/en/careers"},{"label":"Blog","href":"https://supercell.com/en/blog"}]}
                        ]}
                        copyrightText="© 2024 Supercell Oy. Clash of Clans is a trademark of Supercell Oy."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}