'use client'; import React, { useMemo } from 'react'; import Link from 'next/link'; import { Swiper, SwiperSlide } from 'swiper/react'; import { Autoplay, Pagination, A11y } from 'swiper/modules'; import { SIDEBAR_WIDTH } from '@/components/CategorySidebar'; import { getImageUrl } from '@/lib/utils'; import 'swiper/css'; import 'swiper/css/pagination'; export interface SlideItem { id: string; badge: string; title: string; subtitle: string; image: string; buttonText: string; buttonUrl: string; gradient: string; } const DEFAULT_GRADIENTS = [ 'from-[#0b1b3a] via-[#12356f] to-[#1976F3]', 'from-slate-950 via-blue-950 to-[#1565C0]', 'from-[#071428] via-[#0d2f66] to-[#1e88e5]', ]; /** TechShop-style fallback slides when CMS has no slides yet */ export const DEFAULT_SLIDES: SlideItem[] = [ { id: '1', badge: 'Limited Time Offer', title: 'Ultimate Virtual Reality\nExperience Box', subtitle: 'Experience the Future of Entertainment Today', image: '', buttonText: 'Shop Now', buttonUrl: '/shop', gradient: DEFAULT_GRADIENTS[0], }, { id: '2', badge: 'Exclusive Launch', title: 'Next-Gen Performance\nPro Gaming Gear', subtitle: 'Unleash Your Full Creative Power Everywhere', image: '', buttonText: 'Shop Now', buttonUrl: '/shop', gradient: DEFAULT_GRADIENTS[1], }, { id: '3', badge: 'Hot Deal', title: 'Smart Wearables\nFor Everyday Life', subtitle: 'Track fitness, stay connected, look sharp', image: '', buttonText: 'Explore Now', buttonUrl: '/shop', gradient: DEFAULT_GRADIENTS[2], }, ]; function sanitizeGradient(raw: unknown, fallback: string): string { if (typeof raw !== 'string' || !raw.trim()) return fallback; const value = raw.trim(); if ( /^(from|via|to)-[\w\[\]#./%-]+(\s+(from|via|to)-[\w\[\]#./%-]+)*$/.test( value ) ) { return value; } return fallback; } function mapConfigSlides(raw: any[]): SlideItem[] { return raw .filter((s) => s && (s.title || s.badge || s.image || s.image_url)) .map((s: any, idx: number) => { const fallback = DEFAULT_SLIDES[idx % DEFAULT_SLIDES.length]; const imageRaw = s.image || s.image_url || ''; return { id: String(s.id || `slide-${idx + 1}`), badge: String(s.badge || s.discount_tag || fallback.badge), title: String(s.title || fallback.title), subtitle: String(s.subtitle || fallback.subtitle), image: imageRaw ? getImageUrl(imageRaw) : '', buttonText: String( s.buttonText || s.button_text || s.cta_text || fallback.buttonText ), buttonUrl: String( s.buttonUrl || s.button_url || s.cta_link || s.link || fallback.buttonUrl ), gradient: sanitizeGradient( s.gradient, DEFAULT_GRADIENTS[idx % DEFAULT_GRADIENTS.length] ), }; }) .filter((s) => s.title); } function slidesFromConfig(config?: any): SlideItem[] { const raw = config?.metadata_json?.slides || config?.metadata?.slides || config?.slides; if (Array.isArray(raw) && raw.length > 0) { const mapped = mapConfigSlides(raw); if (mapped.length > 0) return mapped; } return DEFAULT_SLIDES; } interface HeroSectionProps { config?: any; enabled?: boolean; } export const HeroSection: React.FC = ({ config, enabled = true, }) => { const slides = useMemo(() => slidesFromConfig(config), [config]); if (!enabled) return null; return (
1} grabCursor autoplay={{ delay: 5500, disableOnInteraction: false, pauseOnMouseEnter: true, }} pagination={{ clickable: true, el: '.techshop-hero-pagination', }} className="h-full w-full" > {slides.map((slide) => (
{slide.badge ? ( {slide.badge} ) : null}

{slide.title}

{slide.subtitle ? (

{slide.subtitle}

) : null} {slide.buttonText ? (
{slide.buttonText}
) : null}
{slide.image ? ( // eslint-disable-next-line @next/next/no-img-element {slide.title.replace(/\n/g, ) : (
)}
))}
); };