"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleApple from '@/components/navbar/NavbarStyleApple/NavbarStyleApple';
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="hover-bubble"
                defaultTextAnimation="entrance-slide"
                borderRadius="soft"
                contentWidth="small"
                sizing="mediumLargeSizeLargeTitles"
                background="circleGradient"
                cardStyle="gradient-radial"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleApple
                            brandName="Calabrese Roofing"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Shop", id: "/shop" },
                                { name: "Contact", id: "/contacts" }
                            ]}
                            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="Calabrese Roofing"
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Storm Damage Repair", href: "#services" },
                                        { label: "New Roof Installation", href: "#services" },
                                        { label: "Inspections & Maintenance", href: "#services" },
                                        { label: "Insurance Claims", href: "#services" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "#about" },
                                        { label: "Our Team", href: "#about" },
                                        { label: "Why Choose Us", href: "#about" },
                                        { label: "Careers", href: "#" }
                                    ]
                                },
                                {
                                    title: "Support",                                    items: [
                                        { label: "FAQ", href: "#faq" },
                                        { label: "Contact Us", href: "#contact" },
                                        { label: "Free Inspection", href: "#contact" },
                                        { label: "Testimonials", href: "#testimonials" }
                                    ]
                                },
                                {
                                    title: "Legal",                                    items: [
                                        { label: "Privacy Policy", href: "/privacy" },
                                        { label: "Terms of Service", href: "/terms" },
                                        { label: "Warranty Information", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Calabrese Roofing Systems. All rights reserved. Licensed & Insured."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="hover-bubble"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="small"
            sizing="mediumLargeSizeLargeTitles"
            background="circleGradient"
            cardStyle="gradient-radial"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleApple
                        brandName="Calabrese Roofing"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Shop", id: "/shop" },
                            { name: "Contact", id: "/contacts" }
                        ]}
                        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="Calabrese Roofing"
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Storm Damage Repair", href: "#services" },
                                    { label: "New Roof Installation", href: "#services" },
                                    { label: "Inspections & Maintenance", href: "#services" },
                                    { label: "Insurance Claims", href: "#services" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "#about" },
                                    { label: "Our Team", href: "#about" },
                                    { label: "Why Choose Us", href: "#about" },
                                    { label: "Careers", href: "#" }
                                ]
                            },
                            {
                                title: "Support",                                items: [
                                    { label: "FAQ", href: "#faq" },
                                    { label: "Contact Us", href: "#contact" },
                                    { label: "Free Inspection", href: "#contact" },
                                    { label: "Testimonials", href: "#testimonials" }
                                ]
                            },
                            {
                                title: "Legal",                                items: [
                                    { label: "Privacy Policy", href: "/privacy" },
                                    { label: "Terms of Service", href: "/terms" },
                                    { label: "Warranty Information", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Calabrese Roofing Systems. All rights reserved. Licensed & Insured."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}