Files
firma/components/ShowCase.tsx
nabijonovdavronbek619@gmail.com f9d27ec11d new web sayt
2025-11-25 21:06:55 +05:00

156 lines
5.1 KiB
TypeScript

"use client";
import { useState, useEffect } from "react";
import Image from "next/image";
import { motion, AnimatePresence } from "framer-motion";
import { ChevronLeft, ChevronRight } from "lucide-react";
import { useTranslations } from "next-intl";
interface ShowCaseProps {
titleKey: string;
subtitleKey?: string;
ctaLabelKey: string;
images: string[];
}
export function ShowCase({
titleKey,
subtitleKey,
ctaLabelKey,
images,
}: ShowCaseProps) {
const t = useTranslations();
const [currentImageIndex, setCurrentImageIndex] = useState(0);
const [autoPlay, setAutoPlay] = useState(true);
useEffect(() => {
if (!autoPlay) return;
const timer = setInterval(() => {
setCurrentImageIndex((prev) => (prev + 1) % images.length);
}, 5000);
return () => clearInterval(timer);
}, [autoPlay, images.length]);
const goToNext = () => {
setCurrentImageIndex((prev) => (prev + 1) % images.length);
setAutoPlay(false);
};
const goToPrev = () => {
setCurrentImageIndex((prev) => (prev - 1 + images.length) % images.length);
setAutoPlay(false);
};
const handleContactClick = () => {
const contactElement = document.querySelector("#contact");
if (contactElement) {
contactElement.scrollIntoView({ behavior: "smooth" });
}
};
return (
<section className="min-h-screen bg-linear-to-br from-gray-50 via-blue-50 to-gray-50 pt-20 pb-20">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="grid grid-cols-1 lg:grid-cols-2 gap-12 items-center">
{/* Left Content */}
<motion.div
initial={{ opacity: 0, x: -50 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6 }}
>
<h1 className="text-4xl lg:text-5xl font-bold text-gray-900 mb-6 leading-tight">
{t(titleKey)}
</h1>
{subtitleKey && (
<p className="text-lg text-gray-600 mb-8 leading-relaxed">
{t(subtitleKey)}
</p>
)}
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
onClick={handleContactClick}
className="px-8 py-3 bg-linear-to-r from-blue-600 to-blue-700 text-white rounded-lg font-semibold hover:shadow-lg transition-shadow"
>
{t(ctaLabelKey)}
</motion.button>
</motion.div>
{/* Right - Image Carousel */}
<motion.div
initial={{ opacity: 0, x: 50 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, delay: 0.2 }}
className="relative"
>
<div className="relative aspect-square rounded-xl overflow-hidden shadow-2xl bg-gray-100">
<AnimatePresence mode="wait">
<motion.div
key={currentImageIndex}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.5 }}
className="absolute inset-0"
>
<Image
src={images[currentImageIndex]}
alt={`Pump ${currentImageIndex + 1}`}
fill
className="object-cover"
priority={currentImageIndex === 0}
onMouseEnter={() => setAutoPlay(false)}
onMouseLeave={() => setAutoPlay(true)}
/>
</motion.div>
</AnimatePresence>
{/* Navigation Buttons */}
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
onClick={goToPrev}
className="absolute left-4 top-1/2 -translate-y-1/2 z-10 bg-white/80 hover:bg-white p-2 rounded-full shadow-lg"
>
<ChevronLeft className="text-gray-800" />
</motion.button>
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
onClick={goToNext}
className="absolute right-4 top-1/2 -translate-y-1/2 z-10 bg-white/80 hover:bg-white p-2 rounded-full shadow-lg"
>
<ChevronRight className="text-gray-800" />
</motion.button>
{/* Indicators */}
<div className="absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex gap-2">
{images.map((_, idx) => (
<motion.button
key={idx}
onClick={() => {
setCurrentImageIndex(idx);
setAutoPlay(false);
}}
className={`h-2 rounded-full transition-all ${
idx === currentImageIndex
? "bg-white w-8"
: "bg-white/50 w-2"
}`}
whileHover={{ scale: 1.2 }}
/>
))}
</div>
</div>
</motion.div>
</div>
</div>
</section>
);
}