"use client";

import { motion } from "framer-motion";
import type { ReactNode } from "react";

import { cn } from "@/lib/utils";

type RevealProps = {
  children: ReactNode;
  className?: string;
  delay?: number;
  trigger?: "mount" | "view";
};

export function Reveal({ children, className, delay = 0, trigger = "view" }: RevealProps) {
  return (
    <motion.div
      className={className}
      initial={{ opacity: 0, y: 14 }}
      animate={trigger === "mount" ? { opacity: 1, y: 0 } : undefined}
      whileInView={trigger === "view" ? { opacity: 1, y: 0 } : undefined}
      viewport={trigger === "view" ? { once: true, margin: "-80px" } : undefined}
      transition={{ duration: 0.42, delay, ease: [0.22, 1, 0.36, 1] }}
    >
      {children}
    </motion.div>
  );
}

type FadeListProps = {
  children: ReactNode;
  className?: string;
};

export function FadeList({ children, className }: FadeListProps) {
  return (
    <motion.div
      className={cn("contents", className)}
      initial="hidden"
      whileInView="show"
      viewport={{ once: true, margin: "-80px" }}
      variants={{
        hidden: {},
        show: {
          transition: {
            staggerChildren: 0.055,
          },
        },
      }}
    >
      {children}
    </motion.div>
  );
}

export function FadeItem({ children, className }: RevealProps) {
  return (
    <motion.div
      className={className}
      initial={{ opacity: 0, y: 12 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true, margin: "-80px" }}
      variants={{
        hidden: { opacity: 0, y: 12 },
        show: { opacity: 1, y: 0 },
      }}
      transition={{ duration: 0.38, ease: [0.22, 1, 0.36, 1] }}
    >
      {children}
    </motion.div>
  );
}
