"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered';
import FooterMedia from '@/components/sections/footer/FooterMedia';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import { useProductCatalog } from "@/hooks/useProductCatalog";
import { useState } from "react";

export default function ShopPage() {
    const [cartOpen, setCartOpen] = useState(false);
    const {
        products,
        isLoading,
        search,
        setSearch,
        filters,
    } = useProductCatalog({ basePath: "/shop" });

    if (isLoading) {
        return (
            <ThemeProvider
                defaultButtonVariant="slide-background"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="mediumSmall"
                sizing="mediumLarge"
                background="grid"
                cardStyle="outline"
                primaryButtonStyle="gradient"
                secondaryButtonStyle="glass"
                headingFontWeight="extrabold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleCentered
                            brandName="KIMCHI & CO"
                            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">
                        <FooterMedia
                            imageSrc="https://img.b2bpic.net/free-psd/authentic-korean-bibimbap-bowl-with-fried-egg-assorted-vegetables_84443-64212.jpg"
                            imageAlt="Korean dining"
                            logoText="KIMCHI & CO"
                            copyrightText="© 2025 Kimchi & Co. All rights reserved. Crafted with passion in Seoul."
                            columns={[
                                {
                                    title: "Restaurant",                                    items: [
                                        { label: "Menu", href: "#menu" },
                                        { label: "Reservations", href: "#contact" },
                                        { label: "Private Events", href: "#" },
                                        { label: "Catering", href: "#" }
                                    ]
                                },
                                {
                                    title: "Connect",                                    items: [
                                        { label: "Instagram", href: "https://instagram.com" },
                                        { label: "Facebook", href: "https://facebook.com" },
                                        { label: "Email Us", href: "mailto:info@kimchiandco.kr" },
                                        { label: "Phone", href: "tel:+82-2-1234-5678" }
                                    ]
                                },
                                {
                                    title: "Location",                                    items: [
                                        { label: "Gangnam District", href: "#" },
                                        { label: "Directions", href: "#" },
                                        { label: "Contact", href: "#contact" },
                                        { label: "About Us", href: "#about" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="slide-background"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="mediumSmall"
            sizing="mediumLarge"
            background="grid"
            cardStyle="outline"
            primaryButtonStyle="gradient"
            secondaryButtonStyle="glass"
            headingFontWeight="extrabold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleCentered
                        brandName="KIMCHI & CO"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        button={{ text: "Cart", onClick: () => setCartOpen(true) }}
                    />
                </div>
                <div id="product-catalog" data-section="product-catalog">
                    <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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-psd/authentic-korean-bibimbap-bowl-with-fried-egg-assorted-vegetables_84443-64212.jpg"
                        imageAlt="Korean dining"
                        logoText="KIMCHI & CO"
                        copyrightText="© 2025 Kimchi & Co. All rights reserved. Crafted with passion in Seoul."
                        columns={[
                            {
                                title: "Restaurant",                                items: [
                                    { label: "Menu", href: "#menu" },
                                    { label: "Reservations", href: "#contact" },
                                    { label: "Private Events", href: "#" },
                                    { label: "Catering", href: "#" }
                                ]
                            },
                            {
                                title: "Connect",                                items: [
                                    { label: "Instagram", href: "https://instagram.com" },
                                    { label: "Facebook", href: "https://facebook.com" },
                                    { label: "Email Us", href: "mailto:info@kimchiandco.kr" },
                                    { label: "Phone", href: "tel:+82-2-1234-5678" }
                                ]
                            },
                            {
                                title: "Location",                                items: [
                                    { label: "Gangnam District", href: "#" },
                                    { label: "Directions", href: "#" },
                                    { label: "Contact", href: "#contact" },
                                    { label: "About Us", href: "#about" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}