"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 FooterBaseCard from '@/components/sections/footer/FooterBaseCard';
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="hover-bubble"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="medium"
                sizing="medium"
                background="none"
                cardStyle="gradient-bordered"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="solid"
                headingFontWeight="extrabold"
            >
                <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: "Download", href: "https://play.google.com/store/apps/details?id=com.supercell.clashofclans" },
                                        { label: "Features", href: "#features" },
                                        { label: "Game Modes", href: "#gamemodes" },
                                        { label: "Community", href: "#community" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "FAQ", href: "#faq" },
                                        { label: "Contact Us", href: "#contact" },
                                        { label: "Bug Reports", href: "https://supercell.com/en/support/" },
                                        { label: "Help Center", href: "https://help.supercellgames.com/" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Supercell", href: "https://supercell.com/" },
                                        { label: "Blog", href: "https://supercell.com/en/blog/" },
                                        { label: "Careers", href: "https://supercell.com/en/careers/" },
                                        { label: "Press", href: "https://supercell.com/en/press/" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "#privacy" },
                                        { label: "Terms of Service", href: "#terms" },
                                        { label: "Cookie Policy", href: "#cookies" },
                                        { label: "Content Policy", href: "#content" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2024 Supercell. All rights reserved. Clash of Clans is a trademark of Supercell."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="medium"
            sizing="medium"
            background="none"
            cardStyle="gradient-bordered"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="solid"
            headingFontWeight="extrabold"
        >
            <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: "Download", href: "https://play.google.com/store/apps/details?id=com.supercell.clashofclans" },
                                    { label: "Features", href: "#features" },
                                    { label: "Game Modes", href: "#gamemodes" },
                                    { label: "Community", href: "#community" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "FAQ", href: "#faq" },
                                    { label: "Contact Us", href: "#contact" },
                                    { label: "Bug Reports", href: "https://supercell.com/en/support/" },
                                    { label: "Help Center", href: "https://help.supercellgames.com/" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Supercell", href: "https://supercell.com/" },
                                    { label: "Blog", href: "https://supercell.com/en/blog/" },
                                    { label: "Careers", href: "https://supercell.com/en/careers/" },
                                    { label: "Press", href: "https://supercell.com/en/press/" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "#privacy" },
                                    { label: "Terms of Service", href: "#terms" },
                                    { label: "Cookie Policy", href: "#cookies" },
                                    { label: "Content Policy", href: "#content" }
                                ]
                            }
                        ]}
                        copyrightText="© 2024 Supercell. All rights reserved. Clash of Clans is a trademark of Supercell."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}