"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
import ProductCatalog from "@/components/ecommerce/productCatalog/ProductCatalog";
import FooterMedia from '@/components/sections/footer/FooterMedia';
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="entrance-slide"
                borderRadius="soft"
                contentWidth="mediumLarge"
                sizing="largeSizeMediumTitles"
                background="circleGradient"
                cardStyle="solid"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="bold"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Services", id: "services" },
                                { name: "About", id: "about" },
                                { name: "Reviews", id: "reviews" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            brandName="Trucking & Construction"
                            bottomLeftText="Family Owned | Texas Based"
                            bottomRightText="Ready to Move Texas Forward"
                            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-photo/blue-truck-rural-highway-with-green-line-logistics-motion_169016-69998.jpg"
                            imageAlt="Trucking and construction services across Texas"
                            logoText="Trucking & Construction Company of Texas"
                            columns={[
                                {
                                    title: "Services",                                    items: [
                                        { label: "Heavy Hauling", href: "/services#heavy-hauling" },
                                        { label: "Freight Transport", href: "/services#freight" },
                                        { label: "Equipment Transport", href: "/services#equipment" },
                                        { label: "Construction Services", href: "/services#construction" }
                                    ]
                                },
                                {
                                    title: "Company",                                    items: [
                                        { label: "About Us", href: "/about" },
                                        { label: "Our Team", href: "/about#team" },
                                        { label: "Reviews", href: "/reviews" },
                                        { label: "Contact", href: "/contact" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "Call: (512) 555-0000", href: "tel:+1-512-555-0000" },
                                        { label: "Email: info@truckingco.tx", href: "mailto:info@truckingco.tx" },
                                        { label: "Service Area: All of Texas", href: "#" },
                                        { label: "24/7 Dispatch", href: "#" }
                                    ]
                                }
                            ]}
                            copyrightText="© 2025 Trucking & Construction Company of Texas. All rights reserved. Family Owned & Operated."
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="entrance-slide"
            borderRadius="soft"
            contentWidth="mediumLarge"
            sizing="largeSizeMediumTitles"
            background="circleGradient"
            cardStyle="solid"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="bold"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Services", id: "services" },
                            { name: "About", id: "about" },
                            { name: "Reviews", id: "reviews" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        brandName="Trucking & Construction"
                        bottomLeftText="Family Owned | Texas Based"
                        bottomRightText="Ready to Move Texas Forward"
                        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">
                    <FooterMedia
                        imageSrc="https://img.b2bpic.net/free-photo/blue-truck-rural-highway-with-green-line-logistics-motion_169016-69998.jpg"
                        imageAlt="Trucking and construction services across Texas"
                        logoText="Trucking & Construction Company of Texas"
                        columns={[
                            {
                                title: "Services",                                items: [
                                    { label: "Heavy Hauling", href: "/services#heavy-hauling" },
                                    { label: "Freight Transport", href: "/services#freight" },
                                    { label: "Equipment Transport", href: "/services#equipment" },
                                    { label: "Construction Services", href: "/services#construction" }
                                ]
                            },
                            {
                                title: "Company",                                items: [
                                    { label: "About Us", href: "/about" },
                                    { label: "Our Team", href: "/about#team" },
                                    { label: "Reviews", href: "/reviews" },
                                    { label: "Contact", href: "/contact" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "Call: (512) 555-0000", href: "tel:+1-512-555-0000" },
                                    { label: "Email: info@truckingco.tx", href: "mailto:info@truckingco.tx" },
                                    { label: "Service Area: All of Texas", href: "#" },
                                    { label: "24/7 Dispatch", href: "#" }
                                ]
                            }
                        ]}
                        copyrightText="© 2025 Trucking & Construction Company of Texas. All rights reserved. Family Owned & Operated."
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}