"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
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="bounce-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="largeSmallSizeLargeTitles"
                background="aurora"
                cardStyle="soft-shadow"
                primaryButtonStyle="shadow"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="SocialHub"
                            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="SocialHub"
                            columns={[
                                {
                                    title: "Platform",                                    items: [
                                        { label: "Feed", href: "#posts" },
                                        { label: "Stories", href: "#stories" },
                                        { label: "Messages", href: "#messages" },
                                        { label: "Explore", href: "#explore" }
                                    ]
                                },
                                {
                                    title: "Community",                                    items: [
                                        { label: "Creators", href: "#creators" },
                                        { label: "Trends", href: "#trends" },
                                        { label: "Events", href: "#events" },
                                        { label: "Support", href: "#support" }
                                    ]
                                },
                                {
                                    title: "Account",                                    items: [
                                        { label: "Settings", href: "#settings" },
                                        { label: "Privacy", href: "#privacy" },
                                        { label: "Security", href: "#security" },
                                        { label: "Help", href: "#help" }
                                    ]
                                },
                                {
                                    title: "Follow Us",                                    items: [
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "Twitter", href: "https://twitter.com" },
                                        { label: "TikTok", href: "https://tiktok.com" },
                                        { label: "YouTube", href: "https://youtube.com" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 SocialHub. All rights reserved."
                            onPrivacyClick={null}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="largeSmallSizeLargeTitles"
            background="aurora"
            cardStyle="soft-shadow"
            primaryButtonStyle="shadow"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="SocialHub"
                        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="SocialHub"
                        columns={[
                            {
                                title: "Platform",                                items: [
                                    { label: "Feed", href: "#posts" },
                                    { label: "Stories", href: "#stories" },
                                    { label: "Messages", href: "#messages" },
                                    { label: "Explore", href: "#explore" }
                                ]
                            },
                            {
                                title: "Community",                                items: [
                                    { label: "Creators", href: "#creators" },
                                    { label: "Trends", href: "#trends" },
                                    { label: "Events", href: "#events" },
                                    { label: "Support", href: "#support" }
                                ]
                            },
                            {
                                title: "Account",                                items: [
                                    { label: "Settings", href: "#settings" },
                                    { label: "Privacy", href: "#privacy" },
                                    { label: "Security", href: "#security" },
                                    { label: "Help", href: "#help" }
                                ]
                            },
                            {
                                title: "Follow Us",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "Twitter", href: "https://twitter.com" },
                                    { label: "TikTok", href: "https://tiktok.com" },
                                    { label: "YouTube", href: "https://youtube.com" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 SocialHub. All rights reserved."
                        onPrivacyClick={null}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}