"use client";

import * as React from "react";
import { motion, useReducedMotion, type Variants } from "framer-motion";

type IconProps = Omit<React.ComponentProps<typeof motion.svg>, "children">;

const frame: Variants = {
  hidden: { opacity: 0, pathLength: 0 },
  visible: {
    opacity: 1,
    pathLength: 1,
    transition: {
      opacity: { duration: 0.2 },
      pathLength: { duration: 0.9, ease: "easeInOut" },
    },
  },
  hover: { opacity: 1, pathLength: 1 },
};

const metric = (delay: number): Variants => ({
  hidden: { opacity: 0, pathLength: 0, x: -6 },
  visible: {
    opacity: 1,
    pathLength: 1,
    x: 0,
    transition: {
      opacity: { duration: 0.2, delay },
      pathLength: { duration: 0.45, delay, ease: "easeOut" },
      x: { duration: 0.45, ease: "easeOut" },
    },
  },
  hover: {
    opacity: [1, 0.5, 1],
    pathLength: 1,
    x: [0, 2.5, 0],
    transition: {
      duration: 1.8,
      delay: delay - 0.9,
      repeat: Infinity,
      ease: "easeInOut",
    },
  },
});

const arrow: Variants = {
  hidden: { opacity: 0, pathLength: 0, x: -5 },
  visible: {
    opacity: 1,
    pathLength: 1,
    x: 0,
    transition: {
      opacity: { duration: 0.2, delay: 1.2 },
      pathLength: { duration: 0.45, delay: 1.2 },
      x: { duration: 0.45 },
    },
  },
  hover: {
    opacity: 1,
    pathLength: 1,
    x: [0, 3, 0],
    transition: { duration: 1.8, repeat: Infinity, ease: "easeInOut" },
  },
};

/** Report rows enter sequentially, then shimmer while hovered. */
export default function ChatbotReports({
  width = 104,
  height = 104,
  style,
  animate,
  whileHover,
  ...props
}: IconProps) {
  const reducedMotion = useReducedMotion();

  return (
    <motion.svg
      {...props}
      width={width}
      height={height}
      viewBox="0 0 104 104"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
      role="img"
      aria-label="Chatbot reports"
      initial={reducedMotion ? false : "hidden"}
      animate={animate}
      whileInView={
        animate !== undefined || reducedMotion ? undefined : "visible"
      }
      viewport={{ once: true, amount: 0.55 }}
      whileHover={
        whileHover !== undefined
          ? whileHover
          : reducedMotion
            ? undefined
            : "hover"
      }
      style={{ display: "inline-block", overflow: "visible", ...style }}
    >
      <motion.path
        d="M13 17.332v56.333a8.667 8.667 0 0 0 8.667 8.667H91"
        stroke="#5c8cf2"
        strokeWidth={7.75}
        strokeLinecap="round"
        strokeLinejoin="round"
        variants={frame}
      />
      <motion.path
        d="M65 17.332H30.334"
        stroke="#5c8cf2"
        strokeWidth={7.75}
        strokeLinecap="round"
        strokeLinejoin="round"
        variants={metric(0.9)}
      />
      <motion.path
        d="M30.334 39h52"
        stroke="#5c8cf2"
        strokeWidth={7.75}
        strokeLinecap="round"
        strokeLinejoin="round"
        variants={metric(1.07)}
      />
      <motion.path
        d="M30.334 60.666h30.333"
        stroke="#5c8cf2"
        strokeWidth={7.75}
        strokeLinecap="round"
        strokeLinejoin="round"
        variants={metric(1.24)}
      />
      <motion.path
        d="M78 69.334l13 13-13 13"
        stroke="#5c8cf2"
        strokeWidth={7.75}
        strokeLinecap="round"
        strokeLinejoin="round"
        variants={arrow}
      />
    </motion.svg>
  );
}
