"use client"; import { useRouter } from "next/navigation"; import { motion, useMotionValue, useTransform, PanInfo } from "framer-motion"; import { MapPin, User } from "lucide-react"; import { DiscoverCandidate, photoUrl } from "@/lib/api"; import { formatDistance } from "@/lib/utils"; const SWIPE_THRESHOLD = 120; export function SwipeCard({ profile, isTop, stackIndex, onDecide, }: { profile: DiscoverCandidate; isTop: boolean; stackIndex: number; onDecide: (direction: "left" | "right") => void; }) { const router = useRouter(); const x = useMotionValue(0); const rotate = useTransform(x, [-260, 260], [-16, 16]); const likeOpacity = useTransform(x, [20, 120], [0, 1]); const nopeOpacity = useTransform(x, [-120, -20], [1, 0]); function handleDragEnd(_: unknown, info: PanInfo) { if (info.offset.x > SWIPE_THRESHOLD) { onDecide("right"); } else if (info.offset.x < -SWIPE_THRESHOLD) { onDecide("left"); } } const photo = profile.photos[0]; return ( 0 ? 400 : x.get() < 0 ? -400 : 0, opacity: 0, transition: { duration: 0.3 }, }} transition={{ type: "spring", stiffness: 300, damping: 30 }} >
isTop && router.push(`/home/${profile.id}`)} className="relative w-full h-full rounded-(--radius-xl) overflow-hidden shadow-(--shadow-cute-lg) bg-(--color-bg-tertiary) cursor-pointer select-none" > {photo ? ( // eslint-disable-next-line @next/next/no-img-element {profile.first_name} ) : (
)}
{isTop && ( <> لایک ردّ )}

{profile.first_name || "بدون نام"}

{profile.age}
{profile.distance_km != null && (
{formatDistance(profile.distance_km)}
)}
); }