/* eslint-disable @next/next/no-img-element */ "use client"; import { motion, AnimatePresence, animate } from "motion/react"; import { ChevronLeft, ChevronRight, Globe, ShieldCheck, Calendar, ArrowLeft } from "lucide-react"; import { useEffect, useState, useRef } from "react"; import { toPersian } from "../lib/utils"; import { useSettingsStore } from "../lib/store/settingsStore"; import { useRouter } from 'next/navigation'; import { Banner } from "../lib/types"; import { getMediaUrl } from "../lib/media"; function StatCounter({ target }: { target: number }) { const [displayValue, setDisplayValue] = useState(0); useEffect(() => { const controls = animate(0, target, { duration: 3, ease: [0.16, 1, 0.3, 1], onUpdate: (latest) => setDisplayValue(Math.round(latest)) }); return controls.stop; }, [target]); return ( {toPersian(displayValue)}+ ); } export default function Hero({ banners = [], onShopNavigate }: { banners?: Banner[]; onShopNavigate?: () => void }) { const router = useRouter(); const getText = useSettingsStore((state) => state?.getText || ((_k: string, fb: string) => fb)); const isInitialized = useSettingsStore((state) => state?.isInitialized ?? false); const [mounted, setMounted] = useState(false); const [currentSlide, setCurrentSlide] = useState(0); const [isPaused, setIsPaused] = useState(false); useEffect(() => { setMounted(true); }, []); const heroBanners = banners.filter(b => b.isActive !== false && b.imageUrl); const totalSlides = heroBanners.length; // Auto-advance slider useEffect(() => { if (totalSlides <= 1 || isPaused) return; const interval = setInterval(() => { setCurrentSlide(prev => (prev + 1) % totalSlides); }, 5000); return () => clearInterval(interval); }, [totalSlides, isPaused]); const activeBanner = totalSlides > 0 ? heroBanners[currentSlide] : null; const defaultTitle = activeBanner?.title || (banners.length > 0 && banners[0].title ? banners[0].title : "تخصص آلمانی در خدمت\nسلامت پت‌های خانگی"); const defaultSubtitle = activeBanner?.subtitle || (banners.length > 0 && banners[0].subtitle ? banners[0].subtitle : 'از سال ۱۹۸۴، شرکت Canina pharma GmbH در برگیش گلادباخ آلمان، با بهره‌گیری از مواد اولیه طبیعی و فرآیندهای پیشرفته، استاندارد طلایی مکمل‌های دامپزشکی را تعریف می‌کند. کنینا نماینده رسمی این برند در ایران است.'); const title = (mounted && isInitialized ? getText('hero_title', '') : '') || defaultTitle; const subtitle = (mounted && isInitialized ? getText('hero_desc', '') : '') || defaultSubtitle; const titleParts = title.split('\n'); const rawHeroImg = (mounted && isInitialized ? getText('hero_image_url', '') : ''); const sanitizedHeroImg = rawHeroImg.includes('hero-section-image.png') ? '' : rawHeroImg; const activeImageUrl = activeBanner?.imageUrl || sanitizedHeroImg || (banners.length > 0 && banners[0].imageUrl ? banners[0].imageUrl : ""); const handleNextSlide = () => { if (totalSlides > 1) { setCurrentSlide(prev => (prev + 1) % totalSlides); } }; const handlePrevSlide = () => { if (totalSlides > 1) { setCurrentSlide(prev => (prev - 1 + totalSlides) % totalSlides); } }; const touchStartX = useRef(null); const touchEndX = useRef(null); const minSwipeDistance = 40; const onTouchStart = (e: React.TouchEvent) => { touchEndX.current = null; touchStartX.current = e.targetTouches[0].clientX; }; const onTouchMove = (e: React.TouchEvent) => { touchEndX.current = e.targetTouches[0].clientX; }; const onTouchEnd = () => { if (!touchStartX.current || !touchEndX.current) return; const distance = touchStartX.current - touchEndX.current; const isLeftSwipe = distance > minSwipeDistance; const isRightSwipe = distance < -minSwipeDistance; if (isRightSwipe) { handleNextSlide(); } else if (isLeftSwipe) { handlePrevSlide(); } }; return (
{/* Background patterns */}
{/* Content */}
{mounted && isInitialized ? getText('hero_badge', "از ۱۹۸۴ در خدمت سلامت حیوانات") : "از ۱۹۸۴ در خدمت سلامت حیوانات"}

{titleParts[0]}
{titleParts[1] && {titleParts[1]}}

{/* Visual Element & Interactive Slider */}
setIsPaused(true)} onMouseLeave={() => setIsPaused(false)} >
{/* Preloaded and persistent slider image stack */} {heroBanners.length > 0 ? ( heroBanners.map((banner, idx) => ( )) ) : activeImageUrl ? ( {activeBanner?.title ) : null} {/* Gradient overlay and slide caption */}
{mounted && isInitialized ? getText('hero_image_badge', "سرآمد علمی در پزشکی پت‌ها") : "سرآمد علمی در پزشکی پت‌ها"}
{activeBanner?.title || (mounted && isInitialized ? getText('hero_image_title', "مکمل‌های تایید شده دامپزشکی با گواهی IFS") : "مکمل‌های تایید شده دامپزشکی با گواهی IFS")}
{activeBanner?.linkUrl && ( اطلاعات بیشتر و خرید )}
{/* Slider Navigation Arrows (shown if multiple slides exist) */} {totalSlides > 1 && ( <> {/* Dot Indicators */}
{heroBanners.map((_, idx) => (
)} {/* Quality Badge inside the image container */}
DE {mounted && isInitialized ? getText('hero_quality_standard', "استاندارد کیفی آلمان") : "استاندارد کیفی آلمان"}
{/* 3D Action Badge */}
✨ فرمول ۳کاره
{/* Stats */}
{/* Stat 1: Founded Year */}
۱۹۸۴
{mounted && isInitialized ? getText('hero_stat_founded', "سال تاسیس برند") : "سال تاسیس برند"}
{/* Stat 2: Active Agencies */}
{mounted && isInitialized ? getText('hero_stat_agencies', "نمایندگی فعال") : "نمایندگی فعال"}
{/* Stat 3: German Formula */}
۱۰۰٪
{mounted && isInitialized ? getText('hero_stat_german_formula', "فرمول آلمانی") : "فرمول آلمانی"}
); }