"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarLayoutFloatingInline from '@/components/navbar/NavbarLayoutFloatingInline';
import FooterCard from '@/components/sections/footer/FooterCard';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";
import { Instagram, Facebook, Twitter, Linkedin } from 'lucide-react';
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-magnetic"
                defaultTextAnimation="entrance-slide"
                borderRadius="sharp"
                contentWidth="compact"
                sizing="largeSmallSizeMediumTitles"
                background="aurora"
                cardStyle="glass-elevated"
                primaryButtonStyle="double-inset"
                secondaryButtonStyle="radial-glow"
                headingFontWeight="medium"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarLayoutFloatingInline
                            brandName="ShopHub"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "products" },
                                { name: "About", id: "about" },
                                { name: "Reviews", id: "testimonials" },
                                { name: "Contact", id: "contact" }
                            ]}
                            button={{ text: "View 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">
                        <FooterCard
                            logoText="ShopHub"
                            copyrightText="© 2025 ShopHub. All rights reserved. | Privacy Policy | Terms of Service"
                            socialLinks={[
                                {
                                    icon: Instagram,
                                    href: "https://instagram.com",                                    ariaLabel: "Follow us on Instagram"
                                },
                                {
                                    icon: Facebook,
                                    href: "https://facebook.com",                                    ariaLabel: "Follow us on Facebook"
                                },
                                {
                                    icon: Twitter,
                                    href: "https://twitter.com",                                    ariaLabel: "Follow us on Twitter"
                                },
                                {
                                    icon: Linkedin,
                                    href: "https://linkedin.com",                                    ariaLabel: "Connect with us on LinkedIn"
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-magnetic"
            defaultTextAnimation="entrance-slide"
            borderRadius="sharp"
            contentWidth="compact"
            sizing="largeSmallSizeMediumTitles"
            background="aurora"
            cardStyle="glass-elevated"
            primaryButtonStyle="double-inset"
            secondaryButtonStyle="radial-glow"
            headingFontWeight="medium"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarLayoutFloatingInline
                        brandName="ShopHub"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "products" },
                            { name: "About", id: "about" },
                            { name: "Reviews", id: "testimonials" },
                            { name: "Contact", id: "contact" }
                        ]}
                        button={{ text: "View 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">
                    <FooterCard
                        logoText="ShopHub"
                        copyrightText="© 2025 ShopHub. All rights reserved. | Privacy Policy | Terms of Service"
                        socialLinks={[
                            {
                                icon: Instagram,
                                href: "https://instagram.com",                                ariaLabel: "Follow us on Instagram"
                            },
                            {
                                icon: Facebook,
                                href: "https://facebook.com",                                ariaLabel: "Follow us on Facebook"
                            },
                            {
                                icon: Twitter,
                                href: "https://twitter.com",                                ariaLabel: "Follow us on Twitter"
                            },
                            {
                                icon: Linkedin,
                                href: "https://linkedin.com",                                ariaLabel: "Connect with us on LinkedIn"
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}