import { useState, useEffect,useRef, useMemo } from 'react'; import { Heart, X, RotateCcw, MapPin, Briefcase, GraduationCap } from 'lucide-react'; import LazyImage from './LazyImage'; import nomoreimg from "../../assets/images/nomoreimg.png"; import { useNavigate } from "react-router-dom"; import bride1 from "../../assets/images/bride1.jpg"; import bride2 from "../../assets/images/bride2.jpg"; import bride3 from "../../assets/images/bride3.jpg"; import bride4 from "../../assets/images/bride4.jpg"; import Tooltip from '@mui/material/Tooltip'; const TinderCard = ({ children, onSwipe, onCardLeftScreen, preventSwipe, className }) => { const [pos, setPos] = useState({ x: 0, y: 0 }); const [dragging, setDragging] = useState(false); const [startPos, setStartPos] = useState({ x: 0, y: 0 }); const [gone, setGone] = useState(false); useEffect(() => { // Reset state on mount setPos({ x: 0, y: 0 }); setDragging(false); setGone(false); }, []); const handleStart = (clientX, clientY) => { if (gone) return; setDragging(true); setStartPos({ x: clientX - pos.x, y: clientY - pos.y }); }; const handleMove = (clientX, clientY) => { if (!dragging || gone) return; setPos({ x: clientX - startPos.x, y: clientY - startPos.y }); }; const handleEnd = () => { if (gone) return; setDragging(false); if (Math.abs(pos.x) > 120) { const dir = pos.x > 0 ? 'right' : 'left'; if (onSwipe) onSwipe(dir); setGone(true); setTimeout(() => onCardLeftScreen && onCardLeftScreen(dir), 300); } else { setPos({ x: 0, y: 0 }); } }; if (gone) return null; const rotation = pos.x / 20; const opacity = Math.min(Math.abs(pos.x) / 100, 1); return (
handleStart(e.clientX, e.clientY)} onMouseMove={(e) => handleMove(e.clientX, e.clientY)} onMouseUp={handleEnd} onMouseLeave={() => dragging && handleEnd()} onTouchStart={(e) => handleStart(e.touches[0].clientX, e.touches[0].clientY)} onTouchMove={(e) => handleMove(e.touches[0].clientX, e.touches[0].clientY)} onTouchEnd={handleEnd} > {pos.x > 50 && (
LIKE
)} {pos.x < -50 && (
NOPE
)} {children}
); }; const profiles = [ { id: 1, name: 'Priya Sharma', age: 26, location: 'Mumbai, India', profession: 'Software Engineer', education: 'B.Tech from IIT Bombay', about: 'Love traveling, reading, and cooking. Looking for someone who values family.', image: bride1 }, { id: 2, name: 'Ananya Patel', age: 24, location: 'Bangalore, India', profession: 'Doctor', education: 'MBBS from AIIMS', about: 'Passionate about healthcare and music. Seeking a caring life partner.', image: bride2 }, { id: 3, name: 'Neha Gupta', age: 27, location: 'Delhi, India', profession: 'CA', education: 'CA from ICAI', about: 'Enjoy yoga and meditation. Looking for someone with similar values.', image: bride3 }, { id: 4, name: 'Kavya Reddy', age: 25, location: 'Hyderabad, India', profession: 'Marketing Manager', education: 'MBA from ISB', about: 'Creative soul who loves art and dance. Seeking a supportive partner.', image: bride4 } ]; export default function MatrimonySwipeCards() { const [swipedCards, setSwipedCards] = useState(new Set()); const [lastDirection, setLastDirection] = useState(''); const [likedProfiles, setLikedProfiles] = useState([]); const [dislikedProfiles, setDislikedProfiles] = useState([]); const [key, setKey] = useState(0); const navigate = useNavigate(); const activeProfiles = profiles.filter(p => !swipedCards.has(p.id)); const canSwipe = activeProfiles.length > 0; // **CHECK TOKEN FOR BLUR CONTROL** const hasValidToken = useMemo(() => { return !!localStorage.getItem("token"); }, []); // **FIX: Ensure consistent order - Priya Sharma first** const displayProfiles = useMemo(() => { return activeProfiles.sort((a, b) => b.id - a.id ); // Sort by ID ascending (1,2,3,4) }, [activeProfiles]); const swiped = (direction, profile) => { setLastDirection(direction); setSwipedCards(prev => new Set([...prev, profile.id])); if (direction === 'right') { setLikedProfiles(prev => [...prev, profile]); } else { setDislikedProfiles(prev => [...prev, profile]); } }; // const swipe = (dir) => { // if (canSwipe) { // const topProfile = activeProfiles[activeProfiles.length - 1]; // swiped(dir, topProfile); // } // }; const swipe = (dir) => { const token = localStorage.getItem("token"); if (!token) { navigate("/login"); return; } navigate("/match"); if (canSwipe) { // const topProfile = activeProfiles[activeProfiles.length - 1]; const topProfile = displayProfiles[0]; // Priya Sharma first swiped(dir, topProfile); } }; const reset = () => { setSwipedCards(new Set()); setLikedProfiles([]); setDislikedProfiles([]); setLastDirection(''); setKey(prev => prev + 1); }; return (

Find Your Match

Swipe right to like, left to pass

{/* Card Container with overflow hidden */}
{!canSwipe ? (

No more profiles!

) : ( displayProfiles .slice(0, 4) // Limit to 3 cards for stack effect .map((profile, index) => { const isTopCard = index === 3; // ALWAYS FIXED TOP CARD // **NO BLUR IF TOKEN EXISTS** const shouldBlur = !hasValidToken && !isTopCard; return ( swiped(dir, profile)} onCardLeftScreen={() => {}} preventSwipe={['up', 'down']} className="absolute w-full max-w-sm cursor-grab active:cursor-grabbing" >
e.stopPropagation()} className="bg-white rounded-2xl shadow-xl overflow-hidden select-none">
{profile.name} {/* LOCK ICON FOR NON TOP CARDS */} {shouldBlur && (
)}
{/* White Gradient Overlay at bottom of image */}

{profile.name}, {profile.age}

{profile.location}
{profile.profession}
{profile.education}

{profile.about}

) }) )}
{/* Action Buttons */} {canSwipe && (
{/* Decline Button with MUI Tooltip */} {/* Reset Button with MUI Tooltip */} {/* Interest Button with MUI Tooltip */}
)} {/* Stats */} {/*

👍 Liked: {likedProfiles.length}

👎 Passed: {dislikedProfiles.length}

*/} {/* Liked Profiles Preview */} {/* {likedProfiles.length > 0 && (

💚 Your Likes

{likedProfiles.map(p => (
{p.name} {p.name.split(' ')[0]}
))}
)} */}
); }