{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "memories-card-motion",
  "title": "Memories Card (Motion)",
  "author": "AlgorizeTech",
  "description": "A swipeable stack of photo cards with location, date and tag metadata. Use it for travel, gallery and testimonial carousels.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/motion/MemoriesCardBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  AnimatePresence,\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n} from \"motion/react\";\nimport type { PanInfo, Variants } from \"motion/react\";\nimport { Calendar, MapPin, RotateCcw, Sparkles } from \"lucide-react\";\nimport React, { useState } from \"react\";\n\nexport interface MemoryItem {\n  id: string;\n  title: string;\n  location?: string;\n  date?: string;\n  image: string;\n  description?: string;\n  tag?: string;\n}\n\nexport interface MemoriesCardProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  items: MemoryItem[];\n  onCardChange?: (index: number) => void;\n}\n\n// The swiped card leaves toward the side it was thrown: `custom` is -1 or 1.\nconst exitVariants: Variants = {\n  exit: (direction: number) => ({\n    x: direction * 350,\n    opacity: 0,\n    rotateZ: direction * 20,\n    transition: { duration: 0.3 },\n  }),\n};\n\nexport const MemoriesCard = React.forwardRef<HTMLDivElement, MemoriesCardProps>(\n  ({ items, onCardChange, className, ...props }, ref) => {\n    const [cards, setCards] = useState<MemoryItem[]>(items);\n    const [exitDirection, setExitDirection] = useState(1);\n\n    // 3D Tilt Motion Values for Front Card\n    const x = useMotionValue(0);\n    const y = useMotionValue(0);\n\n    const rotateX = useSpring(useTransform(y, [-150, 150], [14, -14]), {\n      stiffness: 300,\n      damping: 25,\n    });\n    const rotateY = useSpring(useTransform(x, [-150, 150], [-14, 14]), {\n      stiffness: 300,\n      damping: 25,\n    });\n\n    const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {\n      const rect = e.currentTarget.getBoundingClientRect();\n      const centerX = rect.left + rect.width / 2;\n      const centerY = rect.top + rect.height / 2;\n      x.set(e.clientX - centerX);\n      y.set(e.clientY - centerY);\n    };\n\n    const handleMouseLeave = () => {\n      x.set(0);\n      y.set(0);\n    };\n\n    const handleDragEnd = (_: MouseEvent | TouchEvent, info: PanInfo) => {\n      const threshold = 80;\n      if (Math.abs(info.offset.x) > threshold) {\n        setExitDirection(info.offset.x < 0 ? -1 : 1);\n        // Remove front card and push to the back of the stack\n        setCards((prev) => {\n          const newStack = [...prev];\n          const removed = newStack.shift();\n          if (removed) newStack.push(removed);\n\n          // Fixed: Pass the correct original index of the NEW front card to the parent\n          if (onCardChange && newStack[0]) {\n            const nextActiveIndex = items.findIndex(\n              (orig) => orig.id === newStack[0].id,\n            );\n            onCardChange(nextActiveIndex);\n          }\n\n          return newStack;\n        });\n        x.set(0);\n        y.set(0);\n      }\n    };\n\n    const handleReset = () => {\n      setExitDirection(1);\n      setCards(items);\n      if (onCardChange) onCardChange(0);\n    };\n\n    return (\n      <div\n        ref={ref}\n        className={cn(\n          \"relative w-full min-h-[520px] flex flex-col items-center justify-center py-8 select-none perspective-[1200px]\",\n          className,\n        )}\n        {...props}\n      >\n        {/* Card Stack Container */}\n        <div className=\"relative w-[300px] sm:w-[340px] md:w-[380px] h-[440px] sm:h-[480px] flex items-center justify-center\">\n          <AnimatePresence custom={exitDirection}>\n            {cards.map((item, index) => {\n              const isFront = index === 0;\n\n              // Fixed: Lookup card's original sequence index in the immutable items prop\n              const originalIndex = items.findIndex(\n                (orig) => orig.id === item.id,\n              );\n\n              // Calculate fanned background spread offsets\n              const fanRotate = index === 1 ? 6 : index === 2 ? -6 : index * 4;\n              const fanX = index === 1 ? 24 : index === 2 ? -24 : 0;\n              const fanY = index * 12;\n              const fanScale = 1 - index * 0.05;\n              const fanZIndex = cards.length - index;\n\n              // Hide cards deep in the stack for performance\n              if (index > 3) return null;\n\n              return (\n                <motion.div\n                  key={item.id}\n                  style={\n                    isFront\n                      ? { rotateX, rotateY, zIndex: fanZIndex }\n                      : { zIndex: fanZIndex }\n                  }\n                  onMouseMove={isFront ? handleMouseMove : undefined}\n                  onMouseLeave={isFront ? handleMouseLeave : undefined}\n                  drag={isFront ? \"x\" : false}\n                  dragConstraints={{ left: 0, right: 0 }}\n                  dragElastic={0.6}\n                  onDragEnd={isFront ? handleDragEnd : undefined}\n                  initial={{ scale: 0.8, opacity: 0, y: 50 }}\n                  animate={{\n                    scale: fanScale,\n                    rotateZ: isFront ? 0 : fanRotate,\n                    x: isFront ? 0 : fanX,\n                    y: isFront ? 0 : fanY,\n                    opacity: 1 - index * 0.2,\n                  }}\n                  custom={exitDirection}\n                  variants={exitVariants}\n                  exit=\"exit\"\n                  transition={{ type: \"spring\", stiffness: 260, damping: 25 }}\n                  className={cn(\n                    \"absolute inset-0 rounded-3xl overflow-hidden shadow-2xl transition-shadow duration-300\",\n                    \"bg-card border border-border/80\",\n                    isFront\n                      ? \"cursor-grab active:cursor-grabbing shadow-primary/20 dark:shadow-primary/20 ring-2 ring-primary/30\"\n                      : \"pointer-events-none hover:border-primary/50 shadow-md shadow-zinc-300/40 dark:shadow-black/50\",\n                  )}\n                >\n                  {/* Card Background Image */}\n                  <div className=\"relative w-full h-full overflow-hidden\">\n                    <img\n                      src={item.image}\n                      alt={item.title}\n                      className=\"w-full h-full object-cover pointer-events-none transition-transform duration-700 hover:scale-105\"\n                    />\n\n                    {/* Gradient Overlay for Text Readability */}\n                    <div className=\"absolute inset-0 bg-gradient-to-t from-black/90 via-black/30 to-transparent dark:from-black/95 dark:via-black/40 dark:to-transparent\" />\n\n                    {/* Top Bar Badges */}\n                    <div className=\"absolute top-5 inset-x-5 flex items-center justify-between pointer-events-none text-white\">\n                      {item.tag ? (\n                        <span className=\"inline-flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider px-3 py-1 rounded-full bg-primary/90 backdrop-blur-md text-primary-foreground shadow-sm\">\n                          <Sparkles className=\"w-3 h-3\" />\n                          {item.tag}\n                        </span>\n                      ) : (\n                        <div />\n                      )}\n\n                      {/* Fixed: Displays actual sequence (1/4, 2/4, etc.) based on original index */}\n                      <span className=\"text-xs font-medium text-white/80 bg-black/30 backdrop-blur-md px-2.5 py-1 rounded-full border border-white/10\">\n                        {originalIndex + 1} / {items.length}\n                      </span>\n                    </div>\n\n                    {/* Bottom Metadata Payload */}\n                    <div className=\"absolute inset-x-0 bottom-0 p-6 flex flex-col justify-end pointer-events-none text-white\">\n                      <div className=\"flex items-center gap-4 text-xs font-medium text-zinc-300 dark:text-zinc-400 mb-2\">\n                        {item.date && (\n                          <span className=\"inline-flex items-center gap-1\">\n                            <Calendar className=\"w-3.5 h-3.5 text-primary\" />\n                            {item.date}\n                          </span>\n                        )}\n                        {item.location && (\n                          <span className=\"inline-flex items-center gap-1\">\n                            <MapPin className=\"w-3.5 h-3.5 text-primary\" />\n                            {item.location}\n                          </span>\n                        )}\n                      </div>\n\n                      <h3 className=\"text-2xl md:text-3xl font-semibold tracking-tight mb-2 leading-snug text-white\">\n                        {item.title}\n                      </h3>\n\n                      {item.description && (\n                        <p className=\"text-sm text-zinc-300 dark:text-zinc-400 line-clamp-2 leading-relaxed\">\n                          {item.description}\n                        </p>\n                      )}\n                    </div>\n                  </div>\n                </motion.div>\n              );\n            })}\n          </AnimatePresence>\n        </div>\n\n        {/* Action Controls & Instructions */}\n        <div className=\"flex items-center justify-between w-full max-w-[340px] sm:max-w-[380px] mt-6 px-2 z-40\">\n          <span className=\"text-xs font-medium text-muted-foreground tracking-wide\">\n            ← Swipe card left or right to cycle →\n          </span>\n\n          <button\n            onClick={handleReset}\n            title=\"Reset stack order\"\n            className=\"inline-flex items-center gap-1.5 text-xs font-semibold text-foreground bg-background border border-border px-3 py-1.5 rounded-full shadow-sm hover:bg-primary hover:text-primary-foreground hover:border-primary/30 active:scale-95 transition-all\"\n          >\n            <RotateCcw className=\"w-3.5 h-3.5\" />\n            Reset\n          </button>\n        </div>\n      </div>\n    );\n  },\n);\n\nMemoriesCard.displayName = \"MemoriesCard\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/MemoriesCardBlock.tsx"
    }
  ],
  "docs": "Motion build of `memories-card` — same props, markup and install path; install one or the other. Named export: MemoriesCard. `items` take { id, title, location, date, image, description?, tag? }; `onCardChange` reports the active index. Drag or click to advance the stack.",
  "categories": [
    "media",
    "marketing"
  ],
  "type": "registry:component"
}
