"use client"; import React, { useState, useEffect, useContext } from "react"; import { backendUrl } from "@/utils/axios"; import axios from "axios"; import Image from "next/image"; import { motion } from "framer-motion"; import slugify from "slugify"; import ProductContext from "@/app/contexts/productContext"; const cleanHTML = (html) => { if (!html) return ""; return html.replace(/style="[^"]*color:[^;]*;?"/gi, ""); }; const SubcategoryHero = ({ params }) => { const { products, category } = useContext(ProductContext); console.log("SubcategoryHero mounted. Params:", params); const [selectedSubcategory, setSelectedSubcategory] = useState(null); useEffect(() => { if (products?.length > 0) { const match = products .map((p) => p.product_subcategory) .find( (sub) => slugify(sub?.subcategory_name || "", { lower: true }) === params.subcategory ); console.log("Matched from products:", match); setSelectedSubcategory(match || null); } }, [products, params.subcategory]); // Fallbacks const fallbackImage = "/placeholder-image.jpg"; const fallbackDescription = "Explore our curated collection of spiritual items designed to enhance your journey of self-discovery and inner peace."; const fallbackCategoryName = "Spiritual Essentials"; return (
{/* Hero Image */}
{
{/* Hero Text */}
{selectedSubcategory?.subcategory_name || fallbackCategoryName}
); }; export default SubcategoryHero;