"use client"

import { useEffect, useRef, useState, type ReactNode } from "react"

interface ScrollRevealCardProps {
  children: ReactNode
}

export function ScrollRevealCard({ children }: ScrollRevealCardProps) {
  const ref = useRef<HTMLDivElement>(null)
  const [isVisible, setIsVisible] = useState(false)

  useEffect(() => {
    const el = ref.current
    if (!el) return

    const observer = new IntersectionObserver(
      ([entry]) => {
        if (entry.isIntersecting) setIsVisible(true)
      },
      { threshold: 0.35, rootMargin: "0px 0px -120px 0px" }
    )

    observer.observe(el)
    return () => observer.disconnect()
  }, [])

  return (
    <div
      ref={ref}
      className={`transition-all duration-700 ease-out ${
        isVisible ? "translate-y-0 opacity-100" : "translate-y-12 opacity-20"
      }`}
    >
      {children}
    </div>
  )
}
