Files
rudarksh-frontend/components/siddha-mala/categoryHero.jsx

75 lines
2.6 KiB
JavaScript

"use client";
import { useContext } from "react";
import Image from "next/image";
import { motion } from "framer-motion";
import ProductContext from "@/app/contexts/productContext";
import { Button } from "@/components/ui/button";
import { backendUrl } from "@/utils/axios";
const cleanHTML = (html) => {
if (!html) return "";
return html.replace(/style="[^"]*color:[^;]*;?"/gi, "");
};
const CategoryHero = ({ params }) => {
const { category } = useContext(ProductContext);
const selectedCategory = category?.find((cat) => cat.category_name.toLowerCase() ===
decodeURIComponent(params.name).toLowerCase());
console.log(selectedCategory);
// Fallback values
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 (
<section className="relative min-h-[50vh] md:h-[80vh] py-8 md:py-0 flex items-center justify-center">
<div className="container mx-auto px-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-8 items-center">
<div className="relative h-[250px] md:h-[500px] overflow-hidden rounded-lg shadow-xl">
<Image
src={`${
selectedCategory?.image
? backendUrl + selectedCategory?.image
: "/sidhi-mala/Artboard_1_bf5ccd46-7152-4355-82a8-9e9f27c1bfc2.jpg"
}`}
alt="Category Background"
layout="fill"
objectFit="cover"
quality={100}
priority
/>
</div>
<div className="text-start flex justify-start flex-col h-full">
<motion.h1
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
className="text-2xl md:text-3xl font-bold text-black mb-4"
>
{selectedCategory?.category_name || fallbackCategoryName}
</motion.h1>
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.8, delay: 0.2 }}
className="text-black text-sm md:text-base"
dangerouslySetInnerHTML={{
__html: cleanHTML(
selectedCategory?.descriptions || fallbackDescription
),
}}
/>
</div>
</div>
</div>
</section>
);
};
export default CategoryHero;