"use client";

import ReactLenis from "lenis/react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleFullscreen from '@/components/navbar/NavbarStyleFullscreen/NavbarStyleFullscreen';
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="bounce-effect"
                defaultTextAnimation="reveal-blur"
                borderRadius="pill"
                contentWidth="compact"
                sizing="mediumLargeSizeMediumTitles"
                background="none"
                cardStyle="layered-gradient"
                primaryButtonStyle="diagonal-gradient"
                secondaryButtonStyle="solid"
                headingFontWeight="light"
            >
                <ReactLenis root>
                    <div id="navbar" data-section="navbar">
                        <NavbarStyleFullscreen
                            brandName="Safe Haven Shelter"
                            navItems={[
                                { name: "Home", id: "/" },
                                { name: "Available Pets", id: "available" },
                                { name: "Adopt", id: "adopt" },
                                { name: "Stories", id: "stories" },
                                { name: "Contact", id: "contact" },
                                { name: "Shop", id: "/shop" }
                            ]}
                            bottomLeftText="Love saves lives"
                            bottomRightText="contact@safehaven.org"
                            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/elegant-fashion-girls-summer-park_1157-21448.jpg"
                            imageAlt="Happy rescued animals"
                            logoText="Safe Haven Shelter"
                            copyrightText="© 2024 Safe Haven Shelter. Saving lives, one pet at a time."
                            columns={[
                                {
                                    title: "Adopt",                                    items: [
                                        { label: "Available Pets", href: "available" },
                                        { label: "Adoption Process", href: "adopt" },
                                        { label: "Success Stories", href: "stories" }
                                    ]
                                },
                                {
                                    title: "Get Involved",                                    items: [
                                        { label: "Volunteer", href: "volunteers" },
                                        { label: "Donate", href: "#" },
                                        { label: "Sponsor", href: "#" }
                                    ]
                                },
                                {
                                    title: "Contact",                                    items: [
                                        { label: "About Us", href: "#" },
                                        { label: "Email Us", href: "mailto:contact@safehaven.org" },
                                        { label: "Visit Us", href: "#" }
                                    ]
                                }
                            ]}
                        />
                    </div>
                </ReactLenis>
            </ThemeProvider>
        );
    }

    return (
        <ThemeProvider
            defaultButtonVariant="bounce-effect"
            defaultTextAnimation="reveal-blur"
            borderRadius="pill"
            contentWidth="compact"
            sizing="mediumLargeSizeMediumTitles"
            background="none"
            cardStyle="layered-gradient"
            primaryButtonStyle="diagonal-gradient"
            secondaryButtonStyle="solid"
            headingFontWeight="light"
        >
            <ReactLenis root>
                <div id="navbar" data-section="navbar">
                    <NavbarStyleFullscreen
                        brandName="Safe Haven Shelter"
                        navItems={[
                            { name: "Home", id: "/" },
                            { name: "Available Pets", id: "available" },
                            { name: "Adopt", id: "adopt" },
                            { name: "Stories", id: "stories" },
                            { name: "Contact", id: "contact" },
                            { name: "Shop", id: "/shop" }
                        ]}
                        bottomLeftText="Love saves lives"
                        bottomRightText="contact@safehaven.org"
                        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/elegant-fashion-girls-summer-park_1157-21448.jpg"
                        imageAlt="Happy rescued animals"
                        logoText="Safe Haven Shelter"
                        copyrightText="© 2024 Safe Haven Shelter. Saving lives, one pet at a time."
                        columns={[
                            {
                                title: "Adopt",                                items: [
                                    { label: "Available Pets", href: "available" },
                                    { label: "Adoption Process", href: "adopt" },
                                    { label: "Success Stories", href: "stories" }
                                ]
                            },
                            {
                                title: "Get Involved",                                items: [
                                    { label: "Volunteer", href: "volunteers" },
                                    { label: "Donate", href: "#" },
                                    { label: "Sponsor", href: "#" }
                                ]
                            },
                            {
                                title: "Contact",                                items: [
                                    { label: "About Us", href: "#" },
                                    { label: "Email Us", href: "mailto:contact@safehaven.org" },
                                    { label: "Visit Us", href: "#" }
                                ]
                            }
                        ]}
                    />
                </div>
            </ReactLenis>
        </ThemeProvider>
    );
}